Problem/Motivation
Drupal.org uses American English and this sniff uses the British spelling for 'color'. See Content style guide
For Drupal core, this requires that the word 'colour' is maintained in the list of misspelled words.
There are other sniff names and error codes that CSpell reports, which unfortunately have spelling errors. To maintain backwards-compatibility these cannot be fixed, as they can be referenced in contrib phpcs.xml files or phpcs:ignore comments.
Proposed resolution
Rename the sniffs
Add the following to the core drupal dictionary of words to allow and ignore
ColourDefinitionSniff
SeletorSingleLine
TeamplateSpacingAfterComment
TforValue
TrhowsCommentIndentation
UnecessaryFileDeclaration
Remaining tasks
Issue fork coder-3418190
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:
- 3418190-rename-colourdefinitionsniff-to
changes, plain diff MR !23
Comments
Comment #4
keshav patel commentedRenamed ColourDefinitionSniff to ColorDefinitionSniff, Please Review.
Comment #5
klausiI'm not a big fan of renaming sniffs as then this will break all phpcs configurations that exclude this sniff for example.
What could we do to preserve compatibility?
Also instead of doing this: How easy is it to make an exception in Drupal core in the phpcs.xml.dist config file so that the spell checker ignores this instance?
Side note: Coder is developed on Github, please create pull requests there once we come to a conclusion here. https://github.com/pfrenssen/coder/pulls
Comment #6
klausiSetting to "needs work" to get some answers on my previous comments.
Comment #7
quietone commented@klausi, sorry it too so long to get back. This was brought to my attention again because of a new core issue that I just moved to Coder. Like this one it about a sniff name that does not pass cspell checks. #3464824: cspell complains about DrupalPractice.General.OptionsT.TforValue.
It is true that an exception can be added although I have not yet included it in a spelling issue in core.
However, I still think that Coder itself should follow the Drupal spelling standard and change the name. In principle I think that is the correct action, even though I appreciate the challenges of renaming things and the work to deprecate. And now that there are two issues about the problem maybe this needs more thought?
On the other hand, I don't know how many current sniffs may violate the current core usage of cspell. Maybe the way to go is to just prevent future misspelling. Is there any practice in Coder to ensure that new sniffs follow American English and pass cspell checks?
Comment #8
klausiI think enabling cspell checking in Coder is a very good idea, so that we at least prevent future spelling problems. Started a draft PR at https://github.com/pfrenssen/coder/pull/233 , not finished yet. Should probably be done as separate issue and then we can continue the discussion here what to do about already established sniff names and error codes.
Comment #9
klausiOpened #3465767: Enable cspell checking in Coder to track that.
Comment #10
jonathan1055 commentedEnabling cspell in Coder is an excellent and vital thing to do, to ensure no new sniff names are invalid. But I agree with klausi that renaming a sniff now will break more things than it solves. I did a quick codebase search for
ColourDefinitionSniffand found 29 occurences - many of these are in /vendor/ and I also note that Squizlabs has the same English spelling. We cannot rename a sniff without breaking all of those projects.I think the most realistic solution will be to add the two sniff names (or rather, the section of the sniff name that fails as a word) into one of Drupal's own spelling dictionaries https://git.drupalcode.org/project/drupal/-/tree/11.x/core/misc/cspell?r... These are used in the gitlab cspell job, so will be fixed for all contrib.
Comment #11
jonathan1055 commentedRenamed this issue. There are potentially six sniff parts that need to be added to the dictionary - see the list in #2 on #3465767-2: Enable cspell checking in Coder
Comment #12
quietone commentedWhat about adding a correctly named sniff that is a wrapper for the incorrectly named one?
Comment #13
quietone commentedAlso, how do I get this sniff to fail in core? I changed a color to upper case and it was not detected.
Comment #15
klausiIt looks like in the Drupal core phpcs.xml.dist config you forgot to add the CSS file extensions that you want to check.
Maybe there is generated CSS in core that we don't want to check and that's why it was never enabled?
Wrapper sniff: that is an interesting idea, how could we do that without breaking existing configurations? Then both sniffs would run and duplicate the errors messages, could we prevent that?
Otherwise I agree with jonathan1055, we should add those names as exceptions to Drupal core's cspell config.
Comment #17
jonathan1055 commentedI have just tested the six sniffs and error codes that Klausi listed on #3465767-2: Enable cspell checking in Coder
Each word in a CamalCase string resets the search (this is probably obvious and known to you, but worth mentioning anyway). So the actual words to add to the core dictiionary would be the part words that are misspelled:
The English speling of colour is already in the core/misc/cspell/dictionary.txt, so that does not currently fail the cspell checks in contrib.
My test job is https://git.drupalcode.org/issue/scheduler-3356800/-/jobs/3883429
Comment #18
klausiHm, but adding those partial words would be bad. Can we add the full words like "SeletorSingleLine" to the dictionary? Then it only matches this exact misspelling from Coder.
Comment #19
jonathan1055 commentedYes you are right, that is better. Even though adding the short word is sufficient, adding the full sniff name/code will also match and not report the word.
Here's another test - in which I added 'SeletorSingleLine' and 'Teamplate' to the project dictionary. You can see that the long string 'TeamplateSpacingAfterComment' is not reported, showing that the short word 'teamplate' is sufficient (but we won't be adding that)
The short word 'seletor' in the test file is reported as wrong, but the full word 'SeletorSingleLine' is passed as OK, which is exactly what we want.
https://git.drupalcode.org/issue/scheduler-3356800/-/jobs/3884432
So it is the six long strings as listed in #17 above which are needed in the core dictionary. When that is done, we can remove the
cspell:ignoreadded in the Coder files.What would be the appropriate place to request these words to be added?
Comment #20
klausiProbably Drupal core core/misc/cspell/drupal-dictionary.txt is the canonical home of the cspell dictionary? I would assume that one is used for gitlab runs https://git.drupalcode.org/project/gitlab_templates/-/blob/main/scripts/...
Comment #21
jonathan1055 commentedI didn't frame the question very well, what I meant was which issue queue should that request be made? Is it just a plain core issue? or infrastructure? It's not really a coding standards issue.
Both of the core files are used in the contrib gitlab job. It may be better to add them to the smaller drupal-specifc misc/cspell/drupal-dictionary.txt as it is Drupal source code which has created the incorrect spellings.
Comment #22
klausiDrupal core changes will need a drupal core issue. All drupal core changes are handled in the drupal core issue queue, so best open one there.
Comment #23
jonathan1055 commentedI've updated the issue summary and changed the project to Core, instead of starting a new issue.
Comment #24
quietone commentedComment #25
klausiCoder 9 has fixed the cspell typos in #3556778: Fix spelling in sniff error codes.
Comment #26
quietone commentedNone of the suggested additions to the dictionary are in Drupal core. I don't see what work there is here for core. Also 'colour' is no longer in core.
I am returning this to the Coder project because there is a commit here for that project.
Comment #27
klausiThanks, this has been fixed in Coder 9. Please test!
Comment #29
jonathan1055 commentedBelow is the comment I wrote, which overlapped with @klausi in #27
OK, that's fine. Also I don't think there is anything more for Coder to do, as the incorrectly spelled sniffs have been renamed in Coder 9.
We have resolved the problem that Contrib has (that is, when needing to reference those sniffs), by adding the words listed in #17 as additional allowed words in the CSpell job. See this Gitlab Templates commit from issue #3494834: Add common words not in core dictionaries. We did this back in January as an interim measure, but if the core dictionaries are not going to be changed then it can stay in Gitlab Templates permanently.
I've set this to 'fixed' as there is nothing more to 'review', but if I've missed anything, then do re-open it.