From 6a23a5ddc8b384b368bfb76e11bc66224f02b33d Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 8 Jun 2023 10:03:58 +0100 Subject: [PATCH 1/9] Update ESLint config to target ES2015 (ES6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We may take this higher once we confirm the browser support guarded by our “cut the mustard” checks --- packages/govuk-frontend/.eslintrc.js | 9 +++------ .../src/govuk/components/error-summary/error-summary.mjs | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/govuk-frontend/.eslintrc.js b/packages/govuk-frontend/.eslintrc.js index e2d7273f7a..26d53131b4 100644 --- a/packages/govuk-frontend/.eslintrc.js +++ b/packages/govuk-frontend/.eslintrc.js @@ -12,7 +12,7 @@ module.exports = { excludedFiles: ['**/*.test.mjs'], parser: '@typescript-eslint/parser', parserOptions: { - // Note: Allow ES6 for import/export syntax + // Note: Allow ES2015 for import/export syntax ecmaVersion: '2015', project: [resolve(__dirname, 'tsconfig.json')] }, @@ -23,21 +23,18 @@ module.exports = { extends: [ 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking', - 'plugin:es-x/restrict-to-es5' + 'plugin:es-x/restrict-to-es2015' ], env: { browser: true }, rules: { - // Allow unknown `.prototype` members until ES6 classes + // Allow unknown `.prototype` members until ES2015 classes '@typescript-eslint/no-unsafe-member-access': 'off', // Allow `this` alias until arrow functions supported '@typescript-eslint/no-this-alias': 'off', - // Rollup transpiles modules into other formats - 'es-x/no-modules': 'off', - // Allow `var` until let/const supported 'no-var': 'off', diff --git a/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.mjs b/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.mjs index e771e07a6e..2adf263ded 100644 --- a/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.mjs +++ b/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.mjs @@ -20,7 +20,7 @@ function ErrorSummary ($module, config) { // working the same now we read the elements data attributes if (!($module instanceof HTMLElement)) { // Little safety in case code gets ported as-is - // into and ES6 class constructor, where the return value matters + // into and ES2015 class constructor, where the return value matters return this } From 5e990739600d3d344654a3d7098e3edd17ba32f1 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 8 Jun 2023 13:51:00 +0100 Subject: [PATCH 2/9] Remove ESLint rule `'no-var'` for let/const support --- .eslintrc.js | 5 +---- packages/govuk-frontend/.eslintrc.js | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d5ab59e3de..0dc96f8f86 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -127,10 +127,7 @@ module.exports = { // Ignore paths to example modules 'import/no-unresolved': 'off', - 'n/no-missing-import': 'off', - - // Allow `var` in example code - 'no-var': 'off' + 'n/no-missing-import': 'off' } } ], diff --git a/packages/govuk-frontend/.eslintrc.js b/packages/govuk-frontend/.eslintrc.js index 26d53131b4..850f276b9b 100644 --- a/packages/govuk-frontend/.eslintrc.js +++ b/packages/govuk-frontend/.eslintrc.js @@ -35,9 +35,6 @@ module.exports = { // Allow `this` alias until arrow functions supported '@typescript-eslint/no-this-alias': 'off', - // Allow `var` until let/const supported - 'no-var': 'off', - // JSDoc blocks are mandatory 'jsdoc/require-jsdoc': [ 'error', { From 876e88647807cfb48cdffdba5bb4e52d8c989971 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 8 Jun 2023 14:34:25 +0100 Subject: [PATCH 3/9] Run `eslint --fix` --- docs/contributing/coding-standards/js.md | 6 +- .../examples/scoped-initialisation/index.njk | 2 +- .../cookie-banner-client-side/index.njk | 12 +- .../cookie-banner-essential-cookies/index.njk | 4 +- .../cookie-banner-server-side/index.njk | 6 +- packages/govuk-frontend/src/govuk/all.mjs | 24 ++-- .../govuk/common/closest-attribute-value.mjs | 2 +- .../govuk/common/govuk-frontend-version.mjs | 2 +- .../govuk-frontend/src/govuk/common/index.mjs | 32 ++--- .../src/govuk/common/normalise-dataset.mjs | 6 +- .../govuk/components/accordion/accordion.mjs | 110 +++++++++--------- .../src/govuk/components/button/button.mjs | 8 +- .../character-count/character-count.mjs | 44 +++---- .../components/checkboxes/checkboxes.mjs | 32 ++--- .../src/govuk/components/details/details.mjs | 16 +-- .../error-summary/error-summary.mjs | 26 ++--- .../notification-banner.mjs | 4 +- .../src/govuk/components/radios/radios.mjs | 28 ++--- .../govuk/components/skip-link/skip-link.mjs | 6 +- .../src/govuk/components/tabs/tabs.mjs | 64 +++++----- packages/govuk-frontend/src/govuk/i18n.mjs | 24 ++-- .../tasks/build/package.test.mjs | 2 +- 22 files changed, 230 insertions(+), 230 deletions(-) diff --git a/docs/contributing/coding-standards/js.md b/docs/contributing/coding-standards/js.md index 9f70f8b0e5..e62c4dd024 100644 --- a/docs/contributing/coding-standards/js.md +++ b/docs/contributing/coding-standards/js.md @@ -39,7 +39,7 @@ Example.prototype.init = function () { } // Code goes here - var $module = this.$module + const $module = this.$module } export default Example @@ -117,10 +117,10 @@ When initialising an object, use the `new` keyword. ```mjs // Bad -var myExample1 = Example() +const myExample1 = Example() // Good -var myExample2 = new Example() +const myExample2 = new Example() ``` ## Modules diff --git a/packages/govuk-frontend-review/src/views/examples/scoped-initialisation/index.njk b/packages/govuk-frontend-review/src/views/examples/scoped-initialisation/index.njk index b5d0cd4140..f372059eea 100644 --- a/packages/govuk-frontend-review/src/views/examples/scoped-initialisation/index.njk +++ b/packages/govuk-frontend-review/src/views/examples/scoped-initialisation/index.njk @@ -47,7 +47,7 @@ {% block bodyEnd %}