Problem/Motivation
Fields with exceptionally long names throw a coder warning when exported.
Coding standards state:
Lines containing longer function names, function/class definitions, variable declarations, etc are allowed to exceed 80 chars.
Control structure conditions may exceed 80 chars, if they are simple to read and understand:
Steps to reproduce:
1. Create a field with a very long exported name. This is especially easy to do when the field in a field collection. Example: // 'field_collection_item-field_alpha_channel_sponsored-field_alpha_sponsor_bundle_title'
2. Export above field using features.
3. Run phpcs with Drupal standards.
4. Coder returns: Line exceeds 80 characters; contains 92 characters
.
Proposed resolution
Code sniffer should not throw a warning if the comment string contains no spaces.
Comment | File | Size | Author |
---|---|---|---|
#3 | wrap-long-field-names-2466961-3.patch | 2.39 KB | markdorison |
#1 | wrap-long-field-names-2466961-1.patch | 2.43 KB | markdorison |
Comments
Comment #1
markdorisonThe attached patch solves the issue when wrapping the identifier under the prefix will result in two comment lines both under 80 characters:
I don't have a proposed solution if the identifier itself is over 80 characters (which I have seen) but this is an improvement that probably covers a large number of cases.
Comment #2
markdorisonComment #3
markdorisonSmall style change.
Comment #4
tflanagan CreditAttribution: tflanagan commentedThis looks good and is very much needed. I have had to manually do what your code does when codesniffer doesn't like something!
Comment #5
mpotter CreditAttribution: mpotter commentedThis seems to work well for me.
Comment #6
bedlamWorks for me as well. Would be nice to eliminate this particular source of PHPCS warnings.
Comment #7
mpotter CreditAttribution: mpotter commentedCommitted to 598d4e5.
Comment #9
markdorisonSuper pleased to see this committed. Since the commit was an improvement and not a complete fix of the problem, I am going to reopen the issue so we can continue to track (and hopefully fully resolve) this issue.
Comment #10
joelpittet@markdorison what needs to be further done here?
Comment #11
markdorison@joelpittet I updated the summary; the short answer is I am not sure. How do we pass Drupal code standards of comments no longer than 80 characters long when we are outputting a comment of a field's name that is longer than 80 characters? Some (maybe not great) ideas:
1. Chop the field name in the middle at an underscore and wrap it to two lines.
2. Truncate the field name.
3. Not include the comment line if it is longer than 80 characters.
Comment #12
joelpittet@markdorison We have a bit of leniency it seems when variables and URLs escape the bounds of this rule, though I'm not sure how the automated tools like coder or CodeSniffer deal with this?
So personally I'd let it run;)
Comment #13
markdorison@joelpittet The problem is that the automated tools flag this since it is technically not following Drupal code standards. Anyone using Features who is also automating those tests is going to have a hard time getting them to pass cleanly which is frustrating.
Comment #14
joelpittetMaybe those concessions can be added to the automated tools?
https://www.drupal.org/coding-standards#linelength
Comment #15
markdorison@joelpittet Thanks for pointing out that exception. At this point, I am moving the issue back to the Coder issue queue and updating the summary.
Comment #16
klausiCould you post an example code snippet to the issue summary that demonstrates the false positive in Coder? And this should be fixed in 8.x-2.x first.
Comment #17
benjy CreditAttribution: benjy at PreviousNext commentedThere is a bug in the regex that checks the "Contains" line, it should also match underscore characters.
Comment #18
klausi@benjy: that does not seem to be related to this issue, could you file a new issue? There should be an issue somewhere that deals with the "Contains ..." line.
Comment #19
benjy CreditAttribution: benjy at PreviousNext commented@klausi, ah crap, i had both issues open and commented on the wrong one: https://www.drupal.org/node/2530920#comment-10516578
That's where it went in, not sure if you want a follow-up?
Comment #20
markdorison@klausi: Updated summary with a new field name export example that fails the current tests:
Comment #21
klausiThis has been fixed in Coder with some other issue. If the comment line is only one word then Coder will not complain if it exceeds 80 characters.
Please test!
Comment #23
sureshravi CreditAttribution: sureshravi commentedHi, guys am doing a phpcs drupal standard for my Drupal project. whenever i hit the cmd in terminal phpcs --standard=Drupal .\test.php
it's throwing a warning Line exceeds 80 characters; contains 86 characters. how can I resolve this? Without changing line exceeds the rule(phpcs XML config rule)