Skip to content

Commit

Permalink
fix: πŸ› emulate typescript w/ @typescript-eslint/no-unused-vars
Browse files Browse the repository at this point in the history
🏁 Closes: #78
  • Loading branch information
jimmy-guzman committed Nov 13, 2024
1 parent af3bec2 commit b54d51b
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 29 deletions.
12 changes: 12 additions & 0 deletions src/configs/__snapshots__/typescript.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down
31 changes: 2 additions & 29 deletions src/configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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],
Expand Down
55 changes: 55 additions & 0 deletions src/rules/__snapshots__/typescript.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
}
`;
5 changes: 5 additions & 0 deletions src/rules/typescript.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { typescriptRules } from "./typescript";

test("should create typescript rules", () => {
expect(typescriptRules).toMatchSnapshot();
});
44 changes: 44 additions & 0 deletions src/rules/typescript.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit b54d51b

Please sign in to comment.