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 6, 2024
1 parent 02437a1 commit 2cec55b
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 298 deletions.
5 changes: 1 addition & 4 deletions scripts/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { builtinRules } from "eslint/use-at-your-own-risk";
import eslintConfig from "../src";

const configs = await eslintConfig({
testing: {
// TODO: remove when framework approach is removed
framework: "jest",
},
jest: true,
});

const ruleDts = await flatConfigsToRulesDTS(
Expand Down
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 @@ -8883,7 +8883,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
Expand Up @@ -2,7 +2,7 @@ import { createTypeScriptImportResolver } from "eslint-import-resolver-typescrip
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 @@ -29,7 +29,7 @@ const importsTypescriptConfig = () => {
};

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,14 +3,14 @@ import { testingConfig } from "./testing";

describe("testingConfig", () => {
it("should create default config w/ vitest", async () => {
const [vitest] = await testingConfig({}, false);
const [vitest] = await testingConfig({ vitest: true }, false);

expect(vitest?.name).toBe("jimmy.codes/vitest");
expect(vitest?.ignores).toStrictEqual(GLOB_E2E);
});

it("should create default config w/ jest", async () => {
const [jest] = await testingConfig({ framework: "jest" }, false);
const [jest] = await testingConfig({ jest: true }, false);

expect(jest?.name).toBe("jimmy.codes/jest");
expect(jest?.ignores).toStrictEqual(GLOB_E2E);
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
44 changes: 10 additions & 34 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,22 @@ 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,
hasNext,
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,
nextjs = false,
Expand All @@ -53,35 +45,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());
const isNextjsEnabled = nextjs || (autoDetect && hasNext());
Expand All @@ -94,19 +71,18 @@ 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() : [],
isNextjsEnabled ? await nextjsConfig() : [],
prettierConfig(),
commonjsConfig(),
ignoresConfig(ignores),
configs,
overrides,
moreOverrides,
].flat();
Expand Down
Loading

0 comments on commit 2cec55b

Please sign in to comment.