magento / magento/magento-coding-standard

Magento sniff codes do not match expected format (too many `.`)

Open
#388 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Progress: ready for grooming
Dominant language
PHP
Stars
375
Forks
165
PR merge metrics
No merged PRs in 30d

Description

### Preconditions
1. Use any version of the magento coding standard

### Steps to reproduce
1. Try to use the `--exclude` flag on the CLI to exclude a magento sniff

```bash
$ ./vendor/bin/phpcs -s --standard=Magento2 --exclude=Magento2.Annotation.MethodArguments.MethodArguments src
ERROR: The specified sniff code "Magento2.Annotation.MethodAnnotationStructure.MethodArguments" is invalid

Run "phpcs --help" for usage information
```

### Expected result
1. I can run `phpcs` with the specified rule excluded

### Actual result
I get an error from phpcs as it doesnt expect this many `.` in the sniff codes

https://github.com/squizlabs/PHP_CodeSniffer/blob/b314140057170a81075556a71764f2f302e3b8be/src/Config.php#L851-L859

`squizlabs/php_codesniffer` only expects 2 `.` within a rule name

`--exclude=Magento2.Annotation.MethodArguments.MethodArguments` has 3

When I hack out the check in `vendor/squizlabs/php_codesniffer/src/Config.php` it seems to exclude the rule okay so not sure why they're being strict there. But it still seems like the way the Magento rules are defined they're not fully compatible with `squizlabs/php_codesniffer`

### Workaround

Define my own ruleset which excludes the rules i'm suppressing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked src/Config.php check around lines 851-859 and reproduce the reported ./vendor/bin/phpcs command using the Magento2 standard and --exclude option. Trace how the sniff code is validated against Magento's rule names. Done means the documented Magento sniff can be excluded through the CLI without the invalid-code error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.