ardem / yii-coding-standard Goto Github PK
View Code? Open in Web Editor NEWYii Framework PHP CodeSniffer Coding Standard
Yii Framework PHP CodeSniffer Coding Standard
Hey amazing plugin, only problem I am having is that the current line icon isn't showing in the gutter. I can see which line I am on in the Xdebug Stack window, and if I step through it updates accordingly, and I can see the breakpoints in the gutter, but no visual indication of the current line.
I am running OSX 10.9 and ST3 3059.
Xdebug.sublime-settings:
{
"close_on_stop": true,
}
I have the following input:
for ($i=0;$i<$this->months;$i++) {
$monthStart = ...
and i get the following error:
54 | ERROR | Single line "FOR" must have an expression started from new line.
i have looked into the sniff and from my understanding it is wrongly thinking of this for-statement as a single line for statement and so it can not understand the code.
i have written the following test code:
for ($i=0;$i<10;$i++)
doSomething();
for ($i=0;$i<10;$i++) doSomething();
for ($i=0;$i<10;$i++) {
doSomething();
}
the sniff breaks for the second and third for-statement.
i think there is a problem in line 60 of Yii/Sniffs/ControlStructures/SingleLineWithoutBracesSniff.php because the search for the opening curly bracket is done "local" so it stops at the first semikolon. In a for statement the semikolon is used inside the declaration before the opening curly bracket.
simply doing a non-local search does not fix the problem as in the above testcase no error would be found (missing the second for-statement).
maybe i can later write a patch.
the mb_detect_encoding function sometimes detects ASCII instead of utf8 and then gives an error.
reproduce:
create a file utf-8 encoded but with only ascii complient characters in it.
codesniff the file
it now says
"File must use only UTF-8 encoding. but ASCII found"
Please add composer support
Thanks for your good job. But i use vscode to compile and debug. Could you give some suggestion on how to configure in vscode?
Hi,
sorry for opening this again.
The issue is still there as just like the mb_detect_encoding function file also just detects the encoding by which character type is found in it. therefor an utf-8 encoded file without characters outside the ascii range is detected as ascii. no matter how explicitly you say it should be saved as utf 8. opening the file in vim and asking ":set fileencoding?" or ":set encoding?" returns utf 8.
the detection fails because the function returns ascii (which is a subset of utf8) even though it is utf-8 encoded.
public function testMethod()
{
if (true)
return true;
else
return setFalse();
}
This triggers a false alarm.
Suggested fix:
$newline = false;
while (in_array($tokens[$closeBracket + $n]['type'], array('T_WHITESPACE', 'T_SEMICOLON'))) {
$strlen = strlen($tokens[$closeBracket + $n]['content']);
if ($tokens[$closeBracket + $n]['content'][$strlen - 1] == $phpcsFile->eolChar) {
$newline = true;
break;
}
$n++;
}
There's a problem with sandboxed installation using Composer.
PHP_CodeSniffer accepts the external standard only if it's toplevel directory is named the same as the standard. So, after the following:
$ php composer.phar install --dev
$ phpcs --standard=./vendor/ardem/yii-coding-standard ./src
I get the following irrelevant fatal error:
PHP Fatal error: Cannot redeclare class Yii_Sniffs_Objects_ObjectParenthesesSniff in /home/hijarian/projects/YiiBooster/vendor/ardem/yii-coding-standard/Sniffs/Objects/ObjectParenthesesSniff.php on line 28
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpcs:0
PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:37
PHP 3. PHP_CodeSniffer->process() /usr/share/php/PHP/CodeSniffer/CLI.php:579
PHP 4. PHP_CodeSniffer->populateTokenListeners() /usr/share/php/PHP/CodeSniffer.php:462
PHP 5. PHP_CodeSniffer::autoload() /usr/share/php/PHP/CodeSniffer.php:0
PHP 6. include() /usr/share/php/PHP/CodeSniffer.php:283
After I rename yii-coding-standard
to Yii
(thus corrupting the Composer installation) the invocation
$ phpcs --standard=./vendor/ardem/Yii ./src
does its job at last.
I suppose if you are going to have a Composer-installable library this issue should be resolved...
According to the docs at https://github.com/yiisoft/yii/wiki/Core-framework-code-style, the structure for braces should follow Allman structure at http://en.wikipedia.org/wiki/Indent_style#Allman_style
if (x == y)
{
something();
somethingelse();
}
However, this structure will error
ERROR | Expected "if (...) {\n"; found "if(...)\n{\n"
using the coding standard files, it's wanting the following:
if (x == y) {
something();
somethingelse();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.