Problem/Motivation
Coder has a hard check on 80 characters for any comment line, as per current coding standard. Good or bad standard, that breaks on plugin and entity docblocks.
Plugins and Entities both have annotations, which often specify long class names as values. Those class names, in practice, are longer than 80 characters with alarming frequency. Add to that the necessary padding at the start of the line for the annotation key, indentation, the comment * itself, etc. and so far every single entity I've defined has had annotation lines that cannot ever be less than 80 characters. Yet coder chokes on them and rejects every last one, so any time I touch an entity/plugin class I need to skip coder checks.
The problem also affects the @file block at the top of the file if the class name is long, too.
This is sad making.
Proposed resolution
Whitelist annotation-based docblocks and @file docblocks so that they are not checked for line length.
Comment | File | Size | Author |
---|---|---|---|
#14 | 2530920-14.patch | 1.59 KB | benjy |
#14 | 2530920-14-FAIL.patch | 573 bytes | benjy |
#8 | 2530920-8.patch | 3.05 KB | pfrenssen |
Comments
Comment #1
tatarbjHere is my patch which can handle the mentioned @file block problem.
I'm trying to collect the annotations which can be whitelisted, if someone can help in it it would be great.
Comment #2
tatarbjNew patch with the test cases, the 6th one should be failed but it doesn't. Any idea why?
Comment #3
tatarbjComment #5
klausiI committed a fix for the "Contains ..." lines in @file comments, so that they are allowed to be longer than 80 characters. I added the test to the "good" cases to make sure it does not interfere with other sniffs (all rules are run on the "good" test files which must never throw errors).
What is left for annotations, do we have an example test case?
Comment #6
pfrenssenI have one! I have one!
Here's a real life annotation that triggers it, the admin paths are too long. We can adapt this to be a somewhat realistic example:
Comment #7
pfrenssenHere's already a failing test.
Comment #8
pfrenssenAnd a fix. I have removed the check for long
@Translate
lines, these are also part of annotations so we don't need to check for it any more.Comment #9
klausiWrong docs: An annotation does not have to map to a class name. Should be replaced with "An annotation start with a "@" followed by letters and ending with a '('.
We don't need $matches here, just compare the result of preg_match() === 1.
This patch also means that comments after an annotation will not throw error if they exceed 80 characters, example:
But I think that is an acceptable trade-off for now since we rarely have comments after annotations, right?
Comment #11
klausiCommitted a raw regex fix that should cover the long cases.
Comment #12
benjy CreditAttribution: benjy at PreviousNext commentedThere is a bug in the regex that checks the "Contains" line, it should also match underscore characters.
Comment #13
klausiComment #14
benjy CreditAttribution: benjy at PreviousNext commentedLets try this.
Comment #15
klausiYour FAIL patch is not actually failing ;-)
Fixed the test and committed it, thanks!