]> git.openstreetmap.org Git - rails.git/blob - config/eslint.js
Replace deprecated eslint rules
[rails.git] / config / eslint.js
1 const globals = require("globals");
2 const js = require("@eslint/js");
3 const stylisticJs = require("@stylistic/eslint-plugin-js");
4
5 module.exports = [
6   js.configs.recommended,
7   {
8     plugins: {
9       "@stylistic": stylisticJs
10     },
11     languageOptions: {
12       ecmaVersion: 2021,
13       sourceType: "script",
14       globals: {
15         ...globals.browser,
16         ...globals.jquery,
17         Cookies: "readonly",
18         I18n: "readonly",
19         L: "readonly",
20         OSM: "writable",
21         Matomo: "readonly",
22         Qs: "readonly",
23         Turbo: "readonly",
24         updateLinks: "readonly"
25       }
26     },
27     rules: {
28       "@stylistic/array-bracket-newline": ["error", "consistent"],
29       "@stylistic/array-bracket-spacing": "error",
30       "@stylistic/block-spacing": "error",
31       "@stylistic/brace-style": ["error", "1tbs", { allowSingleLine: true }],
32       "@stylistic/comma-dangle": "error",
33       "@stylistic/comma-spacing": "error",
34       "@stylistic/comma-style": "error",
35       "@stylistic/computed-property-spacing": "error",
36       "@stylistic/dot-location": ["error", "property"],
37       "@stylistic/eol-last": "error",
38       "@stylistic/func-call-spacing": "error",
39       "@stylistic/indent": ["error", 2, {
40         SwitchCase: 1,
41         VariableDeclarator: "first",
42         FunctionDeclaration: { parameters: "first" },
43         FunctionExpression: { parameters: "first" },
44         CallExpression: { arguments: "first" }
45       }],
46       "@stylistic/key-spacing": "error",
47       "@stylistic/keyword-spacing": "error",
48       "@stylistic/no-floating-decimal": "error",
49       "@stylistic/no-mixed-operators": "error",
50       "@stylistic/no-multiple-empty-lines": "error",
51       "@stylistic/no-multi-spaces": "error",
52       "@stylistic/no-trailing-spaces": "error",
53       "@stylistic/no-whitespace-before-property": "error",
54       "@stylistic/object-curly-newline": ["error", { consistent: true }],
55       "@stylistic/object-curly-spacing": ["error", "always"],
56       "@stylistic/object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
57       "@stylistic/operator-linebreak": ["error", "after"],
58       "@stylistic/padded-blocks": ["error", "never"],
59       "@stylistic/quote-props": ["error", "consistent-as-needed", { keywords: true, numbers: true }],
60       "@stylistic/quotes": ["error", "double"],
61       "@stylistic/semi": ["error", "always"],
62       "@stylistic/semi-spacing": "error",
63       "@stylistic/semi-style": "error",
64       "@stylistic/space-before-blocks": "error",
65       "@stylistic/space-before-function-paren": ["error", { named: "never" }],
66       "@stylistic/space-in-parens": "error",
67       "@stylistic/space-infix-ops": "error",
68       "@stylistic/space-unary-ops": "error",
69       "@stylistic/switch-colon-spacing": "error",
70       "@stylistic/wrap-iife": "error",
71       "@stylistic/wrap-regex": "error",
72
73       "accessor-pairs": "error",
74       "array-callback-return": "error",
75       "block-scoped-var": "error",
76       "curly": ["error", "multi-line", "consistent"],
77       "dot-notation": "error",
78       "eqeqeq": ["error", "smart"],
79       "no-alert": "warn",
80       "no-array-constructor": "error",
81       "no-caller": "error",
82       "no-console": "warn",
83       "no-div-regex": "error",
84       "no-eq-null": "error",
85       "no-eval": "error",
86       "no-extend-native": "error",
87       "no-extra-bind": "error",
88       "no-extra-label": "error",
89       "no-implicit-coercion": "warn",
90       "no-implicit-globals": "warn",
91       "no-implied-eval": "error",
92       "no-invalid-this": "error",
93       "no-iterator": "error",
94       "no-labels": "error",
95       "no-label-var": "error",
96       "no-lone-blocks": "error",
97       "no-lonely-if": "error",
98       "no-loop-func": "error",
99       "no-multi-str": "error",
100       "no-negated-condition": "error",
101       "no-nested-ternary": "error",
102       "no-new": "error",
103       "no-new-func": "error",
104       "no-new-wrappers": "error",
105       "no-object-constructor": "error",
106       "no-octal-escape": "error",
107       "no-param-reassign": "error",
108       "no-proto": "error",
109       "no-script-url": "error",
110       "no-self-compare": "error",
111       "no-sequences": "error",
112       "no-throw-literal": "error",
113       "no-undef-init": "error",
114       "no-undefined": "error",
115       "no-unmodified-loop-condition": "error",
116       "no-unneeded-ternary": "error",
117       "no-unused-expressions": "off",
118       "no-unused-vars": ["error", { caughtErrors: "none" }],
119       "no-useless-call": "error",
120       "no-useless-concat": "error",
121       "no-useless-return": "error",
122       "no-use-before-define": ["error", { functions: false }],
123       "no-void": "error",
124       "no-warning-comments": "warn",
125       "radix": ["error", "always"],
126       "yoda": "error"
127     }
128   },
129   {
130     // Additional configuration for test files
131     files: ["test/**/*.js"],
132     languageOptions: {
133       globals: {
134         ...globals.mocha,
135         expect: "readonly",
136         assert: "readonly",
137         should: "readonly"
138       }
139     }
140   },
141   {
142     files: ["config/eslint.js"],
143     languageOptions: {
144       ecmaVersion: 2019,
145       sourceType: "commonjs",
146       globals: {
147         ...globals.commonjs
148       }
149     }
150   }
151 ];