Skip to content

Commit

Permalink
feat: ✨ drop all deprecated options
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 💥 deprecated options are no longer supported.
  • Loading branch information
jimmy-guzman committed Dec 3, 2024
1 parent 496fe8e commit cd09446
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 286 deletions.
2 changes: 1 addition & 1 deletion src/configs/__snapshots__/typescript.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8873,7 +8873,7 @@ If your function does not access \`this\`, you can annotate it with \`this: void
{
"languageOptions": {
"parserOptions": {
"project": "/",
"projectService": true,
"tsconfigRootDir": "/",
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/configs/imports.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -18,7 +18,7 @@ const typescriptImports = {
};

interface ImportsConfigOptions {
typescript?: boolean | TypescriptOptions;
typescript?: boolean;
}

export const importsConfig = ({
Expand Down
4 changes: 2 additions & 2 deletions src/configs/testing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down
10 changes: 5 additions & 5 deletions src/configs/testing.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/configs/typescript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
8 changes: 2 additions & 6 deletions src/configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -14,9 +12,7 @@ export const typescriptConfig = (options?: TypescriptOptions) => {
{
languageOptions: {
parserOptions: {
...(options?.project
? { project: options.project }
: { projectService: true }),
projectService: true,
tsconfigRootDir: process.cwd(),
},
},
Expand Down
68 changes: 0 additions & 68 deletions src/factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 }),
Expand Down
42 changes: 10 additions & 32 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,16 @@ 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 (
{
Expand All @@ -49,35 +42,20 @@ export const eslintConfig = async (
react = false,
storybook = false,
tanstackQuery = false,
testing = false,
testingLibrary = false,
typescript = false,
vitest = false,
}: Options = {},
...moreConfigs: 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());

Expand All @@ -89,11 +67,11 @@ 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() : [],
Expand Down
53 changes: 2 additions & 51 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Linter.RulesRecord & Rules>,
"plugins"
Expand Down Expand Up @@ -95,7 +52,7 @@ export interface Options {
* Are React rules enabled?
* @default false
*/
react?: boolean | ReactOptions;
react?: boolean;
/**
* Are Storybook rules enabled?
* @default false
Expand All @@ -106,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
Expand All @@ -121,7 +72,7 @@ export interface Options {
* Are TypeScript rules enabled?
* @default false
*/
typescript?: boolean | TypescriptOptions;
typescript?: boolean;
/**
* Are Vitest rules enabled?
* @default false
Expand Down
Loading

0 comments on commit cd09446

Please sign in to comment.