cakephp-codesniffer icon indicating copy to clipboard operation
cakephp-codesniffer copied to clipboard

TabAndSpace.DoubleSpace incorrectly detects within the line

Open utdrmac opened this issue 4 months ago • 6 comments

The documentation for this sniff clearly states the following:

Check for any line starting with 2 spaces

However, the sniff will incorrectly trigger on line 2 in this example:

	private array $bufferRequests = [];
	private bool $inBuffer        = false;

The first 2 characters of both lines are tab. The failure of this sniff is that it is checking the entire contents of the line, looking for double space. This is not what the docs say this sniff does. Furthermore, as currently implemented, this behavior conflicts with Generic.Formatting.MultipleStatementAlignment which says that multiple assignment lines should be aligned, as the example above shows.

Please fix this sniff to correctly, and only, search the beginning of the line for violation.

utdrmac avatar Oct 10 '25 21:10 utdrmac

@ADmad Do you know what this sniff was meant to do?

othercorey avatar Oct 10 '25 23:10 othercorey

From https://github.com/cakephp/cakephp-codesniffer/commit/dd0592448fb3f861c5d60cb76db56ef79294cf43 Probably a bit outdated. Most of the indentation should be taken care off by other sniffs now I assume.

And the inline "anti pattern" of alignment would be a different sniff and responsibility either way.

dereuromark avatar Oct 10 '25 23:10 dereuromark

Our standard doesn't use tabs, so frankly I don't really care if a sniffs creates errors from those who do. One can simply disable that sniff in their app config.

ADmad avatar Oct 11 '25 03:10 ADmad

"it doesn't affect me, so I don't care" Nice attitude buddy. Anyways, it's still a valid bug for the rest of the world who might do things differently.

utdrmac avatar Oct 11 '25 15:10 utdrmac

You can make a PR with a suggested fix.

Note: If you are using Tabs you can also consider using psr2r sniffer ruleset. It has also more advanced sniffer on top

dereuromark avatar Oct 11 '25 17:10 dereuromark

Should we deprecate/drop this in favor of different sniffs?

othercorey avatar Oct 11 '25 22:10 othercorey