Skip to content

Commit

Permalink
Merge pull request #8178 from alphagov/1653-tech-spike-more-opinionat…
Browse files Browse the repository at this point in the history
…ed-es6-rules

Use standard for linting JavaScript
  • Loading branch information
dnkrj authored Sep 5, 2023
2 parents bdeb92e + 7cd3125 commit 928e7b2
Show file tree
Hide file tree
Showing 11 changed files with 1,118 additions and 609 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
extends: 'standard',
ignorePatterns: [
'app/assets/javascripts/vendor/',
'app/assets/javascripts/admin_legacy/**/*',
'spec/javascripts/admin_legacy/**/*'
],
env: {
browser: true,
jquery: true,
jasmine: true,
es6: true
},
globals: {
GOVUK: 'readonly',
GOVUKAdmin: 'readonly'
}
}
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ jobs:

lint-scss:
name: Lint SCSS
uses: alphagov/govuk-infrastructure/.github/workflows/stylelint.yml@main
with:
files: "app/assets/stylesheets/"
uses: ./.github/workflows/lintscss.yml

lint-javascript:
name: Lint JavaScript
uses: alphagov/govuk-infrastructure/.github/workflows/standardx.yml@main
with:
files: "'app/assets/javascripts/**/*.js' 'spec/javascripts/**/*.js'"
uses: ./.github/workflows/lintjs.yml

lint-ruby:
name: Lint Ruby
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/lintjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Run lint:js

on: workflow_call

jobs:
run-lint-js:
name: Run Standardx
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Run lint:js
run: yarn run lint:js
17 changes: 17 additions & 0 deletions .github/workflows/lintscss.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Run lint:scss

on: workflow_call

jobs:
run-lint-scss:
name: Run Stylelint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Run lint:scss
run: yarn run lint:scss
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
/failures
/node_modules
/yarn-error.log
.cache/
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
GOVUK.analytics.trackEvent(
'pageElementInteraction',
target.checked ? 'checkboxClickedOn' : 'checkboxClickedOff',
{ label: label }
{ label }
)
})
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/components/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
const category = $select.getAttribute('data-track-category')
const label = $select.getAttribute('data-track-label')
if (category && label) {
window.GOVUK.analytics.trackEvent(category, query, { label: label })
window.GOVUK.analytics.trackEvent(category, query, { label })
}

let matchingOption
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/components/image-cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
guides: false,
zoomable: false,
highlight: false,
minCropBoxWidth: minCropBoxWidth,
minCropBoxHeight: minCropBoxHeight,
minCropBoxWidth,
minCropBoxHeight,
rotatable: false,
scalable: false
})
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/components/miller-columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};

topics.forEach(function (topic) {
topicSuggestions.push({
topic: topic,
topic,
highlightedTopicName: topic.topicName.replace(/<\/?mark>/gm, ''), // strip existing <mark> tags
breadcrumbs: topic.topicNames
})
Expand All @@ -41,7 +41,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
new window.accessibleAutocomplete({ // eslint-disable-line no-new, new-cap
id: input.id,
name: input.name,
element: element,
element,
minLength: 3,
autoselect: false,
source: function (query, syncResults) {
Expand Down
26 changes: 7 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,12 @@
"license": "MIT",
"scripts": {
"lint": "yarn run lint:js && yarn run lint:scss",
"lint:js": "standardx 'app/assets/javascripts/**/*.js' 'spec/javascripts/**/*.js'",
"lint:js": "eslint --cache --cache-location .cache/eslint --color --ignore-path .gitignore -- \"**/*.js\"",
"lint:scss": "stylelint app/assets/stylesheets/",
"jasmine:prepare": "RAILS_ENV=test bundle exec rails assets:clobber assets:precompile",
"jasmine:ci": "yarn run jasmine:prepare && yarn run jasmine-browser-runner runSpecs",
"jasmine:browser": "yarn run jasmine:prepare && yarn run jasmine-browser-runner"
},
"standardx": {
"env": {
"browser": true,
"jquery": true,
"jasmine": true,
"es6": true
},
"globals": [
"GOVUK",
"GOVUKAdmin"
],
"ignore": [
"app/assets/javascripts/vendor/",
"app/assets/javascripts/admin_legacy/**/*",
"spec/javascripts/admin_legacy/**/*"
]
},
"dependencies": {
"accessible-autocomplete": "alphagov/accessible-autocomplete-multiselect",
"choices.js": "^10.2.0",
Expand All @@ -38,10 +21,15 @@
"paste-html-to-govspeak": "^0.3.0"
},
"devDependencies": {
"eslint": "^8.47.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-n": "^16.0.0",
"jasmine-browser-runner": "^2.2.0",
"jasmine-core": "^5.1.1",
"postcss": "^8.4.29",
"standardx": "^7.0.0",
"standard": "^17.1.0",
"stylelint": "^15.10.3",
"stylelint-config-gds": "^1.0.0"
},
Expand Down
Loading

0 comments on commit 928e7b2

Please sign in to comment.