Skip to content

Commit

Permalink
feat: ✨ use @vitest/eslint-plugin for vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Dec 6, 2024
1 parent 7be42e1 commit 0adae02
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 97 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@types/eslint": "9.6.1",
"@typescript-eslint/parser": "^8.17.0",
"@typescript-eslint/utils": "^8.17.0",
"@vitest/eslint-plugin": "^1.1.14",
"astro-eslint-parser": "^1.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.7.0",
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion scripts/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { builtinRules } from "eslint/use-at-your-own-risk";

import eslintConfig from "../src";

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

const ruleDts = await flatConfigsToRulesDTS(
[
Expand Down
29 changes: 4 additions & 25 deletions src/configs/testing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
import { ALLOWED_VITEST_FUNCS } from "../constants";
import { testingConfig } from "./testing";

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

expect(vitest?.rules).toStrictEqual(
expect.objectContaining({
"jest/no-deprecated-functions": "off",
"jest/require-hook": [
"error",
{
allowedFunctionCalls: ALLOWED_VITEST_FUNCS,
},
],
}),
);
expect(vitest?.name).toBe("jimmy.codes/vitest");
});

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

expect(jest?.rules).toStrictEqual(
expect.not.objectContaining({
"jest/no-deprecated-functions": "off",
"jest/require-hook": [
"error",
{
allowedFunctionCalls: ALLOWED_VITEST_FUNCS,
},
],
}),
);
expect(jest?.name).toBe("jimmy.codes/jest");
});
});
5 changes: 2 additions & 3 deletions src/configs/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ export const testingConfig = async (
const configs: TypedConfigItem[] = [];

if (isVitest) {
const jestPlugin = await interopDefault(import("eslint-plugin-jest"));
const vitestPlugin = await interopDefault(import("@vitest/eslint-plugin"));

configs.push({
files: GLOB_TESTS,
ignores: GLOB_E2E,
...jestPlugin.configs["flat/recommended"],
...vitestPlugin.configs.recommended,
name: "jimmy.codes/vitest",
rules: await vitestRules(),
});
Expand Down
2 changes: 0 additions & 2 deletions src/factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ describe("eslintConfig", () => {

it("should include react-query when auto detection is enabled", async () => {
vi.mocked(isPackageExists).mockImplementation((name) => {
// eslint-disable-next-line jest/no-conditional-in-test -- this condition is only for the mock.
return name === "react" || name === "@tanstack/react-query";
});

Expand Down Expand Up @@ -298,7 +297,6 @@ describe("eslintConfig", () => {

it("should include test-library when auto detection is enabled", async () => {
vi.mocked(isPackageExists).mockImplementation((name) => {
// eslint-disable-next-line jest/no-conditional-in-test -- this condition is only for the mock.
return name === "@testing-library/react" || name === "vitest";
});

Expand Down
Loading

0 comments on commit 0adae02

Please sign in to comment.