Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpcs.xml exclusion patterns being ignored #47

Closed
NickGreen opened this issue Mar 19, 2021 · 4 comments
Closed

phpcs.xml exclusion patterns being ignored #47

NickGreen opened this issue Mar 19, 2021 · 4 comments

Comments

@NickGreen
Copy link

NickGreen commented Mar 19, 2021

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"
@dhsathiya
Copy link
Member

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

@NickGreen
Copy link
Author

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.

@dhsathiya
Copy link
Member

@NickGreen It will not. SKIP_FOLDERS is required.

@mrrobot47
Copy link
Member

mrrobot47 commented Jul 6, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants