|
| 1 | +type Severity = 0 | 1 | 2; |
| 2 | +type SeverityString = "error" | "off" | "warn"; |
| 3 | +type RuleLevel = Severity | SeverityString; |
| 4 | +type RuleLevelAndOptions = [RuleLevel, ...unknown[]]; |
| 5 | +type RuleEntry = RuleLevel | RuleLevelAndOptions; |
| 6 | +type RulesRecord = Partial<Record<string, RuleEntry>>; |
| 7 | + |
| 8 | +const templateIndentAnnotations = [ |
| 9 | + "outdent", |
| 10 | + "dedent", |
| 11 | + "html", |
| 12 | + "tsx", |
| 13 | + "ts", |
| 14 | +]; |
| 15 | + |
| 16 | +const p11tOptions = { |
| 17 | + type: "natural", |
| 18 | + ignoreCase: false, |
| 19 | +}; |
| 20 | + |
| 21 | +const p11tGroups = { |
| 22 | + customGroups: { |
| 23 | + id: ["^_$", "^id$", "^key$", "^self$"], |
| 24 | + type: ["^type$", "^kind$"], |
| 25 | + meta: [ |
| 26 | + "^name$", |
| 27 | + "^meta$", |
| 28 | + "^title$", |
| 29 | + "^description$", |
| 30 | + ], |
| 31 | + alias: ["^alias$", "^as$"], |
| 32 | + rules: ["^node$", "^messageId$"], |
| 33 | + }, |
| 34 | + groups: ["id", "type", "meta", "alias", "rules", "unknown"], |
| 35 | +}; |
| 36 | + |
| 37 | +export const typescript: { rules: RulesRecord } = { |
| 38 | + rules: { |
| 39 | + eqeqeq: ["error", "smart"], |
| 40 | + "no-undef": "off", |
| 41 | + "no-console": "error", |
| 42 | + "no-else-return": "error", |
| 43 | + "no-fallthrough": ["error", { commentPattern: ".*intentional fallthrough.*" }], |
| 44 | + "no-implicit-coercion": ["error", { allow: ["!!"] }], |
| 45 | + "no-mixed-operators": "warn", |
| 46 | + "prefer-object-has-own": "error", |
| 47 | + // Part: custom rules |
| 48 | + "no-restricted-syntax": [ |
| 49 | + "error", |
| 50 | + { |
| 51 | + message: "no optional", |
| 52 | + selector: "TSPropertySignature[optional=true]", |
| 53 | + }, |
| 54 | + ], |
| 55 | + // Part: typescript-eslint rules |
| 56 | + "@typescript-eslint/ban-ts-comment": [ |
| 57 | + "error", |
| 58 | + { |
| 59 | + minimumDescriptionLength: 5, |
| 60 | + "ts-check": false, |
| 61 | + "ts-expect-error": "allow-with-description", |
| 62 | + "ts-ignore": true, |
| 63 | + "ts-nocheck": true, |
| 64 | + }, |
| 65 | + ], |
| 66 | + "@typescript-eslint/ban-types": "off", |
| 67 | + "@typescript-eslint/consistent-type-imports": "error", |
| 68 | + "@typescript-eslint/explicit-function-return-type": "off", |
| 69 | + "@typescript-eslint/no-namespace": "off", |
| 70 | + "@typescript-eslint/no-empty-object-type": "off", |
| 71 | + "@typescript-eslint/no-misused-promises": "off", |
| 72 | + "@typescript-eslint/no-unnecessary-parameter-property-assignment": "warn", |
| 73 | + "@typescript-eslint/no-unused-vars": ["warn", { caughtErrors: "all" }], |
| 74 | + "@typescript-eslint/consistent-type-exports": "error", |
| 75 | + "@typescript-eslint/strict-boolean-expressions": ["error", { |
| 76 | + allowAny: false, |
| 77 | + allowNullableBoolean: false, |
| 78 | + allowNullableEnum: false, |
| 79 | + allowNullableNumber: false, |
| 80 | + allowNullableObject: false, |
| 81 | + allowNullableString: false, |
| 82 | + allowNumber: true, |
| 83 | + allowString: false, |
| 84 | + }], |
| 85 | + // Part: jsdoc rules |
| 86 | + "jsdoc/check-param-names": "warn", |
| 87 | + "jsdoc/check-tag-names": "warn", |
| 88 | + "jsdoc/informative-docs": "off", |
| 89 | + "jsdoc/lines-before-block": "off", |
| 90 | + "jsdoc/require-jsdoc": "off", |
| 91 | + "jsdoc/require-param": "warn", |
| 92 | + "jsdoc/require-param-description": "warn", |
| 93 | + "jsdoc/require-returns": "off", |
| 94 | + "jsdoc/require-yields": "warn", |
| 95 | + "jsdoc/tag-lines": "off", |
| 96 | + // Part: simple-import-sort rules |
| 97 | + "simple-import-sort/exports": "warn", |
| 98 | + "simple-import-sort/imports": "warn", |
| 99 | + // Part: stylistic rules |
| 100 | + "@stylistic/arrow-parens": ["warn", "always"], |
| 101 | + "@stylistic/no-multi-spaces": ["warn"], |
| 102 | + "@stylistic/operator-linebreak": [ |
| 103 | + "warn", |
| 104 | + "before", |
| 105 | + ], |
| 106 | + "@stylistic/quote-props": ["error", "as-needed"], |
| 107 | + // Part: perfectionist rules |
| 108 | + "perfectionist/sort-exports": "off", |
| 109 | + "perfectionist/sort-imports": "off", |
| 110 | + "perfectionist/sort-interfaces": [ |
| 111 | + "warn", |
| 112 | + { |
| 113 | + ...p11tOptions, |
| 114 | + ...p11tGroups, |
| 115 | + }, |
| 116 | + ], |
| 117 | + "perfectionist/sort-intersection-types": "off", |
| 118 | + "perfectionist/sort-modules": "off", |
| 119 | + "perfectionist/sort-named-exports": "off", |
| 120 | + "perfectionist/sort-named-imports": "off", |
| 121 | + "perfectionist/sort-object-types": [ |
| 122 | + "warn", |
| 123 | + { |
| 124 | + ...p11tOptions, |
| 125 | + ...p11tGroups, |
| 126 | + }, |
| 127 | + ], |
| 128 | + "perfectionist/sort-objects": [ |
| 129 | + "warn", |
| 130 | + { |
| 131 | + ...p11tOptions, |
| 132 | + ...p11tGroups, |
| 133 | + partitionByComment: "^Part:.*", |
| 134 | + }, |
| 135 | + ], |
| 136 | + "perfectionist/sort-switch-case": "off", |
| 137 | + "perfectionist/sort-union-types": "off", |
| 138 | + // Part: unicorn rules |
| 139 | + "unicorn/template-indent": [ |
| 140 | + "warn", |
| 141 | + { |
| 142 | + comments: templateIndentAnnotations, |
| 143 | + tags: templateIndentAnnotations, |
| 144 | + }, |
| 145 | + ], |
| 146 | + }, |
| 147 | +}; |
0 commit comments