Skip to content

Squiz fixer conflict in file with side effects #2033

Closed
@jrfnl

Description

@jrfnl

The following code sample will give a fixer conflict when the Squiz ruleset is run against it as the Squiz.Classes.ClassDeclaration sniff demands exactly one blank line after a class, while the Squiz.WhiteSpace.FunctionSpacing sniff demands exactly two blank lines before a function.

class MyClass2
{
    var $x;
}

/** ************************************************************************
 * Example with no errors.
 **************************************************************************/
function example() {}

This can be prevented from either sniff by checking either that the next non-empty token is a function keyword (ClassDeclaration) or that the previous non-empty token is a close brace of an OO construct (FunctionSpacing) and bowing out if that's the case.

@gsherwood I'm not sure which of the two sniffs should have precedence, i.e. which sniff should be adjusted ? Guidance appreciated.
I'm happy to prepare the PR once it's clear what the desired fix should be.

Also: there are a number of unintentional parse errors in test files where global functions are prefixed with a visibility keyword. Those would need to be fixed too, as otherwise the fixer conflict would still show (previous/next non-empty would be the visibility keyword breaking the fix).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions