Automated testing now reports on coding standards violations - see #1299710: [meta] Automate the coding-standards part of patch review. Any file which is altered by a patch gets a full list of standards faults, not just in the lines which are altered by the patch.

The Scheduler 8.x code is clean - see #2861902: Fix coding standards violations in 8.x codebase, now we need to do the 7.x code. As at 26 April there are 194 coding standards notices - see https://www.drupal.org/pift-ci-job/657360

The 7.x code was compliant back in October 2013 #1566024: Coding Standards and Coder Review but the standards have moved on since then.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonathan1055 created an issue. See original summary.

jonathan1055’s picture

Status: Active » Needs review
FileSize
36.43 KB

There are currently 189 coding standards messages over the entire codebase at PHP5.3 and 196 messages at PHP5.4+

This patch fixes tests/scheduler.test, which I want to be clean before adding more tests. Because the entire file is checked and all infringements reported, having it clean before adding new tests makes it easier to check that the additons are compliant.

  • jonathan1055 committed 9fda0ac on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix coding standards in 7.x scheduler....

  • jonathan1055 committed f4727f2 on 7.x-1.x
    Issue #2872885 by jonathan1055: Tidy up after coding standards in 7.x...
jonathan1055’s picture

After scheduler.test the standards messages reduced to 145.
Here's a patch for scheduler.admin.inc

jonathan1055’s picture

Title: Fix coding standards violations in 7.x codebase » Fix coding standards in 7.x
FileSize
6.39 KB

Intersting that one coding standards message "Do not concatenate strings to translatable strings, they should be part of the t() argument and you should use placeholders" (Drupal.Semantics.FunctionT.ConcatString) is detected on d.o. running PHP5.3 but is allowed and not classed as a problem at PHP5.4+ (hence why it slipped through)

  • jonathan1055 committed d769504 on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix coding standards in 7.x scheduler....
jonathan1055’s picture

Down to 137 messages after fixing scheduler.admin.inc
Here's a patch for readme.txt, scheduler.api.php and scheduler.cron.inc

  • jonathan1055 committed 5507f13 on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix coding standards in 7.x for readme....
jonathan1055’s picture

Down to 114 messages after fixing readme, api.php and cron.inc

Here's a patch for fixing .drush.inc, .edit.inc, .info and .install

  • jonathan1055 committed 84e5078 on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix coding standards in 7.x for .drush....
jonathan1055’s picture

Down to 102 now.
Here's a patch for .module

  • jonathan1055 committed 60811f2 on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix coding standards in 7.x for .module
    
jonathan1055’s picture

Down to 59 messages.
Patch for .rules.inc, rules_defaults.inc, tokens.inc and views.inc. Plus one 'drupal practice' fix for .install which was missed before.

  • jonathan1055 committed 1b4bb64 on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix coding standards in 7.x for .rules....
jonathan1055’s picture

Now only 28 messages left to fix.
Here's a patch for tests/scheduler_api.test and scheduler_handler_field_scheduler_countdown.inc (which also required a change in scheduler.views.inc).

This should be the last coding standards patch, but there may be one more for Drupal Practice. However, some of those suggestions may not be fixable.

  • jonathan1055 committed e700733 on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix coding standards in 7.x for tests/...
jonathan1055’s picture

Remaining coding standards messages: ZERO :-)

jonathan1055’s picture

Here is a patch which fixes two of the three files with coding practice messages. As these are not reported in d.o. tests, the violations that this patch fixes are:

FILE: /Library/WebServer/Documents/drupal7/sites/all/modules/scheduler/scheduler.edit.inc
---------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 1 LINE
---------------------------------------------------------------------------
 186 | WARNING | Do not use the raw $form_state['input'], use $form_state['values'] instead where possible
 186 | WARNING | Do not use the raw $form_state['input'], use $form_state['values'] instead where possible
---------------------------------------------------------------------------

and


FILE: /Library/WebServer/Documents/drupal7/sites/all/modules/scheduler/scheduler.tokens.inc
---------------------------------------------------------------------------
FOUND 0 ERRORS AND 8 WARNINGS AFFECTING 8 LINES
---------------------------------------------------------------------------
 57 | WARNING | Variable $publish_on is undefined.
 58 | WARNING | Variable $publish_on is undefined.
 63 | WARNING | Variable $unpublish_on is undefined.
 64 | WARNING | Variable $unpublish_on is undefined.
 75 | WARNING | Variable $publish_on is undefined.
 76 | WARNING | Variable $publish_on is undefined.
 78 | WARNING | Variable $unpublish_on is undefined.
 79 | WARNING | Variable $unpublish_on is undefined.
---------------------------------------------------------------------------

  • jonathan1055 committed 9958c32 on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix best practice standards for edit.inc...
DamienMcKenna’s picture

Any further work planned for this? You might just run phpcbf on the codebase and see what happens. I ran it and the only change that showed was on the JS file.

jonathan1055’s picture

Thanks for pointing this out. My phpcs alias had a long list of --extensions but 'js' was missing, hence I never saw these.

Interestingly my version reports different fixes to yours. I have

 23 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
 38 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found

which yours did not fix. But the indentation and @see are not reported in my list.

  • jonathan1055 committed 56bf2ba on 7.x-1.x
    Issue #2872885 by jonathan1055, DamienMcKenna: Fix coding standards in 7...
jonathan1055’s picture

  1. Coder module on a 7.x site reports
    scheduler.edit.inc
    severity: normalreview: style_stdclassLine 30: use stdClass caseCapitalization, it's the one exception to the mixed case style standard [style_stdclass]
    $defaults = new StdClass();
    
  2. scheduler_handler_field_scheduler_countdown.inc
    severity: minorreview: comment_comment_docblock_missingLine 51: Docblock should be immediately above SchedulerHandlerFieldSchedulerCountdown::option_definition (Drupal Docs) [comment_comment_docblock_missing]
    public function option_definition() {
    
  3. scheduler.test
    severity: minorreview: comment_comment_see_inlineLine 606: @see should always be at the beginning of a line, never inline in other comments. (Drupal Docs) [comment_comment_see_inline]
    @see https://drupal.org/node/1614880
    
  4. drupalcsp reports:
    FILE: /Library/WebServer/Documents/drupal7/sites/all/modules/scheduler/scheduler.admin.inc
    -----------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------
     426 | WARNING | Do not use the raw $form_state['input'], use $form_state['values'] instead where possible
    -----------------------------------------------------------------------------
    

None of these are reported on d.o. testing.
Patch fixes 1 and 3 and sets to ignore 2 and 4.

  • jonathan1055 committed a18cd00 on 7.x-1.x
    Issue #2872885 by jonathan1055: Fix coding standards in edit.inc and ....
jonathan1055’s picture

Title: Fix coding standards in 7.x » Fix coding standards and best practice in 7.x
Status: Needs review » Fixed

7.x coding standards and best practices now have no warnings on d.o. testbot output, running coder 7.x-2.6 and using drupalcs and drupalcsp.

So I think we can close this issue as fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.