-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Squiz fixer conflict in file with side effects #2033
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
Comments
I think I'd get ClassDeclaration to not throw an error if the class is followed by a function. But it probably doesn't matter given this sort of code is unlikely to be encountered anyway, so whatever is easier is fine I think. |
…a class is followed by a function (ref #2033)
I ended up going with ClassDeclaration not throwing an error when followed by a function. Haven't removed the parse errors from test files yet though. |
I ran those two sniffs over the test files and they produced fixed content without issue, so I'm not sure if there are any conflicts in the test files. If you find some though, please let me know and I'll fix. |
@gsherwood Thank you! I hadn't gotten round to doing this myself yet. |
The following code sample will give a fixer conflict when the
Squiz
ruleset is run against it as theSquiz.Classes.ClassDeclaration
sniff demands exactly one blank line after a class, while theSquiz.WhiteSpace.FunctionSpacing
sniff demands exactly two blank lines before a function.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).
The text was updated successfully, but these errors were encountered: