diff --git a/src/configs/__snapshots__/typescript.spec.ts.snap b/src/configs/__snapshots__/typescript.spec.ts.snap index 76fa49a..85a0646 100644 --- a/src/configs/__snapshots__/typescript.spec.ts.snap +++ b/src/configs/__snapshots__/typescript.spec.ts.snap @@ -8826,6 +8826,18 @@ If your function does not access \`this\`, you can annotate it with \`this: void }, }, ], + "@typescript-eslint/no-unused-vars": [ + "error", + { + "args": "all", + "argsIgnorePattern": "^_", + "caughtErrors": "all", + "caughtErrorsIgnorePattern": "^_", + "destructuredArrayIgnorePattern": "^_", + "ignoreRestSiblings": true, + "varsIgnorePattern": "^_", + }, + ], "@typescript-eslint/no-use-before-define": [ "error", { diff --git a/src/configs/typescript.ts b/src/configs/typescript.ts index 0c79441..4239f38 100644 --- a/src/configs/typescript.ts +++ b/src/configs/typescript.ts @@ -3,6 +3,7 @@ import { configs } from "typescript-eslint"; import type { TypescriptOptions } from "../types"; import { GLOB_JS, GLOB_JSX, GLOB_TESTS } from "../constants"; +import { typescriptRules } from "../rules/typescript"; export const typescriptConfig = (options: TypescriptOptions) => { return [ @@ -18,35 +19,7 @@ export const typescriptConfig = (options: TypescriptOptions) => { }, }, name: "jimmy.codes/typescript", - rules: { - "@typescript-eslint/consistent-type-exports": [ - "error", - { fixMixedExportsWithInlineTypeSpecifier: false }, - ], - "@typescript-eslint/consistent-type-imports": [ - "error", - { fixStyle: "separate-type-imports" }, - ], - "@typescript-eslint/no-deprecated": "warn", - "@typescript-eslint/no-misused-promises": [ - "error", - { checksVoidReturn: { attributes: false } }, - ], - "@typescript-eslint/no-use-before-define": [ - "error", - { - allowNamedExports: false, - classes: false, - functions: false, - variables: true, - }, - ], - "@typescript-eslint/restrict-template-expressions": [ - "error", - { allowNumber: true }, - ], - "no-use-before-define": "off", - }, + rules: typescriptRules, }, { files: [GLOB_JS, GLOB_JSX], diff --git a/src/rules/__snapshots__/typescript.spec.ts.snap b/src/rules/__snapshots__/typescript.spec.ts.snap new file mode 100644 index 0000000..24e412a --- /dev/null +++ b/src/rules/__snapshots__/typescript.spec.ts.snap @@ -0,0 +1,55 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`should create typescript rules 1`] = ` +{ + "@typescript-eslint/consistent-type-exports": [ + "error", + { + "fixMixedExportsWithInlineTypeSpecifier": false, + }, + ], + "@typescript-eslint/consistent-type-imports": [ + "error", + { + "fixStyle": "separate-type-imports", + }, + ], + "@typescript-eslint/no-deprecated": "warn", + "@typescript-eslint/no-misused-promises": [ + "error", + { + "checksVoidReturn": { + "attributes": false, + }, + }, + ], + "@typescript-eslint/no-unused-vars": [ + "error", + { + "args": "all", + "argsIgnorePattern": "^_", + "caughtErrors": "all", + "caughtErrorsIgnorePattern": "^_", + "destructuredArrayIgnorePattern": "^_", + "ignoreRestSiblings": true, + "varsIgnorePattern": "^_", + }, + ], + "@typescript-eslint/no-use-before-define": [ + "error", + { + "allowNamedExports": false, + "classes": false, + "functions": false, + "variables": true, + }, + ], + "@typescript-eslint/restrict-template-expressions": [ + "error", + { + "allowNumber": true, + }, + ], + "no-use-before-define": "off", +} +`; diff --git a/src/rules/typescript.spec.ts b/src/rules/typescript.spec.ts new file mode 100644 index 0000000..f4c3849 --- /dev/null +++ b/src/rules/typescript.spec.ts @@ -0,0 +1,5 @@ +import { typescriptRules } from "./typescript"; + +test("should create typescript rules", () => { + expect(typescriptRules).toMatchSnapshot(); +}); diff --git a/src/rules/typescript.ts b/src/rules/typescript.ts new file mode 100644 index 0000000..63e50a9 --- /dev/null +++ b/src/rules/typescript.ts @@ -0,0 +1,44 @@ +import type { Rules } from "../types"; + +export const typescriptRules = { + "@typescript-eslint/consistent-type-exports": [ + "error", + { fixMixedExportsWithInlineTypeSpecifier: false }, + ], + "@typescript-eslint/consistent-type-imports": [ + "error", + { fixStyle: "separate-type-imports" }, + ], + "@typescript-eslint/no-deprecated": "warn", + "@typescript-eslint/no-misused-promises": [ + "error", + { checksVoidReturn: { attributes: false } }, + ], + "@typescript-eslint/no-unused-vars": [ + "error", + // https://typescript-eslint.io/rules/no-unused-vars/#benefits-over-typescript + { + args: "all", + argsIgnorePattern: "^_", + caughtErrors: "all", + caughtErrorsIgnorePattern: "^_", + destructuredArrayIgnorePattern: "^_", + ignoreRestSiblings: true, + varsIgnorePattern: "^_", + }, + ], + "@typescript-eslint/no-use-before-define": [ + "error", + { + allowNamedExports: false, + classes: false, + functions: false, + variables: true, + }, + ], + "@typescript-eslint/restrict-template-expressions": [ + "error", + { allowNumber: true }, + ], + "no-use-before-define": "off", +} satisfies Rules;