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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yukare created an issue. See original summary.

yukare’s picture

Category: Support request » Bug report

And now the same on drupal.org: https://www.drupal.org/pift-ci-job/643222

morsok’s picture

Title: phpcs consider yaml file as php » CodeSniffer testing all file extensions instead of the configured ones
Category: Bug report » Support request
Priority: Normal » Major

I 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 ?

yukare’s picture

It 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.

morsok’s picture

The 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.

yukare’s picture

@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 //.

NormySan’s picture

I 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.

--ignore=node_modules,*.css,*.md,*.txt

These are the files that are now automatically checked by the coder ruleset:

php,module,inc,install,test,profile,theme,css,info,txt,md,yml
morsok’s picture

Thank 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 !).

tstoeckler’s picture

I hit this as well. What happens is that Code - specifically the ruleset.xml of the Drupal standard contains this:

 <arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/>

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

deviantintegral’s picture

Including 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?

deviantintegral’s picture

Just a patch disabling md and txt sniffs for now, probably not suitable for committing.

ApacheEx’s picture

Status: Active » Needs review

I 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.

jhedstrom’s picture

If you have a phpcs.xml file in your project, adding this line excludes markdown:

  <!-- Exclude markdown -->
  <exclude-pattern>*md</exclude-pattern>
pfrenssen’s picture

Status: Needs review » Closed (won't fix)

While 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.

m4olivei’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
FileSize
490 bytes

Updated patch for #11 against latest 8,x-3.x.