Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The test subject is the geshifilter module 8.x-dev, running phpcs with:
phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md ./modules/geshifilter/
Gives me:
FILE: ...html/modules/geshifilter/config/install/geshifilter.settings.yml
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
1 | ERROR | [x] Missing file doc comment
45 | ERROR | [x] Perl-style comments are not allowed; use "//
| | Comment" instead
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
It thinks that yaml is a php one and process as this, phpfb is worst, it just "fix" the file as php which gives fatal erros when i install or run tests on the modules.
Comment | File | Size | Author |
---|---|---|---|
#15 | 2867601.15-disable-txt-sniffs.patch | 490 bytes | m4olivei |
#11 | 2867601.11-disable-txt-sniffs.patch | 614 bytes | deviantintegral |
Comments
Comment #2
yukare CreditAttribution: yukare commentedAnd now the same on drupal.org: https://www.drupal.org/pift-ci-job/643222
Comment #3
morsokI have the same issue, CodeSniffer seems to completely ignore the extensions parameters and tests files it should not.
Maybe this is related ? #2862837: Update docs page for file extensions and how to exclude certain extensions
Putting this to major as it breaks CI, feel free to downgrade if this is just an edge case ?
Comment #4
yukare CreditAttribution: yukare commentedIt is not related to that issue, running phpcs with:
phpcs --standard=Drupal modules/geshifilter
Still gives me the same message. The stranger thing it that it process the others yaml well, it is just this file that it complains.
Comment #5
morsokThe issue is that it parses .yml files when you have specified extensions and .yml was not among them according to the issue summary.
I guess the other yml file you have are correct in the eyes of phpcs/coder and so only this one gives you trouble.
Comment #6
yukare CreditAttribution: yukare commented@morsok no, if i have errors in other yml files it complains, just errors like comments with incorrect indentation, but it complains as yaml file, not as php like this one, and it does not tell to replace # with //.
Comment #7
NormySan CreditAttribution: NormySan as a volunteer and at Odd Hill commentedI think i have the sam issue, we use the --extensions setting for all our CI builds to only lint certain files. Because of some change to the --extensions setting all files are now being linted instead and this creates huge issues since we only want to lint files with a certain extension.
Edit:
I solved my issue by adding the ignore setting when running phpcs. The ignore below is the one i used to exclude any node_modules folder and all css, md and txt files since i have no need for linting these.
These are the files that are now automatically checked by the coder ruleset:
Comment #8
morsokThank you @NormySan your workaround worked for me too.
However it would be nice to know what changed and why the --extensions parameter does not work anymore. (It's really weird that .yml files are tested also !).
Comment #9
tstoecklerI hit this as well. What happens is that Code - specifically the
ruleset.xml
of theDrupal
standard contains this:so it will include
md
,yml
, etc. by default.When specifying an own set of extensions, codesniffer merges the list of extensions. As far as I can tell, there is no way to remove them from the list. See also https://github.com/squizlabs/PHP_CodeSniffer/blob/2.9.0/CodeSniffer/CLI....
Not sure if this behavior changed in codesniffer 3.0.0
Comment #10
deviantintegral CreditAttribution: deviantintegral at Lullabot commentedIncluding markdown has blown up warnings in many of our internal project's README files. For example, doctoc's HTML comment is 81 characters long, and using <?php in example code throws errors due to markdown indentation.
Does it make sense to remove md and txt from the default extensions, making it opt-in instead?
Comment #11
deviantintegral CreditAttribution: deviantintegral at Lullabot commentedJust a patch disabling md and txt sniffs for now, probably not suitable for committing.
Comment #12
ApacheEx CreditAttribution: ApacheEx commentedI have the same feeling, we should disable txt and md.
Here is proof: https://pareview.sh/node/1981.
I got 11 errors just in README which is txt file.
So, #11 looks good for me.
Comment #13
jhedstromIf you have a
phpcs.xml
file in your project, adding this line excludes markdown:Comment #14
pfrenssenWhile I agree that PHP_CodeSniffer is probably not the best tool to do linting of Markdown and YAML files, we shouldn't just disable it completely unless we have an alternative available that offers at least all the checks that we currently have.
We offer a couple of sniffs to verify common problems in YAML files, see for example #2837091: Add sniff for weak "access administration pages" permission in Drupal 8 routing.yml, #2842706: Add a test for dependencies for *.info.yml files., #2841649: Add sniff for _access: 'TRUE' in Drupal 8 routing.yml.
Probably instead of just disabling it outright it would be better to open separate issues for the problems that are found so that these can be addressed.
Not all the problems reported are valid: I see for example that one of the reports is failing because there are multiple newlines at the end of the file: this is working as intended.
In the meantime you can exclude any problematic files from being scanned like @jhedstrom demonstrates in #2867601-13: CodeSniffer testing all file extensions instead of the configured ones.
I will close this issue. Please open separate issues for individual problems found in these document types so they can be addressed. If someone feels inspired to create a Drupal standard for a dedicated tool like adrienverge/yamllint then that will definitely be a valid reason to remove the support in Coder.
Comment #15
m4oliveiUpdated patch for #11 against latest 8,x-3.x.