Skip to content

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

Merged
merged 3 commits into from
Dec 21, 2018

Conversation

lenaorobei
Copy link
Contributor

  • 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
@lenaorobei lenaorobei requested a review from paliarush December 19, 2018 16:50
README.md Outdated
# Magento Coding Standard

This is just the beginning of the coding standards consolidation process.
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Contributor Author

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"
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,21 @@
<?php
Copy link
Contributor

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?

Copy link
Contributor Author

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*/ }
Copy link
Contributor

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.

Copy link
Contributor Author

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',
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

http://php.net/manual/en/function.strpos.php

'get_input'
);

$html = preg_replace('(<h([1-6])>(.*?)</h\1>)sex', '"<h$1>" . strtoupper("$2") . "</h$1>"', $html);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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);

Copy link
Contributor Author

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.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$input = "Bet you want a BMW.";
$input = "Test Input.";

Copy link
Contributor Author

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();
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed sniff.

…MEQP2 sniffs

- Removed severity from PHP code and added to the ruleset
@paliarush paliarush merged commit 7630545 into master Dec 21, 2018
@lenaorobei lenaorobei deleted the MM-4941-move-MEQP2-sniffs branch December 23, 2018 01:26
lenaorobei pushed a commit that referenced this pull request Apr 8, 2019
Merging in parent develop
mmansoor-magento pushed a commit that referenced this pull request Dec 2, 2020
…coding-standard-198

[Imported] Discourage local-FS-only methods
fredden added a commit to fredden/magento-coding-standard that referenced this pull request May 24, 2021
    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
fredden added a commit to fredden/magento-coding-standard that referenced this pull request Sep 2, 2021
  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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants