From ba8700a6e501a9539b7a72d1d395649a8263cb69 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 22 Sep 2021 07:32:17 +0200 Subject: [PATCH] eslint: Enable no-var rule `var` has broken/unexpected scoping in JavaScript, and can lead to subtle errors. It's preferable and safer to use `const` whenever possible, and `let` where necessary. Most pages got updated by now, so let's make sure they stay that way. Disable the rule for the four remaining known pages which still use `var`. Also temporarily downgrade the `error` to `warn` when running `npm run eslint`, as that is covered by the unit-tests "distcheck" scenario. This requires touching package.json and thus a node_modules rebuild. --- .eslintrc.json | 1 + node_modules | 2 +- package.json | 2 +- webpack.config.js | 9 +++++++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 03c7935f989..b19fa01f279 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,6 +25,7 @@ "newline-per-chained-call": ["error", { "ignoreChainWithDepth": 2 }], "lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }], "prefer-promise-reject-errors": ["error", { "allowEmptyReject": true }], + "no-var": "error", "react/jsx-indent": ["error", 4], "semi": ["error", "always", { "omitLastInOneLineBlock": true }], diff --git a/node_modules b/node_modules index f233df5d657..855c891ebb1 160000 --- a/node_modules +++ b/node_modules @@ -1 +1 @@ -Subproject commit f233df5d657a3651f51d30db59d5f315594d78a1 +Subproject commit 855c891ebb1f1f804e8b1c12e4eece0f0949c3a5 diff --git a/package.json b/package.json index 4bdab7f2502..1ed37c2c4eb 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "webpack-cli": "^4.7.0" }, "scripts": { - "eslint": "eslint --ext .js --ext .jsx pkg/", + "eslint": "eslint --ext .js --ext .jsx pkg/ --rule 'no-var: warn'", "eslint:fix": "eslint --fix --ext .js --ext .jsx pkg/" } } diff --git a/webpack.config.js b/webpack.config.js index a7a5fe16b3c..729a626db13 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -351,8 +351,13 @@ const plugins = [ }), ]; -if (eslint) - plugins.push(new ESLintPlugin({ extensions: ["js", "jsx"] })); +if (eslint) { + // temporary hack: not all pages got converted to no-var yet; drop this again once they are + const overrideConfig = {}; + if (section === "shell/" || section === 'networkmanager/' || section === "static/" || section === "systemd/") + overrideConfig.rules = { "no-var": "off" }; + plugins.push(new ESLintPlugin({ extensions: ["js", "jsx"], overrideConfig })); +} if (section.startsWith('base1')) plugins.push(new copy({ patterns: base1_fonts }));