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

feat: ✨ add eslint-plugin-playwright rules #99

Merged
merged 1 commit into from
Nov 23, 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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-n": "^17.14.0",
"eslint-plugin-perfectionist": "^4.0.3",
"eslint-plugin-playwright": "^2.1.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "0.4.14",
Expand All @@ -77,6 +78,7 @@
"@commitlint/config-conventional": "19.6.0",
"@eslint/config-inspector": "0.5.6",
"@jimmy.codes/prettier-config": "1.3.0",
"@playwright/test": "1.49.0",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/commit-analyzer": "13.0.0",
"@semantic-release/git": "10.0.1",
Expand Down
66 changes: 66 additions & 0 deletions pnpm-lock.yaml

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

18 changes: 18 additions & 0 deletions src/configs/playwright.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { GLOB_PLAYWRIGHT } from "../constants";
import { playwrightRules } from "../rules/playwright";
import { interopDefault } from "../utils/interop-default";

export const playwrightConfig = async () => {
const playwrightPlugin = await interopDefault(
import("eslint-plugin-playwright"),
);

return [
{
...playwrightPlugin.configs["flat/recommended"],
files: GLOB_PLAYWRIGHT,
name: "jimmy.codes/playwright",
rules: await playwrightRules(),
},
];
};
6 changes: 5 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ export const GLOB_TESTS = [
`**/*.benchmark.${GLOB_SRC_EXT}`,
];

export const GLOB_E2E = [
export const GLOB_PLAYWRIGHT = [
`**/e2e/**/*.spec.${GLOB_SRC_EXT}`,
`**/e2e/**/*.test.${GLOB_SRC_EXT}`,
];

export const GLOB_E2E = [
...GLOB_PLAYWRIGHT,
`**/cypress/**/*.spec.${GLOB_SRC_EXT}`,
`**/cypress/**/*.test.${GLOB_SRC_EXT}`,
];
Expand Down
53 changes: 29 additions & 24 deletions src/factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ describe("jimmyDotCodes", () => {
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/jest" }),
expect.objectContaining({ name: "jimmy.codes/react" }),
expect.objectContaining({
name: "jimmy.codes/testing-library",
}),
expect.objectContaining({ name: "jimmy.codes/testing-library" }),
]),
);
});
Expand All @@ -111,9 +109,7 @@ describe("jimmyDotCodes", () => {
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/vitest" }),
expect.objectContaining({ name: "jimmy.codes/react" }),
expect.objectContaining({
name: "jimmy.codes/testing-library",
}),
expect.objectContaining({ name: "jimmy.codes/testing-library" }),
]),
);
});
Expand All @@ -136,6 +132,16 @@ describe("jimmyDotCodes", () => {
);
});

it("should create configuration w/ playwright", async () => {
await expect(
jimmyDotCodes({ autoDetect: false, playwright: true }),
).resolves.toStrictEqual(
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/playwright" }),
]),
);
});

describe("autoDetect", () => {
it("should include typescript when auto detection is enabled", async () => {
vi.mocked(isPackageExists).mockImplementation((name) => {
Expand All @@ -145,14 +151,11 @@ describe("jimmyDotCodes", () => {
await expect(jimmyDotCodes({ autoDetect: true })).resolves.toStrictEqual(
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/typescript" }),
expect.not.objectContaining({ name: "jimmy.codes/testing" }),
expect.not.objectContaining({ name: "jimmy.codes/vitest" }),
expect.not.objectContaining({ name: "jimmy.codes/jest" }),
expect.not.objectContaining({ name: "jimmy.codes/react" }),
expect.not.objectContaining({ name: "jimmy.codes/react/query" }),
expect.not.objectContaining({
name: "jimmy.codes/testing-library",
}),
expect.not.objectContaining({ name: "jimmy.codes/testing-library" }),
]),
);
});
Expand All @@ -165,14 +168,11 @@ describe("jimmyDotCodes", () => {
await expect(jimmyDotCodes({ autoDetect: true })).resolves.toStrictEqual(
expect.arrayContaining([
expect.not.objectContaining({ name: "jimmy.codes/typescript" }),
expect.not.objectContaining({ name: "jimmy.codes/testing" }),
expect.not.objectContaining({ name: "jimmy.codes/vitest" }),
expect.not.objectContaining({ name: "jimmy.codes/jest" }),
expect.objectContaining({ name: "jimmy.codes/react" }),
expect.not.objectContaining({ name: "jimmy.codes/react/query" }),
expect.not.objectContaining({
name: "jimmy.codes/testing-library",
}),
expect.not.objectContaining({ name: "jimmy.codes/testing-library" }),
]),
);
});
Expand All @@ -186,14 +186,11 @@ describe("jimmyDotCodes", () => {
await expect(jimmyDotCodes({ autoDetect: true })).resolves.toStrictEqual(
expect.arrayContaining([
expect.not.objectContaining({ name: "jimmy.codes/typescript" }),
expect.not.objectContaining({ name: "jimmy.codes/testing" }),
expect.not.objectContaining({ name: "jimmy.codes/vitest" }),
expect.not.objectContaining({ name: "jimmy.codes/jest" }),
expect.objectContaining({ name: "jimmy.codes/react" }),
expect.objectContaining({ name: "jimmy.codes/react/query" }),
expect.not.objectContaining({
name: "jimmy.codes/testing-library",
}),
expect.not.objectContaining({ name: "jimmy.codes/testing-library" }),
]),
);
});
Expand All @@ -211,9 +208,7 @@ describe("jimmyDotCodes", () => {
expect.not.objectContaining({ name: "jimmy.codes/jest" }),
expect.not.objectContaining({ name: "jimmy.codes/react" }),
expect.not.objectContaining({ name: "jimmy.codes/react/query" }),
expect.not.objectContaining({
name: "jimmy.codes/testing-library",
}),
expect.not.objectContaining({ name: "jimmy.codes/testing-library" }),
]),
);
});
Expand All @@ -231,9 +226,7 @@ describe("jimmyDotCodes", () => {
expect.objectContaining({ name: "jimmy.codes/jest" }),
expect.not.objectContaining({ name: "jimmy.codes/react" }),
expect.not.objectContaining({ name: "jimmy.codes/react/query" }),
expect.not.objectContaining({
name: "jimmy.codes/testing-library",
}),
expect.not.objectContaining({ name: "jimmy.codes/testing-library" }),
]),
);
});
Expand Down Expand Up @@ -278,5 +271,17 @@ describe("jimmyDotCodes", () => {
]),
);
});

it("should include playwright when auto detection is enabled", async () => {
vi.mocked(isPackageExists).mockImplementation((name) => {
return name === "@playwright/test";
});

await expect(jimmyDotCodes({ autoDetect: true })).resolves.toStrictEqual(
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/playwright" }),
]),
);
});
});
});
5 changes: 5 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { importsConfig } from "./configs/imports";
import { javascriptConfig } from "./configs/javascript";
import { nodeConfig } from "./configs/node";
import { perfectionistConfig } from "./configs/perfectionist";
import { playwrightConfig } from "./configs/playwright";
import { prettierConfig } from "./configs/prettier";
import { reactConfig } from "./configs/react";
import { regexpConfig } from "./configs/regexp";
Expand All @@ -25,6 +26,7 @@ import {
} from "./utils/get-options";
import {
hasAstro,
hasPlaywright,
hasReact,
hasTesting,
hasTypescript,
Expand All @@ -40,6 +42,7 @@ export const jimmyDotCodes = async (
autoDetect = true,
configs = [],
ignores = [],
playwright = false,
react = false,
testing = false,
typescript = false,
Expand All @@ -62,6 +65,7 @@ export const jimmyDotCodes = async (
testingOptions,
autoDetect,
);
const isPlaywrightEnabled = playwright || (autoDetect && hasPlaywright());

return [
javascriptConfig(),
Expand All @@ -77,6 +81,7 @@ export const jimmyDotCodes = async (
isAstroEnabled ? await astroConfig() : [],
isTestingEnabled ? await testingConfig(testingOptions, autoDetect) : [],
isTestingLibraryEnabled ? await testingLibrary() : [],
isPlaywrightEnabled ? await playwrightConfig() : [],
prettierConfig(),
commonjsConfig(),
ignoresConfig(ignores),
Expand Down
Loading