|
| 1 | +/** |
| 2 | + * @param {string[]} statementTypes |
| 3 | + */ |
| 4 | +const alwaysPad = (...statementTypes) => |
| 5 | + statementTypes |
| 6 | + .map(statementType => [ |
| 7 | + { |
| 8 | + blankLine: "always", |
| 9 | + prev: "*", |
| 10 | + next: statementType, |
| 11 | + }, |
| 12 | + { |
| 13 | + blankLine: "always", |
| 14 | + prev: statementType, |
| 15 | + next: "*", |
| 16 | + }, |
| 17 | + ]) |
| 18 | + .flat(); |
| 19 | + |
| 20 | +/** |
| 21 | + * @param {[string, string[], string[]][]} statementTypeGroups |
| 22 | + */ |
| 23 | +const alwaysPadWithItselfAndWith = (...statementTypeGroups) => |
| 24 | + statementTypeGroups |
| 25 | + .map(statementTypeGroup => [ |
| 26 | + { |
| 27 | + blankLine: "always", |
| 28 | + prev: [statementTypeGroup[0], ...statementTypeGroup[1]], |
| 29 | + next: [statementTypeGroup[0], ...statementTypeGroup[2]], |
| 30 | + }, |
| 31 | + ]) |
| 32 | + .flat(); |
| 33 | + |
| 34 | +/** |
| 35 | + * @param {string[]} statementTypes |
| 36 | + */ |
| 37 | +const alwaysPadInGroups = (...statementTypes) => |
| 38 | + statementTypes |
| 39 | + .map(statementType => [ |
| 40 | + ...alwaysPad(statementType), |
| 41 | + { |
| 42 | + blankLine: "any", |
| 43 | + prev: statementType, |
| 44 | + next: statementType, |
| 45 | + }, |
| 46 | + ]) |
| 47 | + .flat(); |
| 48 | + |
| 49 | +/** |
| 50 | + * @param {string[]} statementTypes |
| 51 | + */ |
| 52 | +const neverPadWithItself = (...statementTypes) => |
| 53 | + statementTypes |
| 54 | + .map(statementType => [ |
| 55 | + { |
| 56 | + blankLine: "never", |
| 57 | + prev: statementType, |
| 58 | + next: statementType, |
| 59 | + }, |
| 60 | + ]) |
| 61 | + .flat(); |
| 62 | + |
| 63 | +/** |
| 64 | + * @type {import("eslint").Linter.Config} |
| 65 | + */ |
| 66 | +module.exports = { |
| 67 | + root: true, |
| 68 | + env: { |
| 69 | + es6: true, |
| 70 | + }, |
| 71 | + |
| 72 | + extends: [ |
| 73 | + "eslint:recommended", |
| 74 | + "plugin:import/typescript", |
| 75 | + "google", |
| 76 | + "plugin:react/recommended", |
| 77 | + "plugin:react/jsx-runtime", |
| 78 | + "plugin:react-hooks/recommended", |
| 79 | + "plugin:@typescript-eslint/recommended", |
| 80 | + "plugin:prettier/recommended", |
| 81 | + ], |
| 82 | + |
| 83 | + parser: "@typescript-eslint/parser", |
| 84 | + parserOptions: { |
| 85 | + project: ["tsconfig.eslint.json"], |
| 86 | + sourceType: "module", |
| 87 | + ecmaVersion: "latest", |
| 88 | + }, |
| 89 | + ignorePatterns: ["/dist/**/*", "/typings/**/*", "/coverage/**/*"], |
| 90 | + plugins: ["@typescript-eslint", "react", "react-hooks", "import", "prettier"], |
| 91 | + |
| 92 | + rules: { |
| 93 | + "@typescript-eslint/explicit-function-return-type": "error", |
| 94 | + "@typescript-eslint/no-empty-interface": "off", |
| 95 | + "@typescript-eslint/no-explicit-any": "off", |
| 96 | + "@typescript-eslint/no-namespace": "off", |
| 97 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 98 | + "@typescript-eslint/no-unused-vars": "off", |
| 99 | + "@typescript-eslint/no-var-requires": "off", |
| 100 | + |
| 101 | + "import/default": "error", |
| 102 | + "import/export": "error", |
| 103 | + "import/named": "off", |
| 104 | + "import/namespace": "error", |
| 105 | + "import/newline-after-import": "warn", |
| 106 | + "import/no-duplicates": "warn", |
| 107 | + "import/no-named-as-default": "warn", |
| 108 | + "import/no-named-as-default-member": "warn", |
| 109 | + "import/no-unresolved": "off", |
| 110 | + "import/order": "warn", |
| 111 | + |
| 112 | + "curly": ["warn", "multi-or-nest"], |
| 113 | + "new-cap": ["error", { capIsNew: false }], |
| 114 | + "no-console": "off", |
| 115 | + "no-inner-declarations": "off", |
| 116 | + "no-invalid-this": "off", |
| 117 | + "prefer-promise-reject-errors": "off", |
| 118 | + "require-jsdoc": "off", |
| 119 | + "spaced-comment": ["error", "always", { markers: ["/"] }], |
| 120 | + "valid-jsdoc": "off", |
| 121 | + |
| 122 | + "padding-line-between-statements": [ |
| 123 | + "warn", |
| 124 | + |
| 125 | + ...neverPadWithItself("if"), |
| 126 | + ...alwaysPad( |
| 127 | + "class", |
| 128 | + "directive", |
| 129 | + "do", |
| 130 | + "for", |
| 131 | + "function", |
| 132 | + "multiline-block-like", |
| 133 | + "multiline-const", |
| 134 | + "multiline-expression", |
| 135 | + "multiline-let", |
| 136 | + "switch", |
| 137 | + "try", |
| 138 | + "while" |
| 139 | + ), |
| 140 | + ...alwaysPadWithItselfAndWith(["case", [], ["default"]]), |
| 141 | + ...alwaysPadInGroups("cjs-export", "cjs-import", "export", "import"), |
| 142 | + ], |
| 143 | + |
| 144 | + "prettier/prettier": [ |
| 145 | + "warn", |
| 146 | + {}, |
| 147 | + { |
| 148 | + usePrettierrc: true, |
| 149 | + }, |
| 150 | + ], |
| 151 | + }, |
| 152 | + |
| 153 | + overrides: [ |
| 154 | + { |
| 155 | + files: ["./src/__tests__/**/*.ts", "./.eslintrc.js", "./vitest.config.ts", "./scripts/**/*.mjs"], |
| 156 | + |
| 157 | + env: { |
| 158 | + es6: true, |
| 159 | + node: true, |
| 160 | + }, |
| 161 | + }, |
| 162 | + |
| 163 | + { |
| 164 | + files: ["./.eslintrc.js", "./scripts/**/*.mjs"], |
| 165 | + |
| 166 | + rules: { |
| 167 | + "@typescript-eslint/explicit-function-return-type": "off", |
| 168 | + }, |
| 169 | + }, |
| 170 | + ], |
| 171 | + |
| 172 | + settings: { |
| 173 | + react: { |
| 174 | + version: "detect", |
| 175 | + }, |
| 176 | + }, |
| 177 | +}; |
0 commit comments