|
| 1 | +import typescriptEslint from "@typescript-eslint/eslint-plugin"; |
| 2 | +import tsParser from "@typescript-eslint/parser"; |
| 3 | +import path from "path"; |
| 4 | +import { fileURLToPath } from "url"; |
| 5 | +import stylistic from "@stylistic/eslint-plugin"; |
| 6 | +import importRules from "eslint-plugin-import"; |
| 7 | + |
| 8 | +const __filename = fileURLToPath(import.meta.url); |
| 9 | +const __dirname = path.dirname(__filename); |
| 10 | + |
| 11 | +const plugins = { |
| 12 | + "@stylistic": stylistic, |
| 13 | + "@typescript-eslint": typescriptEslint, |
| 14 | + import: importRules, |
| 15 | +}; |
| 16 | + |
| 17 | +export const baseRules = { |
| 18 | + "import/extensions": ["error", "ignorePackages", {ts: "always"}], |
| 19 | + "@typescript-eslint/no-floating-promises": "error", |
| 20 | + "@typescript-eslint/no-unused-vars": [ |
| 21 | + 2, |
| 22 | + { args: "none", caughtErrors: "none" }, |
| 23 | + ], |
| 24 | + |
| 25 | + /** |
| 26 | + * Enforced rules |
| 27 | + */ |
| 28 | + // syntax preferences |
| 29 | + "object-curly-spacing": ["error", "always"], |
| 30 | + quotes: [ |
| 31 | + 2, |
| 32 | + "single", |
| 33 | + { |
| 34 | + avoidEscape: true, |
| 35 | + allowTemplateLiterals: true, |
| 36 | + }, |
| 37 | + ], |
| 38 | + "jsx-quotes": [2, "prefer-single"], |
| 39 | + "no-extra-semi": 2, |
| 40 | + "@stylistic/semi": [2], |
| 41 | + "comma-style": [2, "last"], |
| 42 | + "wrap-iife": [2, "inside"], |
| 43 | + "spaced-comment": [ |
| 44 | + 2, |
| 45 | + "always", |
| 46 | + { |
| 47 | + markers: ["*"], |
| 48 | + }, |
| 49 | + ], |
| 50 | + eqeqeq: [2], |
| 51 | + "accessor-pairs": [ |
| 52 | + 2, |
| 53 | + { |
| 54 | + getWithoutSet: false, |
| 55 | + setWithoutGet: false, |
| 56 | + }, |
| 57 | + ], |
| 58 | + "brace-style": [2, "1tbs", { allowSingleLine: true }], |
| 59 | + curly: [2, "multi-or-nest", "consistent"], |
| 60 | + "new-parens": 2, |
| 61 | + "arrow-parens": [2, "as-needed"], |
| 62 | + "prefer-const": 2, |
| 63 | + "quote-props": [2, "consistent"], |
| 64 | + "nonblock-statement-body-position": [2, "below"], |
| 65 | + |
| 66 | + // anti-patterns |
| 67 | + "no-var": 2, |
| 68 | + "no-with": 2, |
| 69 | + "no-multi-str": 2, |
| 70 | + "no-caller": 2, |
| 71 | + "no-implied-eval": 2, |
| 72 | + "no-labels": 2, |
| 73 | + "no-new-object": 2, |
| 74 | + "no-octal-escape": 2, |
| 75 | + "no-self-compare": 2, |
| 76 | + "no-shadow-restricted-names": 2, |
| 77 | + "no-cond-assign": 2, |
| 78 | + "no-debugger": 2, |
| 79 | + "no-dupe-keys": 2, |
| 80 | + "no-duplicate-case": 2, |
| 81 | + "no-empty-character-class": 2, |
| 82 | + "no-unreachable": 2, |
| 83 | + "no-unsafe-negation": 2, |
| 84 | + radix: 2, |
| 85 | + "valid-typeof": 2, |
| 86 | + "no-implicit-globals": [2], |
| 87 | + "no-unused-expressions": [ |
| 88 | + 2, |
| 89 | + { allowShortCircuit: true, allowTernary: true, allowTaggedTemplates: true }, |
| 90 | + ], |
| 91 | + "no-proto": 2, |
| 92 | + |
| 93 | + // es2015 features |
| 94 | + "require-yield": 2, |
| 95 | + "template-curly-spacing": [2, "never"], |
| 96 | + |
| 97 | + // spacing details |
| 98 | + "space-infix-ops": 2, |
| 99 | + "space-in-parens": [2, "never"], |
| 100 | + "array-bracket-spacing": [2, "never"], |
| 101 | + "comma-spacing": [2, { before: false, after: true }], |
| 102 | + "keyword-spacing": [ |
| 103 | + 2, |
| 104 | + { |
| 105 | + overrides: { |
| 106 | + if: { after: true }, |
| 107 | + else: { after: true }, |
| 108 | + for: { after: true }, |
| 109 | + while: { after: true }, |
| 110 | + do: { after: true }, |
| 111 | + switch: { after: true }, |
| 112 | + return: { after: true }, |
| 113 | + }, |
| 114 | + }, |
| 115 | + ], |
| 116 | + "space-before-function-paren": [ |
| 117 | + 2, |
| 118 | + { |
| 119 | + anonymous: "never", |
| 120 | + named: "never", |
| 121 | + asyncArrow: "always", |
| 122 | + }, |
| 123 | + ], |
| 124 | + "no-whitespace-before-property": 2, |
| 125 | + "arrow-spacing": [ |
| 126 | + 2, |
| 127 | + { |
| 128 | + after: true, |
| 129 | + before: true, |
| 130 | + }, |
| 131 | + ], |
| 132 | + "@stylistic/func-call-spacing": 2, |
| 133 | + "@stylistic/type-annotation-spacing": 2, |
| 134 | + |
| 135 | + // file whitespace |
| 136 | + "no-multiple-empty-lines": [2, { max: 2, maxEOF: 0 }], |
| 137 | + "no-mixed-spaces-and-tabs": 2, |
| 138 | + "no-trailing-spaces": 2, |
| 139 | + "linebreak-style": [process.platform === "win32" ? 0 : 2, "unix"], |
| 140 | + indent: [ |
| 141 | + 2, |
| 142 | + 2, |
| 143 | + { SwitchCase: 1, CallExpression: { arguments: 2 }, MemberExpression: 2 }, |
| 144 | + ], |
| 145 | + "key-spacing": [ |
| 146 | + 2, |
| 147 | + { |
| 148 | + beforeColon: false, |
| 149 | + }, |
| 150 | + ], |
| 151 | + "eol-last": 2, |
| 152 | + |
| 153 | + // react |
| 154 | + "react/react-in-jsx-scope": 0, |
| 155 | + "no-console": ["warn", { "allow": ["warn", "error"] }], |
| 156 | +}; |
| 157 | + |
| 158 | +const languageOptions = { |
| 159 | + parser: tsParser, |
| 160 | + ecmaVersion: 9, |
| 161 | + sourceType: "module", |
| 162 | + parserOptions: { |
| 163 | + project: path.join(__dirname, "tsconfig.json"), |
| 164 | + } |
| 165 | +}; |
| 166 | + |
| 167 | +export default [ |
| 168 | + { |
| 169 | + ignores: ["dist/**", "node_modules/**", "**/*.js"], |
| 170 | + }, |
| 171 | + { |
| 172 | + files: ["src/**/*.ts"], |
| 173 | + plugins, |
| 174 | + languageOptions, |
| 175 | + rules: baseRules, |
| 176 | + }, |
| 177 | +]; |
0 commit comments