JustBlackBird / gulp-phpcs

Gulp plugin for running PHP Code Sniffer
MIT License
47 stars 12 forks source link

Support for phpcs.xml #39

Closed dotherightthing closed 5 years ago

dotherightthing commented 6 years ago

I uses phpcs on WordPress projects, via both Gulp/Travis and Sublime Text.

During local development, I've excluded some of the sniffs in phpcs.xml, in my project root:

<?xml version="1.0"?>
<ruleset name="DTRT WordPress">
    <description>WordPress standards with DTRT dev exclusions</description>
    <!-- The WordPress ruleset cherry picks sniffs from Generic, PEAR, PSR-2, Squiz etc -->
    <rule ref="WordPress">
        <exclude name="WordPress.Files.FileName"/>
        <exclude name="WordPress.Functions.DontExtract"/>
    </rule>
</ruleset>

However these are ignored by gulp-phpcs and I need to duplicate them into the exclude array before gulp-phpcs will respect them:

    return gulp.src(phpFiles)
        // Validate files using PHP Code Sniffer
        .pipe(phpcs({
            bin: "vendor/bin/phpcs",
            // standard must be included and cannot reference phpcs.xml, which is ignored
            standard: "WordPress", // -Core + -Docs + -Extra + -VIP
            warningSeverity: 0, // minimum severity required to display an error or warning.
            showSniffCode: true,
            // phpcs.xml exclusions are duplicated below:
            exclude: [
                "WordPress.Files.FileName",
                "WordPress.Functions.DontExtract"
            ]
        }))

In Sublime Text, I use phpcs via SublimeLinter-phpcs. I can configure that plugin to pick up my phpcs.xml like so:

Sublime Text > Preferences > Package Settings > SublimeLinter > Settings

{
    "SublimeLinter.linters.phpcs.standard": "${folder}/phpcs.xml"
}

Is it possible to do something similar in gulp-phpcs so that these exclusions only need to be maintained in one place?

ataylorme commented 5 years ago

@dotherightthing I ran into the same thing but it turns out you can just pass the path to your phpcs.xml to the standard option rather than WordPress and it will use that config file.

JustBlackBird commented 5 years ago

@ataylorme is right. The one of the purposes of standard option is to specify custom config file. I've updated the docs to make this a little bit cleaner.