Problem/Motivation
As discussed in #3134731: Update coder to 8.3.9 with @longwave and @jonathan1055, we propose to have phpcs.xml.dist sorted by rule and by sniff. This will assist any work when a new sniff is added. A test will be written to ensure that any patch which adds a new sniff puts it in the correct place.
Furthermore in another issue #3135935: Keep all sniffs in phpcs.xml.dist in sync with the locked version of Coder a proposal to redesign phpcs.xml.dist and write a test to ensure all sniffs (either commented out or not) are in sync with the full list got from the locked version of coder.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #42 | 3135933-42.patch | 15.87 KB | quietone |
| #42 | interdiff-40-42.txt | 2.94 KB | quietone |
| #40 | interdiff_36-40.txt | 952 bytes | ravi.shankar |
| #40 | 3135933-40.patch | 14.26 KB | ravi.shankar |
| #36 | reroll_diff.txt | 7.42 KB | ravi.shankar |
Issue fork drupal-3135933
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jungleComment #3
jungle- sniffers
+ sniffs
Comment #4
jungleThe categories/sub-categories of sniffs won't be sorted globally, just keep it inline with the output above. The Drupal standard with its sub-categories (sub=categories are sorted by default) at the top, followed by the Drupal DrupalPractice standard.
Internal sniffs will be moved to the above of the Drupal standard.
Comment #5
jungleFirst iteration
Before:
After:
Comment #6
jungle2nd intention: sort Drupal sniffs
To verify:
unsorted.txt should be identical with sorted.txt
Comment #7
jungle3rd iteration
1. Nothing to do with generic sniffs.
Before.txt is identical with after.txt
2. MySource: only 1 sniff, skipped
3. Sorted PEAR sniffs: to verify:
unsorted.txt should be identical with sorted.txt
Comment #8
jungle4th iteration (The last)
1. Nothing to do with PSR2 sniffs,
Before.txt is identical with after.txt
2. Sorted Squiz sniffs: to verify:
unsorted.txt should be identical with sorted.txt
3. Zend sniffs, one sniff only, skipped
4. Drupal Practice sniffs, one sniff only, skipped
Comment #9
alexpottHaving another issue to add a test for the changes added here feels unnecessary. If this issue added the test then we can be sure that we'll never need to redo this work. I think this issue should add the sorting test because that's what it fixes.
Comment #10
jungle@alexpott thanks for your review!
From my understanding, the test in other issue planed is to test if all sniffs in phpcs.xml.dist in sync with the list got from the current version of coder locked in composer.lock. The test needed here is to test sorting.
Comment #11
jonathan1055 commentedNice work @jungle.
@alexpott Yes you are right if the sniffs are to be kept in alphabetic order then this issue should also contain a new test to ensure that.
However, I think no more work should be done here until we decide on the questions asked in the other issue #3135935: Keep all sniffs in phpcs.xml.dist in sync with the locked version of Coder. Until we know whether all sniffs (including the ignored/commented out ones) are in the file, or just the active rules which Core can pass on, then that will affect the processing of the sorted test. So let's have the discussion over there first.
Comment #12
andypostThe related sniff has false positives in coder 8.3.9
Comment #13
jonathan1055 commentedHi andypost,
I don't understand why #3123061: Create a sniff to make sure exception messages are not translated is related to this issue?
Comment #14
andypost@jonathan1055 because inclusion of the sniffer depends on coder release, for 8.3.9
DrupalPractice.General.ExceptionTshould be exuded as having false positivesComment #15
jonathan1055 commentedThe sniff
DrupalPractice.General.ExceptionTwas not being added here. It does not appear in the patches above - we are only sorting the existing phpcs.xml.dist here. (maybe the issue title was misleading so I've altered it and updated the issue summary)Comment #16
jungleRe #11, @alexpott commented on #3135935: Keep all sniffs in phpcs.xml.dist in sync with the locked version of Coder, I think we should continue. The patch sorted:
<file>,<description>,<rule>etc. tags sorted.<exclude>tags) sorted.Comment #17
jungleTrying to make the bot work
Comment #18
jonathan1055 commentedHi Jungle,
No I think you have mis-understood. Alexpott said in #3135935-5: Keep all sniffs in phpcs.xml.dist in sync with the locked version of Coder
meaning that we may not have all the sniffs in the file, but now start to list the ones that are excluded. If that is the case then that issue needs to be done first. Unless there is a good reaons to sorting the sniffs now, then remove and change them all in the other issue?
Comment #19
jungleRe #18, from my understanding, the two issues are not tightly relevant/related/bundled.
I am not a native English speaker, please bear with me at sometimes, Thank you @jonathan1055!
Comment #21
spokjeComment #22
spokjeUsed
3135933-17.patchas base for a re-roll in the new MR.Comment #23
spokjeIssue has tests, removing tag.
Comment #25
spokjeComment #27
spokjeRebased against
9.3.x.Comment #30
spokjeSomething went very wrong when rebasing the previous MR on
9.3.x.Close it and opened a new one.
Comment #31
phenaproximaThis largely makes sense to me; I just have some nitpicks and a couple of questions to keep the test robust easy to understand.
Comment #32
spokjeComment #35
spokjeComment #36
ravi.shankar commentedAdded a patch for Drupal 9.5.x. from MR, added reroll diff between MR and patch.
Comment #39
longwaveThe new test is failing because two of the
exclude-patternlines are out of order.Comment #40
ravi.shankar commentedTrying to fix failed tests of patch #36.
Comment #42
quietone commentedRearranging phpcs.xml.dist so it is sorted.
Comment #43
borisson_This test will work differently on php 7.x vs 8.x, because of the behavior change of sorting with items that have same weight. I'm not sure if that means that we should only commit this to the 10.x branch? Otherwise we're introducing a known random failure target.
If this is a worry for nothing, this looks great and it will make maintaining order in the phpcs config file much better. +1
Comment #44
longwaveNot sure why would items have the same weight here? We are sorting by string values, and there should be no duplicates.
Comment #45
alexpottI ran the test on PHP 7 a few times and it passes just fine.
Committed and pushed 6ef6ffcf46 to 10.1.x and 8cd67cbd9f to 10.0.x and a0586047b7 to 9.5.x and 6b96b54fc5 to 9.4.x. Thanks!
Backported to 9.4.x because this is a dev thing and if we do choose to backport a coding standard fix it'll make it easier.