Closed (fixed)
Project:
Drupal Code Sniffer
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Dec 2011 at 04:59 UTC
Updated:
26 May 2012 at 18:20 UTC
Module implementing Views plugins should use Views conventions. I'm pretty sure I saw some discussion about this in IRC, I guess it was just for a project review, not for this.
Class name must begin with a capital letter
Class name must use UpperCamel naming without underscores
Method name "views_plugin_display::option_definition" is not in lowerCamel format, it must not contain underscores
Comments
Comment #1
das-peter commentedHmm, is there a smart way how we can switch the standard of the sniffer just for views?
Comment #2
klausiI don't think that modules should use the Views conventions, the should at least stick to the UpperCamelCase Drupal conventions for classes.
Methods are a problem if they are overridden (so the name can't be fixed), we could retrieve the class definition that belongs to the method and check if it extends another class beginning with "views_".
Comment #3
das-peter commentedSounds like a plan and a lot of work ;)
Comment #4
tim.plunkettThe plan for the method sounds fine, but why not check the same for the class name? If it extends a class like views_, let it go?
Views brought the first OO approach to Drupal, and there are hundreds of modules that integrate with it. Please don't decide every Views-based module will automatically fail this test.
Comment #5
klausiIt is no shame if a module does not pass all code sniffer rules, because the coding standards change and evolve all the time. There will always be some legacy code in some modules that does not satisfy the newest standards, so I'm not convinced that we should implement and maintain exceptions. However, I know that Views is big - so I would say patches welcome.
Comment #6
ericduran commentedYea, a lot most of the views, ctools, features, and a lot of exported code don't actually follow the drupal conventions.
For now I think we should keep following the conventions and hopefully eventually everyone else will follow. :-/
Comment #7
ericduran commentedSo I'm trying to figure out if this is an actual documentation problem or a bug.
By the looks of it this might be a bug. I can't find anywhere in the coding standard implying that the class name must be camel case. If this does exist can anyone point me to it.
If not we probably should just remove this sniff.
Comment #8
ericduran commentedOh the OO docs are http://drupal.org/node/608152
We still need to figure out what to do here.
Comment #9
tim.plunkettThis is more than just Views, it's also Context.
Looking at the newest of D7 OO modules, i.e. Rules and Commerce, they use proper CamelCase for all new classes, but follow the conventions of the class they are extending.
class CommerceTaxUIAdminTest extends CommerceBaseTestCaseclass commerce_payment_handler_field_amount extends views_handler_fieldModules can't switch class names mid-development without possibly hosing current installs.
Comment #10
klausiWho says a module needs to pass all drupalcs checks? Just because it can't be easily fixed it is still an error, right?
Comment #11
tim.plunkettBecause it makes it unusable as a tool for bringing code up to standards. The hosted version of PAreview also runs drupalcs, and it makes it easy to miss other rules when surrounded by dozens of useless warnings about camel case.
If you are refusing to fix it, we'll just have to remove it from usage and stick to the other 3 coding standards modules.
Comment #12
klausiI'm not refusing to fix, I just won't do it myself. So again: patches welcome.
Comment #13
klausiOh, and of course all the old-style modules can be fixed:
Of course drupalcs will still throw errors for the backward compatibility class, but only on a limited part of the code base that is dedicated to backwards compatibility.
Comment #14
das-peter commentedI'm happy to hear that drupalcs is used :)
I think the essential thing here is to find a consensus about what has which priority and also how to handle different use cases.
I would like to continue the work on drupalcs but unfortunately I'm absolutely buried in project work.
Assuming that klausi is in a similar situation it's essential to set priorities for the different tasks.
I think it's quite some effort to integrate a dependency aware sniff for class names - and if my assumption above applies whether klausi nor I do have the time to build this feature.
It's another thing if someone provides a patch, I'll happily take care about such one...
If providing a patch isn't a solution, how about using the configuration options of PHP_CodeSniffer? A possible solution could be to define the sniffs to execute - see Limiting Results to Specific Sniffs
Comment #15
ericduran commentedI know right now some modules don't pass the sniff. But they don't all have to.
If excluding certain sniff is really important drupalcs can be configured to ignore that sniff.
I don't think we should write the code to support old coding standards. Even if old is last week ;-)
Comment #16
ericduran commentedAlso technically switching class names is a lot easier now in D7 because of the registry.
So essentially all the classes can be switch to use camelCase and all that would be required for any install would be to use a tool like Registry Rebuild to rebuild the registry.
Comment #17
tim.plunkettComment #18
klausiLet's keep this open for further suggestions/ideas.
Comment #19
carn1x commentedSo is "Class" or "class" correct for Drupal? As I've just spent hours fighting ctools_plugin_get_class() and finally found that it's only detecting my class definition with the lower case variant.
EDIT: Created a new issue http://drupal.org/node/1513110
Comment #20
klausi"class" is of course correct for the PHP language keyword.
Comment #21
markdorisonI agree with ericduran that we shouldn't write code to support old standards. As much as it pains me to not see every test pass, I think that it is OK.
Comment #22
acouch commentedIf this doesn't work for Views it is just an intellectual exercise.
Comment #23
tim.plunkettWell, at the very least, an 8.x-1.x branch should be opened for this module instead so its clear that it's following the D8 coding standards, since changes to coding standards are not backported to previous versions.
Comment #24
klausi@tim.plunkett: but all new code written for D6 or D7 should follow the current version of coding standards. From from http://drupal.org/coding-standards
Comment #25
klausiFixing title, as the OO coding standards were introduced even 1.5 years before Drupal 7 was released.
Comment #26
tim.plunkettIt's like you've never used Views before. Unbelievable. Unfollowing the issue.
Comment #27
klausiI do use Views and Ctools a lot and they are great modules. Still, their coding standards are wrong in this regard. Untill somebody comes up with a patch to work around views and ctools in ValidFunctionNameSniff and ValidClassNameSniff here is the additional config for ruleset.xml to run drupalcs without those sniffs on your views/ctools code:
Comment #28
tim.plunkettThat's fixed enough for me. Thanks klausi.