Skip to content

Enhanced support for nested rulesets #380

@shvlv

Description

@shvlv

Is your feature request related to a problem?

The use use-case we are trying to implement is described here - inpsyde/php-coding-standards#81.

In short, we want to introduce template-specific sniffs. It's easy to do with the include-pattern property:

<rule ref="InpsydeTemplates">
    <include-pattern>*/templates/*</include-pattern>
</rule>

But during the discussion, we decided to make InpsydeTemplates extend the existing Inpsyde standard but several sniffs. So the InpsydeTemplates config is:

<rule ref="Inpsyde">
        <exclude name="Inpsyde.CodeQuality.NoElse" />
</rule>

But it seems it's not possible to do what we want to provide proper setup at the consuming package. There are several options:

Option 1

<rule ref="Inpsyde">
        <exclude-pattern>*/templates/*</exclude-pattern>
</rule>

<rule ref="InpsydeTemplates">
     <include-pattern>*/templates/*</include-pattern>
</rule>

It does not work because no Inpsyde specific and imported sniffs are applied to templates directory.

Option 2

<rule ref="Inpsyde" />

<rule ref="Inpsyde">
    <exclude-pattern>*/templates/*</exclude-pattern>
</rule>

<rule ref="InpsydeTemplates">
    <include-pattern>*/templates/*</include-pattern>
</rule>

Imported Inpsyde rules are applied to templates but custom sniffs not.

Option 3

<rule ref="Inpsyde" />

<rule ref="InpsydeTemplates">
    <include-pattern>*/templates/*</include-pattern>
</rule>

It's very close to what we need. The single problem is Inpsyde.CodeQuality.NoElse is still applied to templates what we want to avoid.

Option 3a

The consumer config is the same as above.

The InpsydeTemplates config is:

<rule ref="Inpsyde" />
<rule ref="Inpsyde.CodeQuality.NoElse">
    <severity>0</severity>
</rule>

Inpsyde.CodeQuality.NoElse rule is disabled for whole package.

Describe the solution you'd like

Make the include-pattern (and maybe exclude-pattern) directive more sophisticated. We can use include-pattern to exclude/include sniffs or to define different sniff severity per-directory (regexp).

Additional context (optional)

I briefly checked the PHPCS codebase and saw it's impossible now and may require much effort. After processing all rulesets, we get independent maps of include/ignore patterns and severity per sniff. If so, maybe we can just stick with Option 3. But maybe I missed something.

Thanks a lot for maintaining such an important project!

  • I intend to create a pull request to implement this feature.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions