PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Avoid incompatible sniffs running together

Open fredden opened this issue 3 years ago • 4 comments

Generic.WhiteSpace.ScopeIndent and PSR2.Methods.FunctionCallSignature both try to fix indentation differently. This results in files not being able to be fixed automatically with phpcbf.

See https://github.com/squizlabs/PHP_CodeSniffer/issues/2078#issuecomment-401641650 where @gsherwood says that Generic.WhiteSpace.ScopeIndent should win in these cases.

This pull request fixes #2078 by eliminating the incompatibility when both sniffs are being run. When Generic.WhiteSpace.ScopeIndent is not active, then PSR2.Methods.FunctionCallSignature will continue to work as normal. When Generic.WhiteSpace.ScopeIndent is active, then this particular code-path will be ignored/skipped.

fredden avatar Jul 13 '22 15:07 fredden

I haven't tested this enough it seems. I'll mark this as a draft for now.

fredden avatar Jul 13 '22 15:07 fredden

  1. Do you have a code sample demonstrating the conflict ?
  2. Could that code sample be added to the test file ?
  3. As for referencing another sniff via a hard-coded name to avoid conflicts: that's generally not the way to solve these type of issues.

jrfnl avatar Jul 13 '22 16:07 jrfnl

  1. Do you have a code sample demonstrating the conflict ?

Yes, see https://github.com/squizlabs/PHP_CodeSniffer/issues/2078#issuecomment-401641650.

  1. Could that code sample be added to the test file ?

I've been working on this, and it's difficult. I expect to update the pull request with this soon.

  1. As for referencing another sniff via a hard-coded name to avoid conflicts: that's generally not the way to solve these type of issues.

I agree. Can you suggest a viable alternative in this case?

fredden avatar Jul 19 '22 10:07 fredden

I'm not winning at adding a test case for this. Please can someone help?

fredden avatar Oct 23 '22 11:10 fredden