1
0
forked from mirrors/0ad

Use @stylistic/brace-style for eslint

Up to now `eslint-plugin-brace-rules` was used to enforce a common brace
style for JavaScript code. This plugin was however updated the last time
over 9 years ago and will be incompatible with ESLint v10, as that
[removes `context.getSourceCode()`][1], the plugin relies on.

To keep the eslint config working with ESLint v10, this replaces
`eslint-plugin-brace-rules` with the [`@stylistic/brace-style`][2] rule
from `@stylistic/eslint-plugin`, a package we already use.

While `@stylistic/brace-style` doesn't offer an option to format braces
in exactly the same way as before, the "allman" style seems to be the
one closest to the existing code.

[1]: https://eslint.org/blog/2025/11/eslint-v10.0.0-alpha.0-released/#removed-deprecated-rule-context-members
[2]: https://eslint.style/rules/brace-style
This commit is contained in:
Dunedan
2025-12-30 09:57:37 +01:00
parent 8f8d1195c2
commit 93ce94655d
259 changed files with 4643 additions and 3421 deletions
+2 -34
View File
@@ -3,7 +3,6 @@
// [1] https://nodejs.org/api/esm.html#esm_no_node_path
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const braceRules = require("eslint-plugin-brace-rules");
const stylistic = require("@stylistic/eslint-plugin");
@@ -123,6 +122,7 @@ const configStylistic = {
},
"rules": {
"@stylistic/brace-style": ["warn", "allman", { "allowSingleLine": true }],
"@stylistic/comma-spacing": "warn",
"@stylistic/indent": ["warn", "tab", { "outerIIFEBody": "off" }],
"@stylistic/key-spacing": "warn",
@@ -147,41 +147,9 @@ const configStylistic = {
};
const configBracesRules = {
"plugins": {
"brace-rules": braceRules
},
"rules": {
"brace-rules/brace-on-same-line": [
"warn",
{
"FunctionDeclaration": "never",
"FunctionExpression": "ignore",
"ArrowFunctionExpression": "always",
"IfStatement": "never",
"TryStatement": "ignore",
"CatchClause": "ignore",
"DoWhileStatement": "never",
"WhileStatement": "never",
"ForStatement": "never",
"ForInStatement": "never",
"ForOfStatement": "never",
"SwitchStatement": "never",
},
{
"allowSingleLine": true,
}
],
}
};
const configs = [configIgnores, configEslintRecommended];
Object.assign(configs[1].rules, configEslintExtra.rules);
configs[1].plugins = { ...configBracesRules.plugins };
Object.assign(configs[1].rules, configBracesRules.rules);
Object.assign(configs[1].plugins, configStylistic.plugins);
configs[1].plugins = { ...configStylistic.plugins };
Object.assign(configs[1].rules, configStylistic.rules);
export default configs;