Skip to content

Commit 810f9d9

Browse files
committedJun 24, 2023
feat: added rules for playwright and storybook
Signed-off-by: prisis <d.bannert@anolilab.de>
1 parent 4ce4e51 commit 810f9d9

File tree

8 files changed

+149
-6
lines changed

8 files changed

+149
-6
lines changed
 

‎packages/eslint-config/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"eslint-plugin-react": "^7.32.2",
127127
"eslint-plugin-react-hooks": "^4.6.0",
128128
"eslint-plugin-react-redux": "^4.0.0",
129+
"eslint-plugin-storybook": "^0.6.11",
129130
"eslint-plugin-tailwindcss": "^3.12.1",
130131
"eslint-plugin-testing-library": "^5.11.0",
131132
"eslint-plugin-vitest": "^0.2.6",
@@ -150,6 +151,7 @@
150151
"eslint-plugin-jest-async": "^1.0.3",
151152
"eslint-plugin-jest-dom": "^5.0.1",
152153
"eslint-plugin-jest-formatting": "^3.1.0",
154+
"eslint-plugin-playwright": "^0.15.1",
153155
"eslint-plugin-jsdoc": "^46.2.6",
154156
"eslint-plugin-jsx-a11y": "^6.7.1",
155157
"eslint-plugin-n": "^16.0.0",
@@ -158,6 +160,7 @@
158160
"eslint-plugin-react": "^7.32.2",
159161
"eslint-plugin-react-hooks": "^4.6.0",
160162
"eslint-plugin-react-redux": "^4.0.0",
163+
"eslint-plugin-storybook": "^0.6.11",
161164
"eslint-plugin-tailwindcss": "^3.12.1",
162165
"eslint-plugin-testing-library": "^5.11.0",
163166
"eslint-plugin-tsdoc": "^0.2.17",

‎packages/eslint-config/src/config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ const pluginConfig: PackageRules = [
143143
configName: "ava",
144144
dependencies: ["ava", "eslint-plugin-ava"],
145145
},
146+
{
147+
configName: "storybook",
148+
dependencies: ["storybook", "eslint-plugin-storybook"],
149+
},
150+
{
151+
configName: "playwright",
152+
dependencies: ["playwright", "eslint-plugin-playwright"],
153+
},
146154
];
147155

148156
const loadedPlugins: string[] = [...internalPluginConfig];

‎packages/eslint-config/src/config/es6.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,33 @@ const config: Linter.Config = {
9090
// disallow specific imports
9191
// https://eslint.org/docs/rules/no-restricted-imports
9292
"no-restricted-imports": [
93-
"off",
93+
"error",
9494
{
95-
paths: [],
96-
patterns: [],
95+
paths: [
96+
{
97+
name: "lodash.isequal",
98+
message:
99+
"Lodash modularised (and lodash < 4.17.11) have CVE vulnerabilities. Please use tree-shakeable imports like lodash/xxx instead",
100+
},
101+
{
102+
name: "lodash.uniqueId",
103+
message:
104+
"Lodash modularised (and lodash < 4.17.11) have CVE vulnerabilities. Please use tree-shakeable imports like lodash/xxx instead",
105+
},
106+
{
107+
name: "lodash.mergewith",
108+
message:
109+
"Lodash modularised (and lodash < 4.17.11) have CVE vulnerabilities. Please use tree-shakeable imports like lodash/xxx instead",
110+
},
111+
{
112+
name: "lodash.pick",
113+
message:
114+
"Lodash modularised (and lodash < 4.17.11) have CVE vulnerabilities. Please use tree-shakeable imports like lodash/xxx instead",
115+
},
116+
],
117+
// catch-all for any lodash modularized.
118+
// The CVE is listed against the entire family for lodash < 4.17.11
119+
patterns: ["lodash.*"],
97120
},
98121
],
99122

‎packages/eslint-config/src/config/plugins/jsx-a11y.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
import { hasDependency, hasDevDependency } from "@anolilab/package-json-utils";
12
import type { Linter } from "eslint";
23

4+
let hasStorybook = false;
5+
6+
if (hasDevDependency("storybook") || hasDependency("storybook")) {
7+
hasStorybook = true;
8+
}
9+
310
const config: Linter.Config = {
411
plugins: ["jsx-a11y", "react"],
512

@@ -234,9 +241,9 @@ const config: Linter.Config = {
234241
"jsx-a11y/anchor-is-valid": [
235242
"error",
236243
{
237-
components: ["Link"],
244+
components: ["A", "LinkTo", "Link"],
238245
specialLink: ["to"],
239-
aspects: ["noHref", "invalidHref", "preferButton"],
246+
aspects: ["noHref", "invalidHref", "preferButton", ...(hasStorybook ? ["overrideParams", "kind", "story", "to"] : [])],
240247
},
241248
],
242249

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { hasDependency, hasDevDependency } from "@anolilab/package-json-utils";
2+
import type { Linter } from "eslint";
3+
4+
let hasJest = false;
5+
6+
if (hasDependency("jest") || hasDevDependency("jest") || hasDevDependency("eslint-plugin-jest") || hasDevDependency("@types/jest")) {
7+
hasJest = true;
8+
}
9+
10+
// @see https://github.com/playwright-community/eslint-plugin-playwright
11+
const config: Linter.Config = {
12+
env: {
13+
browser: true,
14+
es6: true,
15+
node: true,
16+
},
17+
overrides: [
18+
{
19+
// To ensure best performance enable only on e2e test files
20+
files: ["**/e2e/**/*.test.{js,ts}"],
21+
extends: [hasJest ? "plugin:playwright/jest-playwright" : "plugin:playwright/recommended"],
22+
rules: {
23+
"@typescript-eslint/no-non-null-assertion": "off",
24+
"@typescript-eslint/no-object-literal-type-assertion": "off",
25+
"@typescript-eslint/no-empty-function": "off",
26+
},
27+
},
28+
],
29+
};
30+
31+
export default config;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { Linter } from "eslint";
2+
3+
// @see https://github.com/storybookjs/eslint-plugin-storybook
4+
const config: Linter.Config = {
5+
env: {
6+
browser: true,
7+
es6: true,
8+
node: true,
9+
},
10+
overrides: [
11+
{
12+
// For performance run storybook/recommended on test files, not regular code
13+
files: ["**/*.stories.{ts,tsx,mdx}"],
14+
extends: ["plugin:storybook/recommended"],
15+
},
16+
],
17+
};
18+
19+
export default config;

‎packages/eslint-config/src/config/style.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ const config: Linter.Config = {
463463
"no-underscore-dangle": [
464464
"error",
465465
{
466-
allow: ["__DEV__"],
466+
allow: ["__DEV__", "__STORYBOOK_CLIENT_API__", "__STORYBOOK_ADDONS_CHANNEL__", "__STORYBOOK_STORY_STORE__"],
467467
allowAfterThis: false,
468468
allowAfterSuper: false,
469469
enforceInMethodNames: true,

‎pnpm-lock.yaml

+52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.