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.

Here's an example from a patch which changed .module
coding standards in .module

It will be helpful if we gradually fix these faults over the entire Scheduler 8.x codebase. I think it is better to fix the standards separately from other bug-fix patches, so that the commit details do not get confusing by altering lines which are not related to the actual issue being addressed. The full dev branch test indicates that we have 553 coding standards faults (as at 19 March 2017). Takling all at once is too big a task, so maybe file by file, or groups of related files, using this issue to test and track the progress.

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
10.47 KB

Here's the first patch - just for the .module file.

Interestingly the full daily testing includes messages about requiring short array syntax, but the individual patch testing does not have these.

jonathan1055’s picture

Not sure if this is right, but I've added use Drupal\node\Entity\NodeType; to fix the warning regarding line 495:
$node_types = \Drupal\node\Entity\NodeType::loadMultiple();

jonathan1055’s picture

  • jonathan1055 committed febe7ca on 8.x-1.x
    Issue #2861902 by jonathan1055: Fix coding standards for .module
    
jonathan1055’s picture

The test output in https://www.drupal.org/pift-ci-job/626021 is empty for coding standards problems so I have committed these changes. It will be useful to see what the full -dev test shows for .module and whether it agrees that the file is clean.

[edit] Ha, I missed one array()

  • jonathan1055 committed 8938d5b on 8.x-1.x
    Issue #2861902 by jonathan1055: Fix coding standards for .module part 2
    
jonathan1055’s picture

scheduler.module is now clean. Overall count reduced by 32, from 553 to 521.

I wonder why the short array syntax messages are not included in patch testing but are part of the standard and are included in the overall -dev daily/on commit tests. Bit annoying as it leads to more work if you miss one.

  • jonathan1055 committed f388543 on 8.x-1.x
    Issue #2861902 by jonathan1055: Fix coding standards violations for...
jonathan1055’s picture

The next four files README.txt, /plugins/content_types/scheduler_form_pane.inc, /scheduler.admin.inc and /scheduler.api.php are now clean. Down to 468 coding messages in total.

Also using phpcs --standard=DrupalPractice it showed that there was an unused variable $entity in scheduler.module which I have now removed.

  • jonathan1055 committed b96e021 on 8.x-1.x
    Issue #2861902 by jonathan1055: Fix coding standards for .drush.inc, ....
jonathan1055’s picture

The above commit for .drush.inc, .install, .tokens.inc, .views.inc and scheduler_handler_field_scheduler_countdown.inc take the violations count down to 398. All files in the root /scheduler directory are now clean.

Now going to work on the /scheduler_rules_integration folder files

  • jonathan1055 committed 4447bdf on 8.x-1.x
    Issue #2861902 by jonathan1055: Coding standards for Rules Integration...
jonathan1055’s picture

Now down to 266 coding messages. All files in the module root folder are clean. Now going to do the /tests folder.

  • jonathan1055 committed 30b27d3 on 8.x-1.x
    Issue #2861902 by jonathan1055: Coding standards for test modules...

  • jonathan1055 committed eb3fdfd on 8.x-1.x
    Issue #2861902 by jonathan1055: Fix coding standards - test files A-M
    

  • jonathan1055 committed 9816449 on 8.x-1.x
    Issue #2861902 by jonathan1055: Fix coding standards - test files N-Z
    

  • jonathan1055 committed 0e1960a on 8.x-1.x
    Issue #2861902 by jonathan1055: Fix test files for Drupal Practice that...
jonathan1055’s picture

Now only 49 coding standards violations remaining. All in /src files.

  • jonathan1055 committed 3c258c6 on 8.x-1.x
    Issue #2861902 by jonathan1055: Fix coding standards in /src and...
jonathan1055’s picture

Now we have zero coding standards violations. The entire Scheduler codebase is clean. Here is the output from phpcs with the file names removed.

PHP CODE SNIFFER REPORT SUMMARY
----------------------------------------------------------------------
FILE                                                  ERRORS  WARNINGS
----------------------------------------------------------------------
...
----------------------------------------------------------------------
A TOTAL OF 0 ERRORS AND 0 WARNINGS WERE FOUND IN 94 FILES
----------------------------------------------------------------------

Time: 4.9 secs; Memory: 23Mb

I have also run phpcsp to check and clean up Drupal Best Practice violations. There were hundreds of these but now just 25 warnings over 7 files. Apart from the 'dependencies' prefix in .info.yml which is not possible to fix for contrib modules all of the remaining 'best practice' warnings have @TODO notes marking them as needing fixing. It was out of scope to do those in this issue and will be followed up separately.

jonathan1055’s picture

For the record, here is the checkstyle output from 19 March before any corrections - 553 warnings
https://dispatcher.drupalci.org/job/drupal_contrib/20253/checkstyleResult/

28th March after fixing all files in root folder and rules_integration, down to 266 warnings
https://dispatcher.drupalci.org/job/drupal_contrib/24228/checkstyleResult/

30th March after fixing /tests, down to 49 warnings
https://dispatcher.drupalci.org/job/drupal_contrib/25141/checkstyleResult/

Now all clean - if there are no warnings you do not get a separate output, just "Checkstyle: 0 warnings from one analysis" on the build front page
https://dispatcher.drupalci.org/job/drupal_contrib/25156/

jonathan1055’s picture

Title: Fix coding standards violations » Fix coding standards violations in 8.x codebase
Status: Needs review » Fixed
Related issues: +#2868553: Fix the code to adhere to Drupal Best Practice

I have raised #2868553: Fix the code to adhere to Drupal Best Practice as a follow-up. Our 8.x codebase is clean for the current set of coding standards so marking this issue fixed. Another follow-up for 7.x coding standards could be started, as the rules have changed since we last cleaned the 7.x code.

jonathan1055’s picture

For the record, here are screen shots of the test output and build output - in case these become unavailable on the links above.

Status: Fixed » Closed (fixed)

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

jonathan1055’s picture

Following from #3002206-37: Update the stable version of drupal/coder to ˆ8.3.1 Scheduler shows the same problem in the drupalci console
https://dispatcher.drupalci.org/job/drupal8_contrib_patches/53370/console

Here is a patch which creates coding standards fault - it will be useful to see if these are reported on d.o. now.

jonathan1055’s picture

Status: Closed (fixed) » Needs review

"Needs Review" to allow patch testing

jonathan1055’s picture

Status: Needs review » Fixed

A fix has been applied to drupalci - see #3002206-44: Update the stable version of drupal/coder to ˆ8.3.1 and we no longer get the conflict, and hence coding standards are now being checked again.

Status: Fixed » Closed (fixed)

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