From ceadc95c9b611a8c6f7109bc6dd3433d22eeed38 Mon Sep 17 00:00:00 2001 From: Jimmy Guzman <30631540+jimmy-guzman@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:17:42 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20actually=20enforce=20sepa?= =?UTF-8?q?rate=20type=20imports=20(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configs/commonjs.ts | 3 ++- src/configs/imports.ts | 6 ++++-- src/configs/perfectionist.ts | 6 ++++-- src/configs/react.ts | 6 ++++-- src/configs/testing-library.ts | 3 ++- src/configs/testing.ts | 3 ++- src/configs/typescript.ts | 3 ++- src/factory.ts | 6 ++++-- src/rules/__snapshots__/imports.spec.ts.snap | 4 ++++ src/rules/base.ts | 2 +- src/rules/imports.ts | 6 ++++-- src/rules/jest.ts | 2 +- src/rules/perfectionist.ts | 2 +- src/rules/react.ts | 2 +- src/rules/testing-library.ts | 2 +- src/types.ts | 2 +- src/utils.ts | 6 +----- 17 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/configs/commonjs.ts b/src/configs/commonjs.ts index c4b9f87..589ca16 100644 --- a/src/configs/commonjs.ts +++ b/src/configs/commonjs.ts @@ -1,7 +1,8 @@ import globals from "globals"; +import type { TypedConfigItem } from "../types"; + import { GLOB_CJS } from "../constants"; -import { type TypedConfigItem } from "../types"; export const commonjsConfig = () => { return [ diff --git a/src/configs/imports.ts b/src/configs/imports.ts index d7938a0..20b2578 100644 --- a/src/configs/imports.ts +++ b/src/configs/imports.ts @@ -1,9 +1,11 @@ -import { type ESLint, type Linter } from "eslint"; +import type { ESLint, Linter } from "eslint"; + import importX from "eslint-plugin-import-x"; import nodeImport from "eslint-plugin-node-import"; +import type { TypescriptOptions } from "../types"; + import { importsRules } from "../rules/imports"; -import { type TypescriptOptions } from "../types"; const typescriptImports = { name: "jimmy.codes/imports/typescript", diff --git a/src/configs/perfectionist.ts b/src/configs/perfectionist.ts index 4803299..851112e 100644 --- a/src/configs/perfectionist.ts +++ b/src/configs/perfectionist.ts @@ -1,8 +1,10 @@ -import { type ESLint } from "eslint"; +import type { ESLint } from "eslint"; + import perfectionist from "eslint-plugin-perfectionist"; +import type { TypedConfigItem } from "../types"; + import { perfectionistRules } from "../rules/perfectionist"; -import { type TypedConfigItem } from "../types"; const perfectionistConfig = () => { return [ diff --git a/src/configs/react.ts b/src/configs/react.ts index aac8296..7a278bf 100644 --- a/src/configs/react.ts +++ b/src/configs/react.ts @@ -1,15 +1,17 @@ +import type { ESLint } from "eslint"; + import queryPlugin from "@tanstack/eslint-plugin-query"; -import { type ESLint } from "eslint"; import jsxA11y from "eslint-plugin-jsx-a11y"; import react from "eslint-plugin-react"; import reactHooks from "eslint-plugin-react-hooks"; import * as reactRefresh from "eslint-plugin-react-refresh"; import globals from "globals"; +import type { ReactOptions, TypedConfigItem } from "../types"; + import { GLOB_JSX, GLOB_TSX } from "../constants"; import { hasReactQuery } from "../has-dep"; import { reactRules } from "../rules/react"; -import { type ReactOptions, type TypedConfigItem } from "../types"; const reactConfig = ( { utilities = [] }: ReactOptions = {}, diff --git a/src/configs/testing-library.ts b/src/configs/testing-library.ts index a668204..0a345f7 100644 --- a/src/configs/testing-library.ts +++ b/src/configs/testing-library.ts @@ -1,8 +1,9 @@ import * as jestDom from "eslint-plugin-jest-dom"; import testingLibrary from "eslint-plugin-testing-library"; +import type { TypedConfigItem } from "../types"; + import { GLOB_E2E, GLOB_TESTS } from "../constants"; -import { type TypedConfigItem } from "../types"; const testingLibraryConfig = () => { return [ diff --git a/src/configs/testing.ts b/src/configs/testing.ts index d408a0c..916d661 100644 --- a/src/configs/testing.ts +++ b/src/configs/testing.ts @@ -1,9 +1,10 @@ import jest from "eslint-plugin-jest"; +import type { Rules, TestingOptions } from "../types"; + import { ALLOWED_VITEST_FUNCS, GLOB_E2E, GLOB_TESTS } from "../constants"; import { hasJest, hasTestingLibrary, hasVitest } from "../has-dep"; import { jestRules } from "../rules/jest"; -import { type Rules, type TestingOptions } from "../types"; import testingLibraryConfig from "./testing-library"; const testingConfig = ( diff --git a/src/configs/typescript.ts b/src/configs/typescript.ts index d015979..0c3a35c 100644 --- a/src/configs/typescript.ts +++ b/src/configs/typescript.ts @@ -1,7 +1,8 @@ import { config, configs } from "typescript-eslint"; +import type { TypescriptOptions } from "../types"; + import { GLOB_JS, GLOB_JSX } from "../constants"; -import { type TypescriptOptions } from "../types"; const typescriptConfig = (options: TypescriptOptions) => { return config( diff --git a/src/factory.ts b/src/factory.ts index a83c0a0..397bbf3 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -1,6 +1,9 @@ -import { type Linter } from "eslint"; +import type { Linter } from "eslint"; + import eslintConfigPrettier from "eslint-config-prettier"; +import type { Options, TypedConfigItem } from "./types"; + import { astroConfig } from "./configs/astro"; import { commonjsConfig } from "./configs/commonjs"; import importsConfig from "./configs/imports"; @@ -11,7 +14,6 @@ import typescriptConfig from "./configs/typescript"; import { GLOB_IGNORES } from "./constants"; import { hasAstro, hasReact, hasTesting, hasTypescript } from "./has-dep"; import { baseRules } from "./rules/base"; -import { type Options, type TypedConfigItem } from "./types"; import { getReactOptions, getTestingOptions, diff --git a/src/rules/__snapshots__/imports.spec.ts.snap b/src/rules/__snapshots__/imports.spec.ts.snap index 4973b7d..60e781c 100644 --- a/src/rules/__snapshots__/imports.spec.ts.snap +++ b/src/rules/__snapshots__/imports.spec.ts.snap @@ -2,6 +2,10 @@ exports[`should create imports rules 1`] = ` { + "import-x/consistent-type-specifier-style": [ + "error", + "prefer-top-level", + ], "import-x/default": "error", "import-x/export": "error", "import-x/first": "error", diff --git a/src/rules/base.ts b/src/rules/base.ts index f4bdd36..5e507e9 100644 --- a/src/rules/base.ts +++ b/src/rules/base.ts @@ -1,6 +1,6 @@ import eslint from "@eslint/js"; -import { type Rules } from "../types"; +import type { Rules } from "../types"; export const baseRules = { ...eslint.configs.recommended.rules, diff --git a/src/rules/imports.ts b/src/rules/imports.ts index c34b514..d5062c1 100644 --- a/src/rules/imports.ts +++ b/src/rules/imports.ts @@ -1,8 +1,10 @@ -import { type Linter } from "eslint"; import importX from "eslint-plugin-import-x"; +import type { Rules } from "../types"; + export const importsRules = { ...importX.configs.recommended.rules, + "import-x/consistent-type-specifier-style": ["error", "prefer-top-level"], "import-x/first": "error", // ! can't get this rule to work "import-x/namespace": "off", @@ -12,4 +14,4 @@ export const importsRules = { "import-x/no-self-import": "error", "import-x/no-useless-path-segments": "error", "node-import/prefer-node-protocol": "error", -} satisfies Linter.RulesRecord; +} satisfies Rules; diff --git a/src/rules/jest.ts b/src/rules/jest.ts index 56e8334..6352cf2 100644 --- a/src/rules/jest.ts +++ b/src/rules/jest.ts @@ -1,6 +1,6 @@ import jest from "eslint-plugin-jest"; -import { type Rules } from "../types"; +import type { Rules } from "../types"; export const jestRules = { ...jest.configs["flat/recommended"].rules, diff --git a/src/rules/perfectionist.ts b/src/rules/perfectionist.ts index fdf9e04..cac3eff 100644 --- a/src/rules/perfectionist.ts +++ b/src/rules/perfectionist.ts @@ -1,6 +1,6 @@ import perfectionist from "eslint-plugin-perfectionist"; -import { type Rules } from "../types"; +import type { Rules } from "../types"; export const perfectionistRules = { ...perfectionist.configs["recommended-natural"].rules, diff --git a/src/rules/react.ts b/src/rules/react.ts index b81e511..2671718 100644 --- a/src/rules/react.ts +++ b/src/rules/react.ts @@ -1,6 +1,6 @@ import jsxA11y from "eslint-plugin-jsx-a11y"; -import { type Rules } from "../types"; +import type { Rules } from "../types"; export const reactRules = { ...jsxA11y.configs.recommended.rules, diff --git a/src/rules/testing-library.ts b/src/rules/testing-library.ts index 3079122..4b1d516 100644 --- a/src/rules/testing-library.ts +++ b/src/rules/testing-library.ts @@ -1,7 +1,7 @@ import * as jestDom from "eslint-plugin-jest-dom"; import testingLibrary from "eslint-plugin-testing-library"; -import { type Rules } from "../types"; +import type { Rules } from "../types"; export const testingLibraryRules = { ...testingLibrary.configs.react.rules, diff --git a/src/types.ts b/src/types.ts index 2ebc19f..581ec05 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import { type Linter } from "eslint"; +import type { Linter } from "eslint"; import type { RuleOptions } from "./rules.gen"; diff --git a/src/utils.ts b/src/utils.ts index e06fd6f..1145112 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,8 +1,4 @@ -import { - type ReactOptions, - type TestingOptions, - type TypescriptOptions, -} from "./types"; +import type { ReactOptions, TestingOptions, TypescriptOptions } from "./types"; export const getTypescriptOptions = (options: boolean | TypescriptOptions) => { return typeof options === "object"