|
1 | | -module.exports = { |
2 | | - extends: ["eslint:recommended", "plugin:prettier/recommended"], |
3 | | - plugins: ["@foxglove", "import", "filenames", "es"], |
4 | | - parserOptions: { |
5 | | - ecmaVersion: 2020, |
6 | | - sourceType: "module", |
7 | | - }, |
8 | | - rules: { |
9 | | - // even new Safari versions do not support regexp lookbehinds |
10 | | - "es/no-regexp-lookbehind-assertions": "error", |
| 1 | +const { fixupPluginRules } = require("@eslint/compat"); |
| 2 | +const js = require("@eslint/js"); |
| 3 | +// @ts-expect-error Missing type definitions |
| 4 | +const es = require("eslint-plugin-es"); |
| 5 | +// @ts-expect-error Missing type definitions |
| 6 | +const filenames = require("eslint-plugin-filenames"); |
| 7 | +// @ts-expect-error Missing type definitions |
| 8 | +const importPlugin = require("eslint-plugin-import"); |
| 9 | +const eslintPluginPrettierRecommended = require("eslint-plugin-prettier/recommended"); |
11 | 10 |
|
12 | | - // import plugin is slow, only enable the critical stuff |
13 | | - "import/export": "error", |
14 | | - "import/first": "error", |
15 | | - "import/named": "error", |
16 | | - "import/newline-after-import": "error", |
17 | | - "import/no-duplicates": "error", |
18 | | - "import/no-mutable-exports": "error", |
19 | | - "import/no-useless-path-segments": "error", |
20 | | - "import/order": [ |
21 | | - "error", |
22 | | - { |
23 | | - alphabetize: { |
24 | | - order: "asc", |
25 | | - }, |
26 | | - "newlines-between": "always", |
27 | | - groups: [ |
28 | | - ["builtin", "external"], |
29 | | - ["internal"], |
30 | | - ["parent", "sibling", "index"], |
31 | | - ], |
| 11 | +const foxglove = require("../plugin"); |
| 12 | + |
| 13 | +const fixedFilenames = fixupPluginRules(filenames); |
| 14 | + |
| 15 | +/** @type {import("eslint").Linter.Config[]} */ |
| 16 | +module.exports = [ |
| 17 | + js.configs.recommended, |
| 18 | + eslintPluginPrettierRecommended, |
| 19 | + { |
| 20 | + linterOptions: { |
| 21 | + reportUnusedDisableDirectives: "error", |
| 22 | + }, |
| 23 | + plugins: { |
| 24 | + "@foxglove": foxglove, |
| 25 | + import: importPlugin, |
| 26 | + es: fixupPluginRules(es), |
| 27 | + |
| 28 | + // eslint-plugin-filenames allows rules to have options, but fixupPluginRules defaults to a |
| 29 | + // schema that does not allow passing any options. We replace this with `false` to disable |
| 30 | + // validation so that options can be passed in. |
| 31 | + filenames: { |
| 32 | + ...fixedFilenames, |
| 33 | + rules: Object.fromEntries( |
| 34 | + Object.entries(fixedFilenames.rules ?? {}).map(([ruleId, rule]) => [ |
| 35 | + ruleId, |
| 36 | + { |
| 37 | + ...rule, |
| 38 | + meta: { |
| 39 | + ...rule.meta, |
| 40 | + schema: rule.meta?.schema ?? false, |
| 41 | + }, |
| 42 | + }, |
| 43 | + ]) |
| 44 | + ), |
32 | 45 | }, |
33 | | - ], |
| 46 | + }, |
| 47 | + rules: { |
| 48 | + // even new Safari versions do not support regexp lookbehinds |
| 49 | + "es/no-regexp-lookbehind-assertions": "error", |
34 | 50 |
|
35 | | - "filenames/match-exported": "error", |
| 51 | + // import plugin is slow, only enable the critical stuff |
| 52 | + "import/export": "error", |
| 53 | + "import/first": "error", |
| 54 | + "import/named": "error", |
| 55 | + "import/newline-after-import": "error", |
| 56 | + "import/no-duplicates": "error", |
| 57 | + "import/no-mutable-exports": "error", |
| 58 | + "import/no-useless-path-segments": "error", |
| 59 | + "import/order": [ |
| 60 | + "error", |
| 61 | + { |
| 62 | + alphabetize: { |
| 63 | + order: "asc", |
| 64 | + }, |
| 65 | + "newlines-between": "always", |
| 66 | + groups: [ |
| 67 | + ["builtin", "external"], |
| 68 | + ["internal"], |
| 69 | + ["parent", "sibling", "index"], |
| 70 | + ], |
| 71 | + }, |
| 72 | + ], |
36 | 73 |
|
37 | | - // require double equal for null and undefined, triple equal everywhere else |
38 | | - "@foxglove/strict-equality": "error", |
39 | | - "@foxglove/no-return-promise-resolve": "error", |
40 | | - "@foxglove/prefer-hash-private": "error", |
| 74 | + "filenames/match-exported": "error", |
41 | 75 |
|
42 | | - // require curly braces everywhere |
43 | | - curly: "error", |
| 76 | + // require double equal for null and undefined, triple equal everywhere else |
| 77 | + "@foxglove/strict-equality": "error", |
| 78 | + "@foxglove/no-return-promise-resolve": "error", |
| 79 | + "@foxglove/prefer-hash-private": "error", |
44 | 80 |
|
45 | | - // avoid eval |
46 | | - "no-eval": "error", |
47 | | - "no-implied-eval": "error", |
48 | | - "no-new-func": "error", |
| 81 | + // require curly braces everywhere |
| 82 | + curly: "error", |
49 | 83 |
|
50 | | - // unused vars must have `_` prefix |
51 | | - "no-unused-vars": [ |
52 | | - "error", |
53 | | - { |
54 | | - vars: "all", |
55 | | - args: "after-used", |
56 | | - varsIgnorePattern: "^_", |
57 | | - argsIgnorePattern: "^_", |
58 | | - }, |
59 | | - ], |
| 84 | + // avoid eval |
| 85 | + "no-eval": "error", |
| 86 | + "no-implied-eval": "error", |
| 87 | + "no-new-func": "error", |
60 | 88 |
|
61 | | - "no-underscore-dangle": [ |
62 | | - "error", |
63 | | - { |
64 | | - allowAfterThis: true, |
65 | | - }, |
66 | | - ], |
| 89 | + // unused vars must have `_` prefix |
| 90 | + "no-unused-vars": [ |
| 91 | + "error", |
| 92 | + { |
| 93 | + vars: "all", |
| 94 | + args: "after-used", |
| 95 | + varsIgnorePattern: "^_", |
| 96 | + argsIgnorePattern: "^_", |
| 97 | + }, |
| 98 | + ], |
67 | 99 |
|
68 | | - // avoid TO.DO and FIX.ME comments, create a ticket to track future work |
69 | | - "no-warning-comments": [ |
70 | | - "error", |
71 | | - { |
72 | | - location: "anywhere", |
73 | | - }, |
74 | | - ], |
| 100 | + "no-underscore-dangle": [ |
| 101 | + "error", |
| 102 | + { |
| 103 | + allowAfterThis: true, |
| 104 | + }, |
| 105 | + ], |
| 106 | + |
| 107 | + // avoid TO.DO and FIX.ME comments, create a ticket to track future work |
| 108 | + "no-warning-comments": [ |
| 109 | + "error", |
| 110 | + { |
| 111 | + location: "anywhere", |
| 112 | + }, |
| 113 | + ], |
75 | 114 |
|
76 | | - "no-unused-expressions": ["error", { enforceForJSX: true }], |
77 | | - "no-param-reassign": "error", |
78 | | - "no-useless-rename": "error", |
79 | | - "object-shorthand": "error", |
80 | | - "prefer-arrow-callback": ["error", { allowNamedFunctions: true }], |
| 115 | + "no-unused-expressions": ["error", { enforceForJSX: true }], |
| 116 | + "no-param-reassign": "error", |
| 117 | + "no-useless-rename": "error", |
| 118 | + "object-shorthand": "error", |
| 119 | + "prefer-arrow-callback": ["error", { allowNamedFunctions: true }], |
| 120 | + }, |
81 | 121 | }, |
82 | | -}; |
| 122 | +]; |
0 commit comments