diff --git a/src/configs/__snapshots__/typescript.spec.ts.snap b/src/configs/__snapshots__/typescript.spec.ts.snap index 346acc3..9de0bcc 100644 --- a/src/configs/__snapshots__/typescript.spec.ts.snap +++ b/src/configs/__snapshots__/typescript.spec.ts.snap @@ -8883,7 +8883,7 @@ If your function does not access \`this\`, you can annotate it with \`this: void { "languageOptions": { "parserOptions": { - "project": "/", + "projectService": true, "tsconfigRootDir": "/", }, }, diff --git a/src/configs/imports.ts b/src/configs/imports.ts index 4cb932f..508f79d 100644 --- a/src/configs/imports.ts +++ b/src/configs/imports.ts @@ -1,7 +1,7 @@ import importX from "eslint-plugin-import-x"; import nodePlugin from "eslint-plugin-n"; -import type { TypedConfigItem, TypescriptOptions } from "../types"; +import type { TypedConfigItem } from "../types"; import { importsRules } from "../rules/imports"; @@ -18,7 +18,7 @@ const typescriptImports = { }; interface ImportsConfigOptions { - typescript?: boolean | TypescriptOptions; + typescript?: boolean; } export const importsConfig = ({ diff --git a/src/configs/testing.spec.ts b/src/configs/testing.spec.ts index 1de5ae5..f887454 100644 --- a/src/configs/testing.spec.ts +++ b/src/configs/testing.spec.ts @@ -3,7 +3,7 @@ import { testingConfig } from "./testing"; describe("testingConfig", () => { it("should create default config w/ vitest overrides", async () => { - const [vitest] = await testingConfig({}, false); + const [vitest] = await testingConfig({ vitest: true }, false); expect(vitest?.rules).toStrictEqual( expect.objectContaining({ @@ -19,7 +19,7 @@ describe("testingConfig", () => { }); it("should create default config w/o vitest overrides", async () => { - const [jest] = await testingConfig({ framework: "jest" }, false); + const [jest] = await testingConfig({ jest: true }, false); expect(jest?.rules).toStrictEqual( expect.not.objectContaining({ diff --git a/src/configs/testing.ts b/src/configs/testing.ts index 2c800a7..afc7ccc 100644 --- a/src/configs/testing.ts +++ b/src/configs/testing.ts @@ -1,4 +1,4 @@ -import type { TestingOptions, TypedConfigItem } from "../types"; +import type { TypedConfigItem } from "../types"; import { GLOB_E2E, GLOB_TESTS } from "../constants"; import { jestRules } from "../rules/jest"; @@ -7,11 +7,11 @@ import { hasJest, hasVitest } from "../utils/has-dependency"; import { interopDefault } from "../utils/interop-default"; export const testingConfig = async ( - { framework = "vitest" }: TestingOptions = {}, - autoDetect = true, + { jest = false, vitest = false }: { jest?: boolean; vitest?: boolean }, + autoDetect?: boolean, ) => { - const isVitest = autoDetect ? hasVitest() : framework === "vitest"; - const isJest = framework === "jest" || (autoDetect && hasJest()); + const isVitest = vitest || (autoDetect && hasVitest()); + const isJest = jest || (autoDetect && hasJest()); const configs: TypedConfigItem[] = []; diff --git a/src/configs/typescript.spec.ts b/src/configs/typescript.spec.ts index 17370e0..69440d1 100644 --- a/src/configs/typescript.spec.ts +++ b/src/configs/typescript.spec.ts @@ -4,7 +4,7 @@ describe("typescriptConfig", () => { it("should create config", () => { vi.spyOn(process, "cwd").mockReturnValue("/"); - expect(typescriptConfig({ project: "/" })).toMatchSnapshot(); + expect(typescriptConfig()).toMatchSnapshot(); }); it("should create config w/ projectService", () => { diff --git a/src/configs/typescript.ts b/src/configs/typescript.ts index 4f7033b..45244ab 100644 --- a/src/configs/typescript.ts +++ b/src/configs/typescript.ts @@ -1,11 +1,9 @@ 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) => { +export const typescriptConfig = () => { return [ ...configs.strictTypeChecked, ...configs.stylisticTypeChecked.filter((config) => { @@ -14,9 +12,7 @@ export const typescriptConfig = (options?: TypescriptOptions) => { { languageOptions: { parserOptions: { - ...(options?.project - ? { project: options.project } - : { projectService: true }), + projectService: true, tsconfigRootDir: process.cwd(), }, }, diff --git a/src/factory.spec.ts b/src/factory.spec.ts index d15aee1..e0083fb 100644 --- a/src/factory.spec.ts +++ b/src/factory.spec.ts @@ -46,54 +46,18 @@ describe("eslintConfig", () => { ); }); - it("should create configuration w/ react & @tanstack/query (deprecated)", async () => { - await expect( - eslintConfig({ - autoDetect: false, - react: { utilities: ["@tanstack/query"] }, - }), - ).resolves.toStrictEqual( - expect.arrayContaining([ - expect.objectContaining({ name: "jimmy.codes/react" }), - expect.objectContaining({ name: "jimmy.codes/react/query" }), - ]), - ); - }); - it("should create configuration w/ jest", async () => { const configs = await eslintConfig({ autoDetect: false, jest: true }); expect(configs.at(7)?.name).toBe("jimmy.codes/jest"); }); - it("should create configuration w/ jest (deprecated)", async () => { - await expect( - eslintConfig({ autoDetect: false, testing: { framework: "jest" } }), - ).resolves.toStrictEqual( - expect.arrayContaining([ - expect.objectContaining({ name: "jimmy.codes/jest" }), - expect.not.objectContaining({ name: "jimmy.codes/vitest" }), - ]), - ); - }); - it("should create configuration w/ vitest", async () => { const configs = await eslintConfig({ autoDetect: false, vitest: true }); expect(configs.at(7)?.name).toBe("jimmy.codes/vitest"); }); - it("should create configuration w/ vitest (deprecated)", async () => { - await expect( - eslintConfig({ autoDetect: false, testing: true }), - ).resolves.toStrictEqual( - expect.arrayContaining([ - expect.not.objectContaining({ name: "jimmy.codes/jest" }), - expect.objectContaining({ name: "jimmy.codes/vitest" }), - ]), - ); - }); - it("should create configuration w/ jest & react & testing library", async () => { const configs = await eslintConfig({ autoDetect: false, @@ -107,22 +71,6 @@ describe("eslintConfig", () => { expect(configs.at(9)?.name).toBe("jimmy.codes/testing-library"); }); - it("should create configuration w/ jest & react & testing library (deprecated)", async () => { - await expect( - eslintConfig({ - autoDetect: false, - react: true, - testing: { framework: "jest", utilities: ["testing-library"] }, - }), - ).resolves.toStrictEqual( - expect.arrayContaining([ - expect.objectContaining({ name: "jimmy.codes/jest" }), - expect.objectContaining({ name: "jimmy.codes/react" }), - expect.objectContaining({ name: "jimmy.codes/testing-library" }), - ]), - ); - }); - it("should create configuration w/ vitest & react & testing library", async () => { const configs = await eslintConfig({ autoDetect: false, @@ -136,22 +84,6 @@ describe("eslintConfig", () => { expect(configs.at(9)?.name).toBe("jimmy.codes/testing-library"); }); - it("should create configuration w/ vitest & react & testing library (deprecated)", async () => { - await expect( - eslintConfig({ - autoDetect: false, - react: true, - testing: { utilities: ["testing-library"] }, - }), - ).resolves.toStrictEqual( - expect.arrayContaining([ - expect.objectContaining({ name: "jimmy.codes/vitest" }), - expect.objectContaining({ name: "jimmy.codes/react" }), - expect.objectContaining({ name: "jimmy.codes/testing-library" }), - ]), - ); - }); - it("should create configuration w/ astro", async () => { await expect( eslintConfig({ astro: true, autoDetect: false }), diff --git a/src/factory.ts b/src/factory.ts index 7e52ab8..a5851c9 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -20,29 +20,21 @@ import { testingConfig } from "./configs/testing"; import { testingLibraryConfig } from "./configs/testing-library"; import { typescriptConfig } from "./configs/typescript"; import { unicornConfig } from "./configs/unicorn"; -import { - getReactOptions, - getTestingOptions, - getTypescriptOptions, -} from "./utils/get-options"; import { hasAstro, hasPlaywright, hasReact, + hasReactQuery, hasStorybook, hasTesting, + hasTestingLibrary, hasTypescript, } from "./utils/has-dependency"; -import { - shouldEnableTanstackQuery, - shouldEnableTestingLibrary, -} from "./utils/should-enable"; export const eslintConfig = async ( { astro = false, autoDetect = true, - configs = [], ignores = [], jest = false, overrides = [], @@ -50,35 +42,20 @@ export const eslintConfig = async ( react = false, storybook = false, tanstackQuery = false, - testing = false, testingLibrary = false, typescript = false, vitest = false, }: Options = {}, ...moreOverrides: Linter.Config[] | TypedConfigItem[] ) => { - const reactOptions = getReactOptions(react); - const testingOptions = getTestingOptions(testing, { - jest, - testingLibrary, - vitest, - }); - const typescriptOptions = getTypescriptOptions(typescript); - const isTypescriptEnabled = - typescript || !!typescriptOptions || (autoDetect && hasTypescript()); + const isTypescriptEnabled = typescript || (autoDetect && hasTypescript()); const isReactEnabled = react || (autoDetect && hasReact()); - const isTestingEnabled = - testing || jest || vitest || (autoDetect && hasTesting()); + const isTestingEnabled = jest || vitest || (autoDetect && hasTesting()); const isAstroEnabled = astro || (autoDetect && hasAstro()); - const isTanstackQueryEnabled = shouldEnableTanstackQuery( - reactOptions, - tanstackQuery, - autoDetect, - ); - const isTestingLibraryEnabled = shouldEnableTestingLibrary( - testingOptions, - autoDetect, - ); + const isTanstackQueryEnabled = + tanstackQuery || (autoDetect && hasReactQuery()); + const isTestingLibraryEnabled = + testingLibrary || (autoDetect && hasTestingLibrary()); const isPlaywrightEnabled = playwright || (autoDetect && hasPlaywright()); const isStorybookEnabled = storybook || (autoDetect && hasStorybook()); @@ -90,18 +67,17 @@ export const eslintConfig = async ( eslintCommentsConfig(), regexpConfig(), importsConfig({ typescript: isTypescriptEnabled }), - isTypescriptEnabled ? typescriptConfig(typescriptOptions) : [], + isTypescriptEnabled ? typescriptConfig() : [], isReactEnabled ? await reactConfig() : [], isTanstackQueryEnabled ? await tanstackQueryConfig() : [], isAstroEnabled ? await astroConfig() : [], - isTestingEnabled ? await testingConfig(testingOptions, autoDetect) : [], + isTestingEnabled ? await testingConfig({ jest, vitest }, autoDetect) : [], isTestingLibraryEnabled ? await testingLibraryConfig() : [], isPlaywrightEnabled ? await playwrightConfig() : [], isStorybookEnabled ? await storybookConfig() : [], prettierConfig(), commonjsConfig(), ignoresConfig(ignores), - configs, overrides, moreOverrides, ].flat(); diff --git a/src/types.ts b/src/types.ts index 006ca9b..1367c39 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,49 +4,6 @@ import type { RuleOptions } from "./rules.gen"; export type Rules = RuleOptions; -/** - * @deprecated - */ -export interface TypescriptOptions { - /** - * Location of `tsconfig.json` used for [type aware linting](https://typescript-eslint.io/getting-started/typed-linting) - * @deprecated since this config uses `projectService` this is no longer needed and will be removed. - */ - project: string | string[]; -} - -type TestingFrameworks = "jest" | "vitest"; -type TestingUtilities = "testing-library"; -type ReactUtilities = "@tanstack/query"; - -/** - * @deprecated - */ -export interface TestingOptions { - /** - * Which testing framework are you using? - * @default "vitest" - */ - framework?: TestingFrameworks; - /** - * Enable additional rules for testing utilities such as: - * - [Testing Library](https://testing-library.com) - */ - utilities?: TestingUtilities[]; -} - -/** - * @deprecated - */ - -export interface ReactOptions { - /** - * Enable additional rules for utilities such as: - * - [React Query](https://tanstack.com/query/latest/docs/framework/react/overview) - */ - utilities?: ReactUtilities[]; -} - export type TypedConfigItem = Omit< Linter.Config, "plugins" @@ -71,12 +28,6 @@ export interface Options { * @default true */ autoDetect?: boolean; - /** - * Additional configs to either extend or overrides configurations - * @deprecated please use {@link Options.configs} instead. - * @default [] - */ - configs?: Linter.Config[] | TypedConfigItem[]; /** * Glob patterns for files that should be ignored * @see [Ignoring files](https://eslint.org/docs/latest/use/configure/ignore) @@ -101,7 +52,7 @@ export interface Options { * Are React rules enabled? * @default false */ - react?: boolean | ReactOptions; + react?: boolean; /** * Are Storybook rules enabled? * @default false @@ -112,12 +63,6 @@ export interface Options { * @default false */ tanstackQuery?: boolean; - /** - * Are testing rules enabled? - * @default false - * @deprecated please use {@link Options.jest}, {@link Options.vitest}, or {@link Options.testingLibrary} instead. - */ - testing?: boolean | TestingOptions; /** * Are Testing Library rules enabled? * @default false @@ -127,7 +72,7 @@ export interface Options { * Are TypeScript rules enabled? * @default false */ - typescript?: boolean | TypescriptOptions; + typescript?: boolean; /** * Are Vitest rules enabled? * @default false diff --git a/src/utils/get-options.spec.ts b/src/utils/get-options.spec.ts deleted file mode 100644 index a7f5198..0000000 --- a/src/utils/get-options.spec.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - getReactOptions, - getTestingOptions, - getTypescriptOptions, -} from "./get-options"; - -describe("getTypescriptOptions", () => { - it("should return undefined when a boolean is provided", () => { - expect(getTypescriptOptions(true)).toBeUndefined(); - }); - it("should return override options when an object is provided", () => { - expect( - getTypescriptOptions({ - project: "./tsconfig.eslint.json", - }), - ).toStrictEqual({ - project: "./tsconfig.eslint.json", - }); - }); -}); - -describe("getTestingOptions", () => { - it("should return default options when a boolean is provided", () => { - expect( - getTestingOptions(true, { - jest: false, - testingLibrary: false, - vitest: false, - }), - ).toStrictEqual({ - framework: "vitest", - }); - }); - it("should return override options when an object is provided", () => { - expect( - getTestingOptions( - { - framework: "jest", - utilities: ["testing-library"], - }, - { - jest: false, - testingLibrary: false, - vitest: false, - }, - ), - ).toStrictEqual({ - framework: "jest", - utilities: ["testing-library"], - }); - }); -}); - -describe("getReactOptions", () => { - it("should return default options when a boolean is provided", () => { - expect(getReactOptions(true)).toStrictEqual({ utilities: [] }); - }); - it("should return override options when an object is provided", () => { - expect( - getReactOptions({ - utilities: ["@tanstack/query"], - }), - ).toStrictEqual({ - utilities: ["@tanstack/query"], - }); - }); -}); diff --git a/src/utils/get-options.ts b/src/utils/get-options.ts deleted file mode 100644 index 63e46da..0000000 --- a/src/utils/get-options.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { ReactOptions, TestingOptions, TypescriptOptions } from "../types"; - -export const getTypescriptOptions = (options: boolean | TypescriptOptions) => { - return typeof options === "object" ? options : undefined; -}; - -export const getTestingOptions = ( - options: boolean | TestingOptions, - configs: { - jest: boolean; - testingLibrary: boolean; - vitest: boolean; - }, -) => { - return typeof options === "object" - ? options - : ({ - framework: configs.vitest ? "vitest" : configs.jest ? "jest" : "vitest", - ...(configs.testingLibrary && { - utilities: ["testing-library" as const], - }), - } as const); -}; - -export const getReactOptions = (options: boolean | ReactOptions) => { - return typeof options === "object" ? options : { utilities: [] }; -}; diff --git a/src/utils/should-enable.ts b/src/utils/should-enable.ts deleted file mode 100644 index d69cbf4..0000000 --- a/src/utils/should-enable.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { ReactOptions, TestingOptions } from "../types"; - -import { hasReactQuery, hasTestingLibrary } from "./has-dependency"; - -export const shouldEnableTanstackQuery = ( - { utilities = [] }: ReactOptions, - tanstackQuery: boolean, - autoDetect: boolean, -) => { - return ( - tanstackQuery || - utilities.includes("@tanstack/query") || - (autoDetect && hasReactQuery()) - ); -}; - -export const shouldEnableTestingLibrary = ( - { utilities = [] }: TestingOptions, - autoDetect: boolean, -) => { - return ( - utilities.includes("testing-library") || (autoDetect && hasTestingLibrary()) - ); -};