]> git.openstreetmap.org Git - rails.git/blob - config/eslint.config.mjs
Fix eslint warning
[rails.git] / config / eslint.config.mjs
1 import globals from "globals";
2 import js from "@eslint/js";
3 import erb from "eslint-plugin-erb";
4 import stylisticJs from "@stylistic/eslint-plugin-js";
5
6 export default [
7   js.configs.recommended,
8   erb.configs.recommended,
9   {
10     ignores: [
11       "app/assets/javascripts/i18n/",
12       "coverage/assets/",
13       "public/assets/",
14       "vendor/"
15     ]
16   },
17   {
18     plugins: {
19       "@stylistic": stylisticJs
20     },
21     languageOptions: {
22       ecmaVersion: 2021,
23       sourceType: "script",
24       globals: {
25         ...globals.browser,
26         ...globals.jquery,
27         Cookies: "readonly",
28         I18n: "readonly",
29         L: "readonly",
30         Matomo: "readonly",
31         OSM: "writable",
32         Turbo: "readonly",
33         bootstrap: "readonly",
34         plurals: "readonly",
35         updateLinks: "readonly"
36       }
37     },
38     linterOptions: {
39       // The "unused disable directive" is set to "warn" by default.
40       // For the ERB plugin to work correctly, you must disable
41       // this directive to avoid issues described here
42       // https://github.com/eslint/eslint/discussions/18114
43       // If you're using the CLI, you might also use the following flag:
44       // --report-unused-disable-directives-severity=off
45       reportUnusedDisableDirectives: "off"
46     },
47     rules: {
48       "@stylistic/array-bracket-newline": ["error", "consistent"],
49       "@stylistic/array-bracket-spacing": "error",
50       "@stylistic/arrow-spacing": "error",
51       "@stylistic/block-spacing": "error",
52       "@stylistic/brace-style": ["error", "1tbs", { allowSingleLine: true }],
53       "@stylistic/comma-dangle": "error",
54       "@stylistic/comma-spacing": "error",
55       "@stylistic/comma-style": "error",
56       "@stylistic/computed-property-spacing": "error",
57       "@stylistic/dot-location": ["error", "property"],
58       "@stylistic/eol-last": "error",
59       "@stylistic/func-call-spacing": "error",
60       "@stylistic/indent": ["error", 2, {
61         CallExpression: { arguments: "first" },
62         FunctionDeclaration: { parameters: "first" },
63         FunctionExpression: { parameters: "first" },
64         SwitchCase: 1,
65         VariableDeclarator: "first"
66       }],
67       "@stylistic/key-spacing": "error",
68       "@stylistic/keyword-spacing": "error",
69       "@stylistic/max-statements-per-line": "error",
70       "@stylistic/no-floating-decimal": "error",
71       "@stylistic/no-mixed-operators": "error",
72       "@stylistic/no-multi-spaces": "error",
73       "@stylistic/no-multiple-empty-lines": "error",
74       "@stylistic/no-trailing-spaces": "error",
75       "@stylistic/no-whitespace-before-property": "error",
76       "@stylistic/object-curly-newline": ["error", { consistent: true }],
77       "@stylistic/object-curly-spacing": ["error", "always"],
78       "@stylistic/object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
79       "@stylistic/one-var-declaration-per-line": "error",
80       "@stylistic/operator-linebreak": ["error", "after"],
81       "@stylistic/padded-blocks": ["error", "never"],
82       "@stylistic/quote-props": ["error", "consistent-as-needed", { keywords: true, numbers: true }],
83       "@stylistic/quotes": ["error", "double"],
84       "@stylistic/semi": ["error", "always"],
85       "@stylistic/semi-spacing": "error",
86       "@stylistic/semi-style": "error",
87       "@stylistic/space-before-blocks": "error",
88       "@stylistic/space-before-function-paren": ["error", { named: "never" }],
89       "@stylistic/space-in-parens": "error",
90       "@stylistic/space-infix-ops": "error",
91       "@stylistic/space-unary-ops": "error",
92       "@stylistic/switch-colon-spacing": "error",
93       "@stylistic/wrap-iife": "error",
94       "@stylistic/wrap-regex": "error",
95
96       "accessor-pairs": "error",
97       "array-callback-return": "error",
98       "block-scoped-var": "error",
99       "curly": ["error", "multi-line", "consistent"],
100       "dot-notation": "error",
101       "eqeqeq": ["error", "smart"],
102       "no-alert": "error",
103       "no-array-constructor": "error",
104       "no-caller": "error",
105       "no-console": "warn",
106       "no-div-regex": "error",
107       "no-eq-null": "error",
108       "no-eval": "error",
109       "no-extend-native": "error",
110       "no-extra-bind": "error",
111       "no-extra-label": "error",
112       "no-implicit-coercion": "warn",
113       "no-implicit-globals": "error",
114       "no-implied-eval": "error",
115       "no-invalid-this": "error",
116       "no-iterator": "error",
117       "no-label-var": "error",
118       "no-labels": "error",
119       "no-lone-blocks": "error",
120       "no-lonely-if": "error",
121       "no-loop-func": "error",
122       "no-multi-str": "error",
123       "no-negated-condition": "error",
124       "no-nested-ternary": "error",
125       "no-new": "error",
126       "no-new-func": "error",
127       "no-new-wrappers": "error",
128       "no-object-constructor": "error",
129       "no-octal-escape": "error",
130       "no-param-reassign": "error",
131       "no-proto": "error",
132       "no-script-url": "error",
133       "no-self-compare": "error",
134       "no-sequences": "error",
135       "no-throw-literal": "error",
136       "no-undef-init": "error",
137       "no-undefined": "error",
138       "no-unmodified-loop-condition": "error",
139       "no-unneeded-ternary": "error",
140       "no-unused-expressions": "off",
141       "no-unused-vars": ["error", { caughtErrors: "none" }],
142       "no-use-before-define": ["error", { functions: false }],
143       "no-useless-call": "error",
144       "no-useless-concat": "error",
145       "no-useless-return": "error",
146       "no-var": "error",
147       "no-void": "error",
148       "no-warning-comments": "warn",
149       "operator-assignment": "error",
150       "prefer-const": "error",
151       "prefer-object-spread": "error",
152       "radix": ["error", "always"],
153       "yoda": "error"
154     }
155   },
156   {
157     // Additional configuration for test files
158     files: ["test/**/*.js"],
159     languageOptions: {
160       globals: {
161         ...globals.mocha,
162         expect: "readonly",
163         assert: "readonly",
164         should: "readonly"
165       }
166     }
167   },
168   {
169     files: ["config/eslint.config.mjs"],
170     languageOptions: {
171       sourceType: "module"
172     },
173     rules: {
174       "sort-keys": ["error", "asc", { minKeys: 5 }]
175     }
176   }
177 ];