-
Notifications
You must be signed in to change notification settings - Fork 160
MM-4941: [EQP][Sniffs Consolidation] Create new GitHub repo and move MEQP2 sniffs #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lenaorobei
commented
Dec 19, 2018
- Decoupled MEQP2 sniffs from MEQP coding standard
- Skipped false-positive and dynamic sniffs for now
…MEQP2 sniffs - Decoupled MEQP2 sniffs from MEQP coding standard - Skipped false-positive and dynamic sniffs for now
README.md
Outdated
# Magento Coding Standard | ||
|
||
This is just the beginning of the coding standards consolidation process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better not add this, because we will forget to remove it eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
README.md
Outdated
|
||
1. Make it easier to run static checks for core project contributors and extensions developers. | ||
2. Store all related to Magento 2 sniffs in one place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Store all related to Magento 2 sniffs in one place. | |
2. Store all Magento 2 sniffs in one place. |
Is this just Magento 2 or both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magento 2 only. Fixed message.
"squizlabs/php_codesniffer": "~3.3.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are we going to ensure compatibility with all major versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only way to support "php": ">=5.5.0"
compatibility which we need for Magento 2.0.x.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is, are we going to test our sniffs with all phpunit versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the same approach as PHP CodeSniffer https://github.com/squizlabs/PHP_CodeSniffer/blob/3.3.0/composer.json#L34
@@ -0,0 +1,21 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we use custom .inc
extension? Where does this convention come from for such tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is out-of-box CodeSniffer approach for unit testing.
|
||
function emptyBlockT () { return true; } | ||
|
||
interface EmptyBlockInterface { /*Empty interface block*/ } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it fail for an empty interface which extends another one? It should not.
Same for the class.
Please consider covering such scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed check for empty class and interface for now.
protected $map = [ | ||
'count' => [ | ||
// phpcs:ignore Generic.Files.LineLength.TooLong | ||
'message' => 'count(...) function should not be used to check if array is empty. Use empty(...) language construct instead', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to run all these sniffs against Magento 2 repository to see how many false positive we get. Maybe will have to remove some of them like this one.
@lenaorobei could you please analyze this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the result of running against app/code
A TOTAL OF 0 ERRORS AND 253 WARNINGS WERE FOUND IN 205 FILES
At first glance - 90% of findings are positive.
use PHP_CodeSniffer\Files\File; | ||
|
||
/** | ||
* Detects misusing of IS_IDENTICAL operators. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we trying to detect with this sniff, briefly looked at Magento/Tests/PHP/ReturnValueCheckUnitTest.inc
but cannot get the purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strict comparison should be user to check the return value for strpos
, stripos
,
array_search
, because they can return boolean false
, and may also return a non-boolean value which evaluates to false
.
'get_input' | ||
); | ||
|
||
$html = preg_replace('(<h([1-6])>(.*?)</h\1>)sex', '"<h$1>" . strtoupper("$2") . "</h$1>"', $html); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$html = preg_replace('(<h([1-6])>(.*?)</h\1>)sex', '"<h$1>" . strtoupper("$2") . "</h$1>"', $html); | |
$html = preg_replace('(<h([1-6])>(.*?)</h\1>)xes', '"<h$1>" . strtoupper("$2") . "</h$1>"', $html); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -0,0 +1,26 @@ | |||
<?php | |||
|
|||
$input = "Bet you want a BMW."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$input = "Bet you want a BMW."; | |
$input = "Test Input."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
echo $block->escapeHtml($block->getGroupCode()); | ||
echo $this->escapeHtml($this->getGroupCode()); | ||
$this->foo(); | ||
$this->helper(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is not allowed either. Please provide source of information which states that this is allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed sniff.
…MEQP2 sniffs - Code review fixes
…MEQP2 sniffs - Removed severity from PHP code and added to the ruleset
…coding-standard-198 [Imported] Discourage local-FS-only methods
Fatal error: Uncaught TypeError: vsprintf(): Argument magento#2 ($values) must be of type array, int given in /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php:1056 Stack trace: #0 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(1056): vsprintf('Direct throw of...', 531) magento#1 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(706): PHP_CodeSniffer\Files\File->addMessage(false, 'Direct throw of...', 67, 4, 'FoundDirectThro...', 531, 8, false) magento#2 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Exceptions/DirectThrowSniff.php(48): PHP_CodeSniffer\Files\File->addWarning('Direct throw of...', 526, 'FoundDirectThro...', 531) magento#3 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Exceptions\DirectThrowSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 526) magento#4 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process() #5 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(630): PHP_CodeSniffer\Files\LocalFile->process() magento#6 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile)) magento#7 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run() magento#8 /srv/www/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS() magento#9 {main} thrown in /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php on line 1056
PHP Fatal error: Uncaught TypeError: strpos(): Argument magento#2 ($needle) must be of type string, null given in /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php:629 Stack trace: #0 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php(629): strpos('\\VendorName\\Mod...', NULL) magento#1 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php(515): Magento2\Sniffs\Annotation\MethodArgumentsSniff->validateFormattingConsistency(Array, Array, Object(PHP_CodeSniffer\Files\LocalFile), Array) magento#2 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php(600): Magento2\Sniffs\Annotation\MethodArgumentsSniff->validateMethodParameterAnnotations(385, Array, Array, Object(PHP_CodeSniffer\Files\LocalFile), Array, 356, 380) magento#3 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Annotation\MethodArgumentsSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 385) magento#4 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process() #5 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(630): PHP_CodeSniffer\Files\LocalFile->process() magento#6 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile)) magento#7 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run() magento#8 /srv/www/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS() magento#9 {main} thrown in /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php on line 629