coder icon indicating copy to clipboard operation
coder copied to clipboard

refactor(FullyQualifiedNamespace): Replace sniff in favor of a sniff from Slevomat

Open klausi opened this issue 2 years ago • 6 comments

Issue: https://www.drupal.org/project/coder/issues/3214374

The goal would be to delete our FullyQualifiedNamespace sniff and switch to using the one from Slevomat.

Was not able to complete this yet because of a bug in Slevomat https://github.com/slevomat/coding-standard/issues/1564

klausi avatar Apr 30 '23 20:04 klausi

You've probably realised this, but the failing tests for standards is because the new file tests/Drupal/good/GoodNamespace.php is not excluded when checking Coder's own files:

    <!-- Test files that should not be checked. -->
    <exclude-pattern>tests/*\.(inc|css|js|api\.php|tpl\.php)$</exclude-pattern>
    <exclude-pattern>tests/*/(good|bad)\.php$</exclude-pattern>
    <exclude-pattern>tests/*/drupal(6|7|8)/*\.php$</exclude-pattern>

The patterns above seem to exclude nearly all files in the tests/good/ folder but not everything. Am I right in thinking that all files in the tests/good folder should follow Drupal standards, and hence they are excluded because Coder uses a different customised set for it's own files? If so, we could exclude everything from tests/good in one statement, rather than try to cater for most files over the three patterns.

Sorry if this is wrong, I've not looked in great detail at what is not excluded from the above three.

jonathan1055 avatar May 01 '23 17:05 jonathan1055

Yep, this is not ready for review yet, was just uploading my work in progress here.

klausi avatar May 02 '23 08:05 klausi

Sorry, yes of course. But I've done some learning in the meantime, I wanted to see if we could exclude everything in /good except the GoodUnitTest.php but I could not get a neagative pattern to work, so the easiest thing would be to add GoodNamespace into the tests/*/(good|GoodNamespace|bad)\.php$ pattern

jonathan1055 avatar May 02 '23 09:05 jonathan1055

Created upstream bug report at https://github.com/slevomat/coding-standard/issues/1570

klausi avatar May 06 '23 09:05 klausi

That bug was resolved, yay!

Now some test fails remain where Slevomat gets confused by multiple use statements, it somehow thinks one is a constant.

Not sure if we should simply drop this test case from Coder and not care about it anymore, or if we should try to improve the Slevomat sniff.

klausi avatar May 06 '23 11:05 klausi

Reported the constant confusion upstream: https://github.com/slevomat/coding-standard/issues/1581

klausi avatar Jun 09 '23 15:06 klausi