status | implementation | status_last_reviewed |
---|---|---|
accepted |
done |
2024-03-04 |
Update the way we do linting by using Rubocop directly and using NPM-packages to lint CSS and JS.
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.
- 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). - 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.
- 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.
- The scss_lint tool is being deprecated. The authors suggest using a different library.
- 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. - 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. - 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.
- 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.
- Retire the
govuk-lint
gem - Create a new gem called
govuk_rubocop
that includes all rules configuration and a dependency on therubocop
gem - Adopt NPM modules standard for Javascript linting and sass-lint for CSS linting
- All applications that provide a frontend will have a development / CI dependency on Yarn.
- Create new
govuk_rubocop
gem - Update all GOV.UK repos to switch out
govuk-lint
forgovuk_rubocop
, addinherit_gem
to.rubocop.yml
, and add apackage.json
with standard and sass-lint and tasks defined. We would probably be able to automate this. - Update govuk-jenkinslib to automatically
yarn install
and run the linting tasks - Update documentation
- Enable Dependabot for NPM modules in repos