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