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