|
| 1 | +import eslint from "@eslint/js"; |
| 2 | +import comments from "@eslint-community/eslint-plugin-eslint-comments/configs"; |
| 3 | +import jsdoc from "eslint-plugin-jsdoc"; |
| 4 | +import jsonc from "eslint-plugin-jsonc"; |
| 5 | +import markdown from "eslint-plugin-markdown"; |
| 6 | +import n from "eslint-plugin-n"; |
| 7 | +import packageJson from "eslint-plugin-package-json/configs/recommended"; |
| 8 | +import perfectionistNatural from "eslint-plugin-perfectionist/configs/recommended-natural"; |
| 9 | +import * as regexp from "eslint-plugin-regexp"; |
| 10 | +import vitest from "eslint-plugin-vitest"; |
| 11 | +import yml from "eslint-plugin-yml"; |
| 12 | +import tseslint from "typescript-eslint"; |
| 13 | + |
| 14 | +export default tseslint.config( |
| 15 | + { |
| 16 | + ignores: [ |
| 17 | + "coverage*", |
| 18 | + "lib", |
| 19 | + "node_modules", |
| 20 | + "pnpm-lock.yaml", |
| 21 | + "**/*.snap", |
| 22 | + ], |
| 23 | + }, |
| 24 | + { |
| 25 | + linterOptions: { |
| 26 | + reportUnusedDisableDirectives: "error", |
| 27 | + }, |
| 28 | + }, |
| 29 | + eslint.configs.recommended, |
| 30 | + ...jsonc.configs["flat/recommended-with-json"], |
| 31 | + ...markdown.configs.recommended, |
| 32 | + ...yml.configs["flat/recommended"], |
| 33 | + ...yml.configs["flat/prettier"], |
| 34 | + comments.recommended, |
| 35 | + jsdoc.configs["flat/recommended-typescript-error"], |
| 36 | + n.configs["flat/recommended"], |
| 37 | + packageJson, |
| 38 | + perfectionistNatural, |
| 39 | + regexp.configs["flat/recommended"], |
| 40 | + ...tseslint.config({ |
| 41 | + extends: [ |
| 42 | + ...tseslint.configs.strictTypeChecked, |
| 43 | + ...tseslint.configs.stylisticTypeChecked, |
| 44 | + ], |
| 45 | + files: ["**/*.js", "**/*.ts"], |
| 46 | + languageOptions: { |
| 47 | + parserOptions: { |
| 48 | + EXPERIMENTAL_useProjectService: { |
| 49 | + allowDefaultProjectForFiles: ["./*.*s", "eslint.config.js"], |
| 50 | + defaultProject: "./tsconfig.json", |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + rules: { |
| 55 | + // TODO: Eventually, it'd be nice to enable these... |
| 56 | + "@typescript-eslint/ban-types": "off", |
| 57 | + "@typescript-eslint/no-confusing-void-expression": "off", |
| 58 | + "@typescript-eslint/no-explicit-any": "off", |
| 59 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 60 | + "@typescript-eslint/no-redundant-type-constituents": "off", |
| 61 | + "@typescript-eslint/no-unsafe-assignment": "off", |
| 62 | + "@typescript-eslint/no-unsafe-call": "off", |
| 63 | + "@typescript-eslint/no-unsafe-member-access": "off", |
| 64 | + "@typescript-eslint/no-unsafe-return": "off", |
| 65 | + "@typescript-eslint/restrict-template-expressions": "off", |
| 66 | + "@typescript-eslint/unbound-method": "off", |
| 67 | + |
| 68 | + // These off-by-default rules work well for this repo and we like them on. |
| 69 | + "jsdoc/informative-docs": "error", |
| 70 | + "logical-assignment-operators": [ |
| 71 | + "error", |
| 72 | + "always", |
| 73 | + { enforceForIfStatements: true }, |
| 74 | + ], |
| 75 | + "operator-assignment": "error", |
| 76 | + |
| 77 | + // These on-by-default rules don't work well for this repo and we like them off. |
| 78 | + "@typescript-eslint/no-var-requires": "off", |
| 79 | + "jsdoc/require-jsdoc": "off", |
| 80 | + "jsdoc/require-param": "off", |
| 81 | + "jsdoc/require-property": "off", |
| 82 | + "jsdoc/require-returns": "off", |
| 83 | + "n/no-missing-require": "off", |
| 84 | + "no-constant-condition": "off", |
| 85 | + |
| 86 | + // These on-by-default rules work well for this repo if configured |
| 87 | + "@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "all" }], |
| 88 | + "perfectionist/sort-objects": [ |
| 89 | + "error", |
| 90 | + { |
| 91 | + order: "asc", |
| 92 | + "partition-by-comment": true, |
| 93 | + type: "natural", |
| 94 | + }, |
| 95 | + ], |
| 96 | + |
| 97 | + // Stylistic concerns that don't interfere with Prettier |
| 98 | + "no-useless-rename": "error", |
| 99 | + "object-shorthand": "error", |
| 100 | + }, |
| 101 | + }), |
| 102 | + { |
| 103 | + files: ["*.jsonc"], |
| 104 | + rules: { |
| 105 | + "jsonc/comma-dangle": "off", |
| 106 | + "jsonc/no-comments": "off", |
| 107 | + "jsonc/sort-keys": "error", |
| 108 | + }, |
| 109 | + }, |
| 110 | + { |
| 111 | + extends: [tseslint.configs.disableTypeChecked], |
| 112 | + files: ["**/*.md/*.*s"], |
| 113 | + rules: { |
| 114 | + "n/no-missing-import": ["error", { allowModules: ["console-fail-test"] }], |
| 115 | + }, |
| 116 | + }, |
| 117 | + { |
| 118 | + files: ["**/*.test.*"], |
| 119 | + languageOptions: { |
| 120 | + globals: vitest.environments.env.globals, |
| 121 | + }, |
| 122 | + plugins: { vitest }, |
| 123 | + rules: { |
| 124 | + ...vitest.configs.recommended.rules, |
| 125 | + |
| 126 | + // These on-by-default rules aren't useful in test files. |
| 127 | + "@typescript-eslint/no-unsafe-assignment": "off", |
| 128 | + "@typescript-eslint/no-unsafe-call": "off", |
| 129 | + }, |
| 130 | + }, |
| 131 | + { |
| 132 | + files: ["**/*.{yml,yaml}"], |
| 133 | + rules: { |
| 134 | + "yml/file-extension": ["error", { extension: "yml" }], |
| 135 | + "yml/sort-keys": [ |
| 136 | + "error", |
| 137 | + { |
| 138 | + order: { type: "asc" }, |
| 139 | + pathPattern: "^.*$", |
| 140 | + }, |
| 141 | + ], |
| 142 | + "yml/sort-sequence-values": [ |
| 143 | + "error", |
| 144 | + { |
| 145 | + order: { type: "asc" }, |
| 146 | + pathPattern: "^.*$", |
| 147 | + }, |
| 148 | + ], |
| 149 | + }, |
| 150 | + }, |
| 151 | +); |
0 commit comments