Skip to content
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

Squiz operator-related false positives in JavaScript template literals #3454

Closed
wongjn opened this issue Oct 16, 2021 · 1 comment
Closed

Comments

@wongjn
Copy link

wongjn commented Oct 16, 2021

Describe the bug
Getting false errors on JavaScript files within template literals that have operator characters. The false sniffs include:

  • Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore
  • Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter
  • Squiz.Formatting.OperatorBracket.MissingBrackets

Code sample

`foo/bar`;
`foo-bar`;
`foo+bar`;
`foo%bar`;

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.js with the code sample above.
  2. Run ./vendor/bin/phpcs test.js --standard=Squiz
  3. See many incorrect errors displayed
----------------------------------------------------------------------
FOUND 12 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------
 1 | ERROR | [ ] Missing file doc comment
 1 | ERROR | [x] Operation must be bracketed
 1 | ERROR | [x] Expected 1 space before "/"; 0 found
 1 | ERROR | [x] Expected 1 space after "/"; 0 found
 2 | ERROR | [x] Operation must be bracketed
 2 | ERROR | [x] Expected 1 space before "-"; 0 found
 2 | ERROR | [x] Expected 1 space after "-"; 0 found
 3 | ERROR | [x] Expected 1 space before "+"; 0 found
 3 | ERROR | [x] Expected 1 space after "+"; 0 found
 4 | ERROR | [x] Operation must be bracketed
 4 | ERROR | [x] Expected 1 space before "%"; 0 found
 4 | ERROR | [x] Expected 1 space after "%"; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 11 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Expected behavior
No errors from:

  • Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore
  • Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter
  • Squiz.Formatting.OperatorBracket.MissingBrackets

Versions:

  • OS: Ubuntu 18.04
  • PHP: 7.4
  • PHPCS: 3.6.1
  • Standard: Squiz
@gsherwood
Copy link
Member

The ability to sniff JS and CSS files is deprecated. All JS functionality will be removed in version 4 and no bugs will be fixed in version 3. I strongly suggest switching to a dedicated JS linting tool like eslint.

The version 4 roadmap can be found here: https://github.com/squizlabs/PHP_CodeSniffer/milestone/11

The specific issue for this is here: #2448

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

No branches or pull requests

2 participants