Part of #1299710: [meta] Automate the coding-standards part of patch review.

Problem/Motivation

Once core is cleaned up, qa.drupal.org should take code style into account when determining pass or fail. It should make sure all javascript follow our coding standards.

As with all code quality checks, we should allow individual projects to determine whether a coding standards problem fails and halts, or merely reports. This should extend to allowing for different behavior on different test types, such as issue patch versus branch.

The default behavior of the testbot will be to check if a given tool has a configuration file (in this case, .eslintrc.json), and then only perform a review, without halting the test build if it fails.

We can optionally lint only changed files, always linting the whole project if .eslintrc.json has been changed in a patch.

Drupal core currently has a core/package.json file. This file is similar to composer.json, but for packaging JavaScript. This file specifies that core uses eslint for JS linting. ESLint change notice: https://www.drupal.org/node/2274223

Proposed resolution

Implement an npm_install plugin. This plugin will have a configurable start directory, and if there is a package.json file in that directory, it will perform npn install.

Implement an eslint plugin. This plugin will have a configurable start directory. It will check whether an eslint executable exists in {start_directory}/node_packages/eslint/binary/eslint.json, and if it does, use it to lint the project.

Remaining tasks

  • Determine output artifact format.
  • Determine D.O integration.

Related and/or Blocking Issues:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

attiks created an issue. See original summary.

attiks’s picture

Manual testing

npm install eslint
./node_modules/eslint/bin/eslint.js .
attiks’s picture

Warning: do not run this, it will fail hard

✖ 2548 problems (2325 errors, 223 warnings)

The reason of the failures was because it was checking modules and themes as well, so I'm proposing to move it to the core directory, see #2575541: Move ESLint config to core folder

attiks’s picture

FileSize
4.14 KB

First try

nod_’s picture

It's supposed to check all modules and themes, they need to fix their stuff.

attiks’s picture

FileSize
4.17 KB

#5 I guess we need to decide if we want our code standards to be global or not, it was just decided to move phpcs.xml to core so it only applies to core. But this is off-topic for now.

Attached an updated file

attiks’s picture

FileSize
4.17 KB

New patch using config files from core folder

attiks’s picture

FileSize
4.2 KB

Attached patch allows you to run eslint on core, only errors are reported.

To run: ./drupalci run eslint

Output can be found in /var/www/html/artifacts/eslint.xml on the docker container

Running eslint only takes like 10 seconds, but installing nodejs, updating npm and installing eslint can take a couple of minutes, so ideally they will be moved to the docker image.

nod_’s picture

What needs to happen to get that in and have it run on all core patches? I really really want it, I'd do whatever is needed to facilitate.

jthorson’s picture

TODO:

1. Add nodejs / epm / jslint to DrupalCI container definitions
2. Strip install code from this class and commit jslint class to drupalci test runner
3. Add Drupal.org integration code to PIFT code, so that new jslint jobs are triggered on each patch

May require some thought on how to best display results from multiple job types on drupal.org.

jthorson’s picture

Alternatively, as a quick fix, we can add it to the DrupalCI containers and add an eslint command to the simpletest job.

elachlan’s picture

elachlan’s picture

I have added the required change to the container definition in #2580007: Add phantomjs2 to the testrunners. As they are related.

If anyone could have a look and maybe give a review that would be great :)

elachlan’s picture

We now have a separate issue to sort out adding eslint.

#2600626: [PP-1] Ensure availability of node/npm in the testrunners

elachlan’s picture

Issue summary: View changes

Updated issue with more details.

elachlan’s picture

Updated Parent issue, previous issue #1266442: [meta] Implement automated code style checks for core was closed and marked as duplicate.

Changing priority as Parent issue is Major and this is blocking.

elachlan’s picture

YesCT’s picture

Issue tags: +Coding standards
Mile23’s picture

Addressing blockers for this issue: #2654650: [meta] Jobs for linting and coding standards

Mixologic’s picture

Component: Miscellaneous » Jobs and Job Handling
Wim Leers’s picture

Title: DrupalCI should return failed for poor code style - JS » [PP-2] DrupalCI should return failed for poor code style - JS
Mile23’s picture

Issue summary: View changes
Status: Needs review » Needs work
Related issues: +#2600626: [PP-1] Ensure availability of node/npm in the testrunners

Updating IS with new specs based on discovery.

Mixologic’s picture

Assigned: Unassigned » Mixologic

Im currently working on this.

Mixologic’s picture

Status: Needs work » Fixed

Okay, so eslinting is now happening as part of drupalci, and results are showing up on dispatcher.drupalci.org

Next is getting checkstyle results on drupal.org itself - #2854700: DrupalCI: Display or link to checkstyle results on Drupal.org

Mixologic’s picture

Status: Fixed » Needs work

This is mostly working, but we need to shuffle around how its executed.

  • Mixologic committed 1a8873b on 2575501-eslint-execution-adjustments
    Issue #2575501: No need to set the ignore file. either its in the...
  • Mixologic committed 1af8e6e on 2575501-eslint-execution-adjustments
    Issue #2575501: adds eslint to d7
    
  • Mixologic committed 5ee6d16 on 2575501-eslint-execution-adjustments
    Issue #2575501: Updates project type configuration
    
  • Mixologic committed 779908e on 2575501-eslint-execution-adjustments
    Issue #2575501: updates eslint to self discover config files
    
  • Mixologic committed e65dda0 on 2575501-eslint-execution-adjustments
    Issue #2575501: Updates eslint file
    
Mixologic’s picture

Status: Needs work » Fixed

Okay, this should now work they way nod_ and I discussed in IRC. We're letting eslint be responsible for discovering its own config now.

Status: Fixed » Closed (fixed)

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