@shayanthenerd/eslint-config
Version:
A modern, flexible ESLint configuration for enforcing best practices and maintaining a consistent coding style
164 lines (163 loc) • 7.22 kB
JavaScript
import { isEnabled } from "../utils/isEnabled.mjs";
import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
//#region src/rules/typescript.ts
function getTypescriptRules(options) {
const { typescript } = options.configs;
const { removeUnusedImports, typeDefinitionStyle, methodSignatureStyle } = isEnabled(typescript) ? typescript : defaultOptions.configs.typescript;
return {
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": ["warn", { "ts-expect-error": { descriptionFormat: "^ -- .+ $" } }],
"@typescript-eslint/consistent-return": "error",
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/explicit-member-accessibility": "warn",
"@typescript-eslint/no-array-delete": "error",
"@typescript-eslint/no-base-to-string": "error",
"@typescript-eslint/no-confusing-void-expression": "error",
"@typescript-eslint/no-deprecated": "error",
"@typescript-eslint/no-duplicate-enum-values": "error",
"@typescript-eslint/no-duplicate-type-constituents": "error",
"@typescript-eslint/no-dynamic-delete": "error",
"@typescript-eslint/no-empty-object-type": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extra-non-null-assertion": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-implied-eval": "error",
"@typescript-eslint/no-invalid-void-type": "error",
"@typescript-eslint/no-meaningless-void-operator": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-misused-spread": "error",
"@typescript-eslint/no-mixed-enums": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-redundant-type-constituents": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/no-unnecessary-template-expression": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unnecessary-type-constraint": "error",
"@typescript-eslint/no-unnecessary-type-conversion": "error",
"@typescript-eslint/no-unnecessary-type-parameters": "error",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-unsafe-call": "warn",
"@typescript-eslint/no-unsafe-declaration-merging": "warn",
"@typescript-eslint/no-unsafe-enum-comparison": "error",
"@typescript-eslint/no-unsafe-function-type": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/no-unsafe-return": "error",
"@typescript-eslint/no-unsafe-unary-minus": "error",
"@typescript-eslint/no-unused-vars": ["error", {
args: "all",
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
enableAutofixRemoval: { imports: removeUnusedImports }
}],
"@typescript-eslint/no-useless-default-assignment": "warn",
"@typescript-eslint/no-wrapper-object-types": "error",
"@typescript-eslint/only-throw-error": "error",
"@typescript-eslint/prefer-as-const": "warn",
"@typescript-eslint/prefer-literal-enum-member": "warn",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/prefer-promise-reject-errors": "error",
"@typescript-eslint/prefer-reduce-type-parameter": "error",
"@typescript-eslint/prefer-return-this-type": "error",
"@typescript-eslint/related-getter-setter-pairs": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/require-await": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"@typescript-eslint/restrict-template-expressions": "error",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
"@typescript-eslint/adjacent-overload-signatures": "warn",
"@typescript-eslint/array-type": "warn",
"@typescript-eslint/class-literal-property-style": "warn",
"@typescript-eslint/consistent-generic-constructors": "warn",
"@typescript-eslint/consistent-indexed-object-style": "warn",
"@typescript-eslint/consistent-type-assertions": "warn",
"@typescript-eslint/consistent-type-definitions": ["warn", typeDefinitionStyle],
"@typescript-eslint/dot-notation": "warn",
"@typescript-eslint/no-confusing-non-null-assertion": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/non-nullable-type-assertion-style": "error",
"@typescript-eslint/prefer-find": "warn",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "warn",
"@typescript-eslint/prefer-nullish-coalescing": "warn",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/prefer-readonly": "warn",
"@typescript-eslint/prefer-regexp-exec": "warn",
"@typescript-eslint/prefer-string-starts-ends-with": "warn",
"@typescript-eslint/default-param-last": "warn",
"@typescript-eslint/prefer-destructuring": ["warn", {
object: true,
array: false
}],
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/consistent-type-imports": "warn",
"@typescript-eslint/no-useless-empty-export": "error",
"@typescript-eslint/no-unsafe-type-assertion": "warn",
"@typescript-eslint/prefer-enum-initializers": "error",
"@typescript-eslint/no-unnecessary-qualifier": "warn",
"@typescript-eslint/strict-void-return": "error",
"@typescript-eslint/switch-exhaustiveness-check": ["warn", {
requireDefaultForNonUnion: true,
considerDefaultExhaustiveForUnions: true
}],
"@typescript-eslint/no-unused-private-class-members": "error",
"@typescript-eslint/no-unnecessary-parameter-property-assignment": "warn",
"@typescript-eslint/method-signature-style": ["warn", methodSignatureStyle],
"@typescript-eslint/naming-convention": [
"warn",
{
selector: "variable",
modifiers: ["destructured"],
format: [
"camelCase",
"PascalCase",
"UPPER_CASE"
],
leadingUnderscore: "allow"
},
{
selector: "variable",
format: [
"camelCase",
"PascalCase",
"UPPER_CASE"
]
},
{
selector: "memberLike",
modifiers: ["#private", "private"],
format: ["camelCase"],
leadingUnderscore: "forbid"
},
{
selector: "enumMember",
format: ["PascalCase"]
},
{
selector: "typeLike",
format: ["PascalCase"],
custom: {
regex: "^(I|T(?!S))[A-Z]",
match: false
}
}
]
};
}
//#endregion
export { getTypescriptRules };