|
| 1 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 2 | +import js from "@eslint/js"; |
| 3 | +import tsParser from "@typescript-eslint/parser"; |
| 4 | +import prettier from "eslint-config-prettier/flat"; |
| 5 | +import jsonc from "eslint-plugin-jsonc"; |
| 6 | +import simpleImportSort from "eslint-plugin-simple-import-sort"; |
| 7 | +import unusedImports from "eslint-plugin-unused-imports"; |
| 8 | + |
| 9 | +const compat = new FlatCompat({ |
| 10 | + baseDirectory: import.meta.dirname, |
| 11 | + recommendedConfig: js.configs.recommended, |
| 12 | + allConfig: js.configs.all, |
| 13 | +}); |
| 14 | + |
| 15 | +const config = [ |
| 16 | + { |
| 17 | + ignores: [ |
| 18 | + "node_modules/**", |
| 19 | + ".next/**", |
| 20 | + "out/**", |
| 21 | + "build/**", |
| 22 | + "coverage/**", |
| 23 | + "package-lock.json", |
| 24 | + "next-env.d.ts", |
| 25 | + "proto/**", |
| 26 | + ], |
| 27 | + }, |
| 28 | + // eslint 9 flipped this default to "warn"; |
| 29 | + { |
| 30 | + linterOptions: { reportUnusedDisableDirectives: "warn" }, |
| 31 | + }, |
| 32 | + |
| 33 | + // both legacy extends must go through the same FlatCompat instance so the |
| 34 | + // @typescript-eslint plugin resolves to one module object ("Cannot redefine |
| 35 | + // plugin" otherwise) |
| 36 | + |
| 37 | + // Come back to this after we upgrade next.js https://github.com/Couchers-org/couchers/issues/9280 |
| 38 | + ...compat.extends( |
| 39 | + "plugin:@typescript-eslint/recommended", |
| 40 | + "next/core-web-vitals", |
| 41 | + ), |
| 42 | + prettier, |
| 43 | + { |
| 44 | + plugins: { |
| 45 | + "simple-import-sort": simpleImportSort, |
| 46 | + "unused-imports": unusedImports, |
| 47 | + }, |
| 48 | + rules: { |
| 49 | + // ~~~ settings for simple import sort plugin ~~~ |
| 50 | + "simple-import-sort/imports": "warn", |
| 51 | + "simple-import-sort/exports": "warn", |
| 52 | + "sort-imports": "off", |
| 53 | + "import/order": "off", |
| 54 | + "import/first": "warn", |
| 55 | + "import/newline-after-import": "warn", |
| 56 | + "import/no-duplicates": "warn", |
| 57 | + |
| 58 | + // ~~~ setings for unused imports plugin ~~~ |
| 59 | + "unused-imports/no-unused-imports": "warn", |
| 60 | + |
| 61 | + // ~~~ custom couchers settings ~~~ |
| 62 | + //allow theme to be unused in makeStyles |
| 63 | + "@typescript-eslint/no-unused-vars": "off", |
| 64 | + "no-unused-vars": "off", |
| 65 | + "unused-imports/no-unused-vars": [ |
| 66 | + "warn", |
| 67 | + { |
| 68 | + argsIgnorePattern: "theme", |
| 69 | + varsIgnorePattern: "classes|useStyles", |
| 70 | + }, |
| 71 | + ], |
| 72 | + //good in theory, but ts isn't perfect and library types can be wrong |
| 73 | + "@typescript-eslint/ban-ts-comment": "off", |
| 74 | + //better avoided but useful for gRPC |
| 75 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 76 | + //used in testing |
| 77 | + "@typescript-eslint/no-empty-function": "off", |
| 78 | + //not using this right now |
| 79 | + "@next/next/no-img-element": "off", |
| 80 | + |
| 81 | + "react/no-unescaped-entities": "off", |
| 82 | + // Prefer inferred types so that the code is as close to JS as possible |
| 83 | + "@typescript-eslint/explicit-module-boundary-types": "off", |
| 84 | + }, |
| 85 | + }, |
| 86 | + { |
| 87 | + files: ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"], |
| 88 | + languageOptions: { parser: tsParser }, |
| 89 | + }, |
| 90 | + // the jsonc preset is pinned to **/*.json: unpinned it would also grab |
| 91 | + // .json5/.jsonc, and without files globs `eslint .` wouldn't lint json at all |
| 92 | + ...jsonc.configs["flat/recommended-with-json"].map((config) => ({ |
| 93 | + ...config, |
| 94 | + files: ["**/*.json"], |
| 95 | + })), |
| 96 | + { |
| 97 | + files: ["**/*.json"], |
| 98 | + rules: { "jsonc/no-comments": "off" }, |
| 99 | + }, |
| 100 | +]; |
| 101 | + |
| 102 | +export default config; |
0 commit comments