Skip to content

Static tests: forbid 'or' instead of '||' #21062

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

Closed
novikor opened this issue Feb 8, 2019 · 13 comments
Closed

Static tests: forbid 'or' instead of '||' #21062

novikor opened this issue Feb 8, 2019 · 13 comments
Assignees
Labels
Component: StaticTest feature request Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@novikor
Copy link
Contributor

novikor commented Feb 8, 2019

Summary (*)

At the moment, static tests allow to use or operator which, however, is bad coding practice.
There was a PR related to this problem: #20628

I believe ot would be nice to include this check in the static tests.

Proposed solution

Update static tests rules to cover this case

Examples (*)

@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Feb 8, 2019

Hi @novikor. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@novikor do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Feb 8, 2019
@novikor novikor self-assigned this Feb 8, 2019
@novikor novikor removed the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Feb 8, 2019
@magento-engcom-team magento-engcom-team added Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Feb 8, 2019
@ghost ghost self-assigned this Feb 8, 2019
@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Feb 8, 2019

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • Next steps are available in case you are a member of Community Maintainers.

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@ghost ghost added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Component: StaticTest feature request labels Feb 8, 2019
@ghost
Copy link

ghost commented Feb 8, 2019

Hi @novikor thank you for you report, It will be processed faster if you move this to https://github.com/magento/community-features

@ghost ghost closed this as completed Feb 8, 2019
@novikor
Copy link
Contributor Author

novikor commented Feb 8, 2019

@engcom-backlog-nazar , OK, I`ll do it.

However, I can try to create a PR to this repository with this improvement by myself. Am I right?

@orlangur
Copy link
Contributor

orlangur commented Feb 8, 2019

@novikor surely you can ;)

@ghost
Copy link

ghost commented Feb 8, 2019

@novikor Yes feel fre to create a Pull Request.

@novikor novikor reopened this Feb 8, 2019
@orlangur
Copy link
Contributor

orlangur commented Feb 8, 2019

@novikor the best way to introduce such check would be to implement a long-awaited static test involving php-cs-fixer as it has a rule

logical_operators [@PhpCsFixer:risky]

Use && and || logical operators instead of and and or.

Risky rule: risky, because you must double-check if using and/or with lower precedence was intentional.

@ghost ghost removed their assignment Feb 12, 2019
@orlangur
Copy link
Contributor

Oh, there is existing phpcs sniff actually, thanks @lenaorobei for finding this out.

Closing in favor of magento/magento-coding-standard#23.

@novikor please consider php-cs-fixer integration anyway ;)

@novikor novikor reopened this Feb 15, 2019
@novikor
Copy link
Contributor Author

novikor commented Feb 15, 2019

@orlangur , I have found a solution how to apply this rule to phpcs and static tests.
Ruleset.xml is present in magento/magento-coding-standard, but .php_cs.dist is not.

May I create a PR in this repository?

@orlangur
Copy link
Contributor

@novikor sure thing! Are you going to implement a proper php-cs-fixer integration?

@novikor
Copy link
Contributor Author

novikor commented Feb 15, 2019

@novikor sure thing! Are you going to implement a proper php-cs-fixer integration?

Yes, I will try

novikor pushed a commit to novikor/magento2 that referenced this issue Mar 1, 2019
Added Squiz.Operators.ValidLogicalOperators rule
novikor pushed a commit to novikor/magento2 that referenced this issue Mar 1, 2019
Added Squiz.Operators.ValidLogicalOperators rule
@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Mar 4, 2019
@magento-engcom-team
Copy link
Contributor

Hi @novikor. Thank you for your report.
The issue has been fixed in #21275 by @novikor in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.2 release.

magento-engcom-team added a commit that referenced this issue Mar 4, 2019
 - Merge Pull Request #21275 from novikor/magento2:Static-tests-forbid-or-instead-of-21062
 - Merged commits:
   1. 23f415a
@magento-engcom-team
Copy link
Contributor

Hi @novikor. Thank you for your report.
The issue has been fixed in #21543 by @novikor in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.9 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Mar 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: StaticTest feature request Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests

3 participants