Skip to content

Configure to use a projects ruleset #10

@ghost

Description

Our team is currently in the process of trying to get codesniffer working in sublime.

So far we have been able to set it up and get it running as it should with the default properties.

However, due to our different codebases we ideally need to use a different ruleset per project.

Having looked at the PHP_CodeSniffer documentation it says that If you run PHP_CodeSniffer without specifying a coding standard, PHP_CodeSniffer will look in the current directory, and all parent directories, for a file called either .phpcs.xml, phpcs.xml, .phpcs.xml.dist, or phpcs.xml.dist

I've removed the phpcs_standard parameter from the PHP_CodeSniffer.sublime-settings file but it doesn't seem to be picking up my projects phpcs.xml file at all.

Is there another setting I need to change somewhere to tell this plugin to use my projects phpcs.xml file?

We have installed PHP_CodeSniffer globally via composer.

This is the current PHP_CodeSniffer.sublime-settings file:

{
     // Run PHPCS when a buffer is saved.
    "run_on_save": false,

    // Path to PHP.
    "php_path": "C:/WAMP/PHP/7.1.33/php.exe",

    // Path to the PHPCS script.
    "phpcs_path": "C:/Users/rob/AppData/Roaming/Composer/vendor/squizlabs/php_codesniffer/bin/phpcs",

    // Path to the PHPCBF script.
    "phpcbf_path": "C:/Users/rob/AppData/Roaming/Composer/vendor/squizlabs/php_codesniffer/phpcbf",

    // PHPCS Standard to Use. Can be a string or a dict (folder => standard).
    // "phpcs_standard": "Squiz",

    // Additional arguments to pass to PHPCS/PHPCBF.
    "additional_args": [],

    // Gutter error icon colour.
    "error_scope": "comment.block",

    // Gutter warning icon colour.
    "warning_scope": "function"
}

This is what our custom ruleset looks like:

<?xml version="1.0"?>

<ruleset name="Custom-Ruleset">
    <description>Custom Ruleset</description>
    <arg name="tab-width" value="4"/>

     <exclude-pattern>*/vendor/*</exclude-pattern>

    <rule ref="PSR12">
        <exclude name="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose" />
        <exclude name="PSR12.Operators.OperatorSpacing.NoSpaceBefore" />
        <exclude name="PSR12.Operators.OperatorSpacing.NoSpaceAfter" />
        <exclude name="PSR12.Functions.ReturnTypeDeclaration.SpaceBeforeColon" />
        <exclude name="PEAR.ControlStructures.MultiLineCondition.StartWithBoolean" />
        <exclude name="PEAR.ControlStructures.MultiLineCondition.SpacingAfterOpenBrace" />
    </rule>

    <rule ref="Squiz">
        <exclude name="Squiz.Commenting.ClosingDeclarationComment.Missing" />
        <exclude name="Squiz.Commenting.FileComment.Missing" />
        <exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />
        <exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType" />
        <exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
        <exclude name="Squiz.Files.FileExtension.ClassFound" />
        <exclude name="Squiz.Operators.ComparisonOperatorUsage.ImplicitTrue" />
        <exclude name="Squiz.Operators.ComparisonOperatorUsage.NotAllowed" />
        <exclude name="Squiz.PHP.DisallowComparisonAssignment.AssignedComparison" />
        <exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen" />
        <exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose" />
        <exclude name="Squiz.WhiteSpace.FunctionClosingBraceSpace.SpacingBeforeClose" />
        <exclude name="Squiz.WhiteSpace.FunctionOpeningBraceSpace.SpacingAfter" />
        <exclude name="Squiz.WhiteSpace.FunctionSpacing.After" />
        <exclude name="Squiz.WhiteSpace.FunctionSpacing.AfterLast" />
        <exclude name="Squiz.WhiteSpace.FunctionSpacing.Before" />
        <exclude name="Squiz.WhiteSpace.FunctionSpacing.BeforeFirst" />
    </rule>

    <rule ref="Generic.Formatting.SpaceAfterCast">
        <properties>
            <property name="spacing" value="1" />
        </properties>
    </rule>

    <rule ref="Generic.Formatting.SpaceAfterNot">
        <properties>
            <property name="spacing" value="0" />
        </properties>
    </rule>

    <rule ref="Generic.PHP.ForbiddenFunctions">
        <properties>
            <property name="forbiddenFunctions" type="array">
                <element key="count" value="sizeof"/>
                <element key="print" value="echo"/>
            </property>
         </properties>
    </rule>
</ruleset>

The ruleset seems to work fine in other editor plugins (i.e. linter-phpcs for Atom), so I'm fairly certain that I'm missing an important configuration setting in this plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions