Skip to content

Commit

Permalink
Install node based JS and SCSS linters
Browse files Browse the repository at this point in the history
This is added to this project as part of roll-out across GOV.UK of stylelint
to replace scss_lint-govuk as the default linter.

This project previously didn't have any JS linting installed so Standard is
installed as per the GDS Way [1]. For SCSS linting stylelint-config-gds [2]
is used which is a GDS standard based upon stylelint [3]. Both of these
projects are then added to dependabot to have their versions maintained with
the same approach we use for rubocop-govuk.

Standardx is used instead of standard because Standard 16 introduced a rule
that disallowed the use of `var`, instead preferring `let` or `const` [4].
This conflicts with the GOV.UK approach where we tend to not embrace features
that we know will break old browsers even if they're not necessarily supported
[5], disallowing var will mean that < IE 11 will be unable to run any of the JS.

In order to customise standard rules this project has switched to using
standardx [6] which allows us to disallow rules. I've used this so we
can disallow the 'no-var' rule.

[1]: https://gds-way.cloudapps.digital/manuals/programming-languages/js.html#linting
[2]: https://github.com/alphagov/stylelint-config-gds
[3]: https://stylelint.io/
[4]: standard/standard#633
[5]: alphagov/govuk_publishing_components#1611 (comment)
[6]: https://github.com/standard/standardx
  • Loading branch information
kevindew committed Dec 3, 2020
1 parent a8aafe1 commit 5f42852
Show file tree
Hide file tree
Showing 5 changed files with 2,893 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Expand Up @@ -27,6 +27,20 @@ updates:
- dependency-name: sassc-rails
dependency-type: direct

- package-ecosystem: npm
directory: /
schedule:
interval: daily
allow:
# Internal packages
- dependency-name: stylelint-config-gds
dependency-type: direct
# Framework packages
- dependency-name: standardx
dependency-type: direct
- dependency-name: stylelint
dependency-type: direct

# Ruby needs to be upgraded manually in multiple places, so cannot
# be upgraded by Dependabot. That effectively makes the below
# config redundant, as ruby is the only updatable thing in the
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -23,3 +23,7 @@

# Zeus config
/custom_plan.rb

# Yarn
/node_modules
/yarn-error.log
1 change: 1 addition & 0 deletions Jenkinsfile
Expand Up @@ -6,6 +6,7 @@ REPOSITORY = 'release'

node {
govuk.buildProject(
beforeTest: { sh("yarn install") },
sassLint: false,
)
}
31 changes: 31 additions & 0 deletions package.json
@@ -0,0 +1,31 @@
{
"name": "release",
"description": "Admin application for GOV.UK",
"private": true,
"author": "Government Digital Service",
"license": "MIT",
"scripts": {
"lint": "yarn run lint:js && yarn run lint:scss",
"lint:js": "standardx 'app/assets/javascripts/**/*.js'",
"lint:scss": "stylelint app/assets/stylesheets/"
},
"standardx": {
"env": {
"browser": true,
"jquery": true
}
},
"eslintConfig": {
"rules": {
"no-var": 0
}
},
"stylelint": {
"extends": "stylelint-config-gds/scss"
},
"devDependencies": {
"standardx": "^7.0.0",
"stylelint": "^13.8.0",
"stylelint-config-gds": "^0.1.0"
}
}

0 comments on commit 5f42852

Please sign in to comment.