Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 4.79 KB

rfc-100-linting.md

File metadata and controls

59 lines (42 loc) · 4.79 KB
status implementation status_last_reviewed
accepted
done
2024-03-04

RFC 💯: Update linting system

Summary

Update the way we do linting by using Rubocop directly and using NPM-packages to lint CSS and JS.

Background

At present, we use a gem called govuk-lint for linting in our projects.

  • It's a wrapper around rubocop, a community driven styleguide for Ruby, so that we can have central configuration files that specify our linting rules
  • It also adds the --diff --cached commands to rubocop, which allow us to lint only the changed files
  • It provides a wrapper for scss_lint to provide shared rules for CSS. These tools are used by the Design System team, are well maintained and have an autocorrect feature.

We wrote about introducing linting in 2016.

Issues

  1. Rubocop now has a native way of sharing rules: you include rules by specifing inherit_gem in .rubocop.yml. This has been successfully trialed in content-performance-manager. As mentioned in that PR, this makes the linting faster and makes it compatible with developer environments (see this issue from 2016 for evidence of a need).
  2. A lot of hard work has gone into fixing older Ruby linting violations (for example in finder-frontend). This has allowed us to turn off the "diffing" behaviour for most projects - we now lint all of the code all of the time.
  3. We currently do not lint our Javascript. This is a gap first raised in 2016 and further discussed in an issue talking about Standard.js.
  4. The scss_lint tool is being deprecated. The authors suggest using a different library.
  5. The CSS linting hasn't been fully adopted in GOV.UK projects - only a few frontend applications have it enabled. Others explicitly disable it. The main reason for this is that scss_lint does not have an autocorrect feature, so it's a significant (and boring) investment to adopt the linting for older projects.
  6. While govuk-lint has been adopted by a lot of Ruby projects in GDS and wider government, the CSS linting feature isn't always used. Projects that don't use CSS still need to pull in the scss_lint dependency.
  7. Last year, GOV.UK Frontend (part of the Design System) was officially launched. Since this is the defacto standard for building frontend things in government, GOV.UK should be adopting the same tools it uses. This will allow us to easily push things upstream and re-use GOV.UK Frontend patterns.
  8. There's been a shift in the Ruby community regarding the use of Javascript packages. Where previously it was preferred to use tools written in Ruby like scss_lint, Rails now ships with Yarn and supports Webpack.

Proposal

  1. Retire the govuk-lint gem
  2. Create a new gem called govuk_rubocop that includes all rules configuration and a dependency on the rubocop gem
  3. Adopt NPM modules standard for Javascript linting and sass-lint for CSS linting

Consequences

Impact

  • All applications that provide a frontend will have a development / CI dependency on Yarn.

Implementation

  1. Create new govuk_rubocop gem
  2. Update all GOV.UK repos to switch out govuk-lint for govuk_rubocop, add inherit_gem to .rubocop.yml, and add a package.json with standard and sass-lint and tasks defined. We would probably be able to automate this.
  3. Update govuk-jenkinslib to automatically yarn install and run the linting tasks
  4. Update documentation
  5. Enable Dependabot for NPM modules in repos