rtCamp/action-phpcs-code-review

phpcs.xml exclusion patterns being ignored

NickGreen opened this issue · 4 comments

Problem

When we set <exclude-pattern> in the phpcs.xml file, those are being ignored, and the specified folders are being scanned anyway.

Desired behavior

The exclusions in the phpcs.xml file should be honored, and the specified folders should be ignored during sniffing. For example, here's one of our phpcs.xml files:

<?xml version="1.0"?>
<ruleset name="">
	<description>PHPCS declaration</description>

	<rule ref="WordPress-Extra">
		<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
		<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
	</rule>

	<arg name="extensions" value="php"/>
	<arg value="s"/>

	<exclude-pattern>.github/</exclude-pattern>
	<!-- Third-party code -->
	<exclude-pattern>themes/storefront/*</exclude-pattern>
	<exclude-pattern>*/bower-components/*</exclude-pattern>
	<exclude-pattern>*/node_modules/*</exclude-pattern>
	<exclude-pattern>themes/resonar-wpcom/*</exclude-pattern>
	<exclude-pattern>themes/storefront/*</exclude-pattern>
	<exclude-pattern>*/plugins/*</exclude-pattern>
	<exclude-pattern>*/mu-plugins/*</exclude-pattern>
	<exclude-pattern>*/vendor/*</exclude-pattern>
</ruleset>

In this case, the plugins folder should not be sniffed. However, it is still getting sniffed.

Workaround

We've added the plugins folder to the SKIP_FOLDERS setting in the action itself, e.g.:

on: pull_request
name: Code tests
jobs:
  runPHPCSInspection:
    name: Run PHPCS inspection
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        ref: ${{ github.event.pull_request.head.sha }}
    - name: Run PHPCS inspection
      uses: rtCamp/action-phpcs-code-review@master
      env:
        GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
        SKIP_FOLDERS: "tests,.github,plugins,mu-plugins"
      with:
        args: "WordPress-Extra"

Hey @NickGreen,
Is the Workaround you mentioned is working fine?

I can see a comment here from @mrrobot47 mentioning the following:

# Delete all the folders to be skipped to ignore them from being scanned.

I think you want to know why this is happening. Let me know if I got the problem statement right.

The issue is happening due to this maybe.

I have also tried using this from VIP documentation but the output was almost the same.

cc: @mrrobot47

Delete all the folders to be skipped to ignore them from being scanned.

Ah, that's interesting, I hadn't seen that. I'll test removing the "SKIP_FOLDERS" and see if it then honors the exclusion patterns in the xml file.

@NickGreen It will not. SKIP_FOLDERS is required.

Closing this issue.

You can use either SKIP_FOLDERS or more vip-go-ci native option: .vipgoci_phpcs_skip_folders for excluding the directories that are listed in phpcs XML ruleset. Please check the documentation here: https://github.com/rtCamp/action-phpcs-code-review#skipping-phpcs-scanning-for-specific-folders (Make sure you use the latest tag @v2 of the action to use this)

The exclusions in the phpcs.xml file should be honored

This does not happen because of the temp files created for getting just the diff of PR. And then the PHPCS scan running on those temp files. And these temp files do not match with any written exclude patterns.