Skip to content

Commit

Permalink
https://github.com/wikimedia/eslint-config-wikimedia
Browse files Browse the repository at this point in the history
Why switch?
- it's standard for wikimedia projects
- it has some cool features such as jquery deprecation warnings, and enforcing a specific version of JavaScript
- I believe it has many more rules than our previous configuration, which will help with identifying areas of the code to modernize

What this patch does
- delete all old linter rules, except for these rules I carried over:
	- `no-nested-ternary`
	- `no-restricted-syntax` for `.done()` and `.fail()`
- upgrade eslint a couple minor versions
- add eslint-config-wikimedia and its default rules
- disable controversial rules such as
	- whitespace in parentheses (`space-in-parens`, `space-before-function-paren`, `array-bracket-spacing`, `computed-property-spacing`, `object-curly-spacing`)
	- max line length 100 (`max-len`)
- disable some rules
	- `indent` because it would involve touching almost every line, messing up git blame (although I may autofix this in the future and set a .git-blame-ignore-revs to reduce git blame spam)
	- `wrap-iife` to reduce VS Code yellow underline spam (will autofix this in a future patch)
	- couple others that I don't like and have disabled in my other projects
- set it to ES6 since wikimedia "modern layer" support is now on ES6
- warn/error for syntax or internal functions higher than ES6 (this is more thorough than the old >ES6 detection we were using)
- set all remaining detected violations to "warn" for now, so that CI passes
- will apply autofixes for all the rules that "warn" in a future patch

The rules are in two groups, with an extra line break in the middle separating them.
- The top group are rules that should not be fixed
- The bottom group are rules that should be fixed over time via autofixes and manual fixing. Once everything for that rule is fixed, that rule can be deleted, so that the linter starts enforcing it in CI.

Over time, rules will be fixed and removed from the config, and the code will be incrementally modernized, until it arrives at the Wikimedia standard.
  • Loading branch information
NovemLinguae committed Jun 22, 2024
1 parent e87b051 commit d4f15ae
Show file tree
Hide file tree
Showing 3 changed files with 1,578 additions and 167 deletions.
113 changes: 58 additions & 55 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,23 @@
{
"parserOptions": {
"emcaVersion": 6
},
"extends": ["eslint:recommended"],
"extends": [
"wikimedia/client/es6",
"wikimedia/jquery",
"wikimedia/mediawiki"
],
"root": true,
"env": {
"browser": true,
"jquery": true,
"es6": true
},
"globals": {
"jQuery": "readonly",
"mw": "readonly",
"Map": "readonly"
},
"ignorePatterns": ["scripts/", "tests/", "lib/"],
"rules": {
"no-console": "error",
"no-extra-parens": ["error", "all", { "nestedBinaryExpressions": false }],
"no-unreachable-loop": "error",
"block-scoped-var": "error",
"curly": "error",
"default-case": "error",
"dot-notation": "error",
"eqeqeq": "error",
"guard-for-in": "error",
"no-caller": "error",
"no-else-return": "error",
"no-implicit-coercion": ["error", { "boolean": false }],
"no-lone-blocks": "error",
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"no-useless-return": "error",
"yoda": "error",
"block-spacing": "error",
"brace-style": ["error", "1tbs"],
"comma-dangle": "error",
"comma-spacing": ["error", { "before": false, "after": true }],
"computed-property-spacing": ["error", "never"],
"func-call-spacing": ["error", "never"],
"indent": ["error", "tab", { "outerIIFEBody": 0, "SwitchCase": 1 }],
"key-spacing": ["error", {"singleLine": {"beforeColon": false, "afterColon": true}}],
"keyword-spacing": ["error", { "after": true, "before": true}],
"linebreak-style": ["error", "unix"],
"no-array-constructor": "error",
"no-bitwise": "error",
"no-mixed-operators": "error",
"no-new-object": "error",
"no-tabs": ["error", { "allowIndentationTabs": true }],
"no-trailing-spaces": "error",
"no-unneeded-ternary": "error",
"no-whitespace-before-property": "error",
"quote-props": ["error", "consistent-as-needed"],
"quotes": ["error", "single", { "avoidEscape": true }],
"semi": ["error", "always"],
"space-before-blocks": "error",
"space-in-parens": ["error", "never"],
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": ["error", "always", { "line": { "exceptions": ["-"] }, "block": { "balanced": true } }],
"switch-colon-spacing": "error",
"array-bracket-spacing": "off",
"camelcase": "off",
"computed-property-spacing": "off",
"max-len": "off",
"no-jquery/no-class-state": "off",
"no-jquery/no-global-selector": "off",
"no-nested-ternary": "error",
"no-restricted-syntax": [
"warn",
Expand All @@ -69,7 +29,50 @@
"message": "Using .fail() is discouraged. See https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Asynchronous_code",
"selector": "MemberExpression > Identifier[name=\"fail\"]"
}
]
},
"reportUnusedDisableDirectives": true
],
"no-shadow": "off",
"no-underscore-dangle": "off",
"object-curly-spacing": "off",
"space-before-function-paren": "off",
"space-in-parens": "off",
"unicorn/prefer-string-slice": "off",

"arrow-parens": "warn",
"dot-location": "warn",
"es-x/no-array-prototype-includes": "warn",
"es-x/no-object-values": "warn",
"indent": "off",
"jsdoc/require-asterisk-prefix": "warn",
"mediawiki/class-doc": "warn",
"new-cap": "warn",
"new-parens": "warn",
"no-alert": "warn",
"no-jquery/no-constructor-attributes": "warn",
"no-jquery/no-each-util": "warn",
"no-jquery/no-extend": "warn",
"no-jquery/no-grep": "warn",
"no-jquery/no-in-array": "warn",
"no-jquery/no-map-util": "warn",
"no-jquery/no-parse-html-literal": "warn",
"no-jquery/no-sizzle": "warn",
"no-jquery/variable-pattern": "warn",
"no-loop-func": "warn",
"no-multi-spaces": "warn",
"no-multiple-empty-lines": "warn",
"no-new": "warn",
"no-return-assign": "warn",
"no-script-url": "warn",
"no-sequences": "warn",
"no-throw-literal": "warn",
"no-unneeded-ternary": "warn",
"no-unused-expressions": "warn",
"no-use-before-define": "warn",
"no-useless-concat": "warn",
"no-var": "warn",
"operator-linebreak": "warn",
"prefer-arrow-callback": "warn",
"prefer-const": "warn",
"quote-props": "warn",
"wrap-iife": "off"
}
}
Loading

0 comments on commit d4f15ae

Please sign in to comment.