Skip to content

Commit

Permalink
eslint: Enable no-var rule
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
martinpitt committed Sep 22, 2021
1 parent a498f6c commit ba8700a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],

Expand Down
2 changes: 1 addition & 1 deletion node_modules
Submodule node_modules updated 2067 files
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
}
}
9 changes: 7 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down

0 comments on commit ba8700a

Please sign in to comment.