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