Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 actually enforce separate type imports #34

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/configs/commonjs.ts
Original file line number Diff line number Diff line change
@@ -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 [
Expand Down
6 changes: 4 additions & 2 deletions src/configs/imports.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/configs/perfectionist.ts
Original file line number Diff line number Diff line change
@@ -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 [
Expand Down
6 changes: 4 additions & 2 deletions src/configs/react.ts
Original file line number Diff line number Diff line change
@@ -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 = {},
Expand Down
3 changes: 2 additions & 1 deletion src/configs/testing-library.ts
Original file line number Diff line number Diff line change
@@ -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 [
Expand Down
3 changes: 2 additions & 1 deletion src/configs/testing.ts
Original file line number Diff line number Diff line change
@@ -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 = (
Expand Down
3 changes: 2 additions & 1 deletion src/configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/rules/__snapshots__/imports.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/base.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/rules/imports.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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;
2 changes: 1 addition & 1 deletion src/rules/jest.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/perfectionist.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/react.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/testing-library.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Linter } from "eslint";
import type { Linter } from "eslint";

import type { RuleOptions } from "./rules.gen";

Expand Down
6 changes: 1 addition & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down