Problem/Motivation
Currently Drupal.Commenting.InlineComment.InvalidEndChar is ignored if the comment starts with the string cspell. There are two issues with that:
- Per the documentation both the strings
cSpell and spell-checker are allowed as well, so we should apply the same handling in those cases
- If an "actual" comment precedes the cspell comment line, the exception is not triggered. For example the following stanza:
// Give a reason for the following cspell line.
// cspell:ignore bananarama
would lead to the $commentText being Give a rason for the following cspell line. cpsell:ignore banarama and that does not start with cspell so it would be raised as an error
Steps to reproduce
Add the following to a file:
// cspell:ignore bananarama
and see that it correctly does not raise a warning.
Add any of the following to a file:
// cSpell:ignore bananarama
// spell-checker:ignore bananarama
// Ignore the word "banarama".
// cspell:ignore bananarama
and see it incorrectly (?!) raises a warning.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
tstoecklerOops forgot to link the docs in the issue summary.
Comment #3
quietone commentedJust ran into this with core. It is certainly a nuisance that only 1 spelling of cspell is recognized.
Comment #4
quietone commentedIn core the following are also detected and reported as errors.
This,
// cspell:ignore·fffffg, fails when on line 719 on the file but not on line 19. I copied and pasted the line. And similar withcspell:ignore·tést·fïle·nàmeit fails on line 101 but passes on line 13. And the// cspell:enableafter the disable mentioned about is not reported as an error. But if I move the 'disable' a line down, it is not detected. For these cases, maybe it because the line before is also an in-line comment and coder thinks it is more text.Comment #5
quietone commentedSince this is detecting valid spellings of cspell as errors as well as valid cspell lines as error, I am changing this to a bug.
It is also blocking core issue #2719663: Fix 'Drupal.Commenting.InlineComment.InvalidEndChar' coding standard
Comment #6
klausiThanks for reporting, I pushed a fix!
Comment #7
jonathan1055 commentedFor reference, this is the commit you made
https://git.drupalcode.org/project/coder/-/commit/b4972e78ac25e514ee00e1...
I think there were actually two problems reported in the issue summary, and only one has been dealt with here.
The change from the specific
strpos($commentText, 'cspell:')to the more generalpreg_match('/(cspell|spell\-checker):ignore/i', $commentText)certainly solves the problem. But this, technically, is too relaxed. It means that if 'cspell:ignore' or 'spell-checker:ignore' are found anywhere in the comment then the comment will be ignored. So if 'cspell:ignore' was put in the middle of a line, say when refering to it in text, that would still be matched. I know this is a rare edge case, so maybe its OK. But is does also mean that the actual real comment text is not checked for the end char. For exampleSetting back to 'needs work' so that the issue does not automatically close just yet, to allow the discussion to continue. I can help on the sniff, I am not saying you have to do the work :-)
Comment #8
jonathan1055 commentedAlso as per the cSpell documentation, we should allow 'spellchecker' without a hyphen. And we should remove 'ignore' from the regex, because this change should also cater for 'disable', 'disable-next-line' and 'enable'. So just having ':' at the end of the regex pattern should be sufficient.
Comment #9
klausiThanks, good points.
For the too relaxed edge case: I think we don't care. I assume it would make the sniff code more complex to detect/split comments. But I'm very happy to review and accept pull requests that try to address this!
For the additional keywords: I think your proposal makes sense to just match for the colon at the end of the regex pattern and add "spellchecker". I will check if I can do that quickly now.
Comment #11
klausiOK, that was quick and we already changed the regex to only match for the colon.
Closing this as fixed again, please make a new issue if you want to address the too relaxed edge case :-)