Great new sniff in the last version of coder, namely ClassFileNameSniff.
However, if one has code examples in README files, this can lead to some annoying false positives.
Steps to reproduce:
- Clone coder.
- Create a folder called test_fails_folder
- Create a file called README.md with a code example with a class in it. In my case it contains the following:
this is not a php file
```php
<?php
/**
* Class.
*/
class Test {
}
```
- Run phpcs with the following command:
$ ./vendor/bin/phpcs --standard=./coder_sniffer/Drupal test_fails_folder/
FILE: /xxx/coder/test_fails_folder/README.md
------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------
9 | ERROR | Class name doesn't match filename; expected "class README"
------------------------------------------------------------------------
Time: 124ms; Memory: 8MB
I would expect this case to not give me any errors, since this file is only a markdown file, and even if it contains php code, it would for sure be inconvenient to always name the first code example containing a class after the filename itself to get the code style to pass :)
Patch coming up
Comment | File | Size | Author |
---|---|---|---|
#2 | 3074186.patch | 932 bytes | eiriksm |
Comments
Comment #2
eiriksmPatch attached. Would be nice with a test, but I do not have time for that today :(
Comment #3
eiriksmhttps://github.com/pfrenssen/coder/pull/56
Comment #4
klausiI think this fix makes sense. We should add a test case with an example *.md or *.txt file and make sure it does not throw errors.
Comment #5
eiriksmAdded a test in the PR. Still unsure how you prefer code to be posted to this project, but its over there at least :)
Comment #6
klausiNice, thanks a lot! Left some comments there.
Comment #7
eiriksmShould i set this issue to "needs review" again, now that I followed up on your comments? :)
Comment #9
klausiCommitted, thanks!