From 6dd73bf5e7f6a1c49d1c1771069a55598264b307 Mon Sep 17 00:00:00 2001 From: toofar Date: Sat, 6 Apr 2024 18:19:45 +1300 Subject: [PATCH] Begin upgrading to eslint9 Initial migration was just: import yaml with open('.eslintrc.yaml') as f: config=yaml.load(f.read(), yaml.CLoader) with open("eslint.config.js", "w") as f: json.dump(config, f) Then add a new ignores key, figuring out how to import the default "all" config, and the globals. Added some ignore lines for undefined globals in the config file since they are probably legitimately not available in a browser. The `ignores` config item doesn't seem to be working, not sure why. Other than that theres not many warnings from the files that are actually supposed to be linted, so that's good! I have no-idea how much of the rest of the config is or isn't working. --- qutebrowser/javascript/.eslintignore | 5 - qutebrowser/javascript/.eslintrc.yaml | 7 ++ qutebrowser/javascript/caret.js | 2 +- qutebrowser/javascript/eslint.config.js | 136 ++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 6 deletions(-) delete mode 100644 qutebrowser/javascript/.eslintignore create mode 100644 qutebrowser/javascript/eslint.config.js diff --git a/qutebrowser/javascript/.eslintignore b/qutebrowser/javascript/.eslintignore deleted file mode 100644 index 65143f360..000000000 --- a/qutebrowser/javascript/.eslintignore +++ /dev/null @@ -1,5 +0,0 @@ -# Upstream Mozilla's code -pac_utils.js -# Actually a jinja template so eslint chokes on the {{}} syntax. -greasemonkey_wrapper.js -global_wrapper.js diff --git a/qutebrowser/javascript/.eslintrc.yaml b/qutebrowser/javascript/.eslintrc.yaml index 566304c27..d64c26951 100644 --- a/qutebrowser/javascript/.eslintrc.yaml +++ b/qutebrowser/javascript/.eslintrc.yaml @@ -17,6 +17,13 @@ env: extends: "eslint:all" +#ignores: +# # Upstream Mozilla's code +# pac_utils.js +# # Actually a jinja template so eslint chokes on the {{}} syntax. +# greasemonkey_wrapper.js +# global_wrapper.js + rules: strict: ["error", "global"] one-var: "off" diff --git a/qutebrowser/javascript/caret.js b/qutebrowser/javascript/caret.js index 4aeefcdb9..9b4249b53 100644 --- a/qutebrowser/javascript/caret.js +++ b/qutebrowser/javascript/caret.js @@ -1290,7 +1290,7 @@ window._qutebrowser.caret = (function() { if (CaretBrowsing.isDebug) { console.debug(`caret: ${text}`); } - } + }; CaretBrowsing.init = function() { CaretBrowsing.isWindowFocused = document.hasFocus(); diff --git a/qutebrowser/javascript/eslint.config.js b/qutebrowser/javascript/eslint.config.js new file mode 100644 index 000000000..49105013e --- /dev/null +++ b/qutebrowser/javascript/eslint.config.js @@ -0,0 +1,136 @@ +// qutebrowser's way of using eslint is perhaps a bit untypical: We turn on *all* +// the checks eslint has to offer, and then selectively disable/reconfigure the +// ones which got in the way below. +// +// This makes eslint much stricter (which is good). However, it means you might +// run into a case where you totally disagree with what it says, because some +// check is not useful or desired for qutebrowser, but nobody did run into it +// yet. +// +// In those cases, it's absolutely okay to modify this config as part of your PR. +// See it as a way to fine-tune eslint rather than a rigid style guide. +const js = require("@eslint/js"); // eslint-disable-line no-undef +const globals = require("globals"); // eslint-disable-line no-undef +module.exports = [ // eslint-disable-line no-undef + js.configs.all, + { + "languageOptions": { + globals: { + ...globals.browser, + }, + }, + "ignores": [ + // Upstream Mozilla's code + "pac_utils.js", + // Actually a jinja template so eslint chokes on the {{}} syntax. + "greasemonkey_wrapper.js", + "global_wrapper.js", + ], + "rules": { + "strict": [ + "error", + "global", + ], + "one-var": "off", + "padded-blocks": [ + "error", + "never", + ], + "space-before-function-paren": [ + "error", + "never", + ], + "no-underscore-dangle": "off", + "camelcase": "off", + "require-jsdoc": "off", + "func-style": [ + "error", + "declaration", + ], + "init-declarations": "off", + "no-plusplus": "off", + "no-extra-parens": "off", + "id-length": [ + "error", + { + "exceptions": [ + "i", + "n", + "k", + "v", + "x", + "y", + ], + }, + ], + "object-shorthand": "off", + "max-statements": [ + "error", + { + "max": 40, + }, + ], + "quotes": [ + "error", + "double", + { + "avoidEscape": true, + }, + ], + "object-property-newline": [ + "error", + { + "allowMultiplePropertiesPerLine": true, + }, + ], + "comma-dangle": [ + "error", + "always-multiline", + ], + "no-magic-numbers": "off", + "no-undefined": "off", + "wrap-iife": [ + "error", + "inside", + ], + "func-names": "off", + "sort-keys": "off", + "no-warning-comments": "off", + "max-len": [ + "error", + { + "ignoreUrls": true, + "code": 88, + }, + ], + "capitalized-comments": "off", + "prefer-destructuring": "off", + "line-comment-position": "off", + "no-inline-comments": "off", + "array-bracket-newline": "off", + "array-element-newline": "off", + "no-multi-spaces": [ + "error", + { + "ignoreEOLComments": true, + }, + ], + "function-paren-newline": "off", + "multiline-comment-style": "off", + "no-bitwise": "off", + "no-ternary": "off", + "max-lines": "off", + "multiline-ternary": [ + "error", + "always-multiline", + ], + "max-lines-per-function": "off", + "require-unicode-regexp": "off", + "max-params": "off", + "prefer-named-capture-group": "off", + "function-call-argument-newline": "off", + "no-negated-condition": "off", + "no-console": "off", + }, + }, +];