Skip to content

Commit ae322d6

Browse files
committed
Update severity and folder pattern, add formatting rules for Playwright
1 parent 49318be commit ae322d6

File tree

7 files changed

+50
-18
lines changed

7 files changed

+50
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ All peer dependencies used by `@code-pushup/eslint-config` are listed below, alo
9090
| ![jest](./docs/icons/material/jest.png) | [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest) | `^28.8.0` | |
9191
| ![test](./docs/icons/icons8/test.png) | [eslint-plugin-jest-formatting](https://www.npmjs.com/package/eslint-plugin-jest-formatting) | `^3.0.0` | |
9292
| ![nodejs](./docs/icons/material/nodejs.png) | [eslint-plugin-n](https://www.npmjs.com/package/eslint-plugin-n) | `>=17.0.0` | |
93-
| ![playwright](./docs/icons/material/playwright.png) | [eslint-plugin-playwright](https://www.npmjs.com/package/eslint-plugin-playwright) | `>=2.1.0` | |
93+
| ![playwright](./docs/icons/material/playwright.png) | [eslint-plugin-playwright](https://www.npmjs.com/package/eslint-plugin-playwright) | `^2.1.0` | |
9494
| ![rxjs](./docs/icons/other/rxjs.png) | [eslint-plugin-rxjs-x](https://www.npmjs.com/package/eslint-plugin-rxjs-x) | `>=0.6.0` | |
9595
| ![storybook](./docs/icons/material/storybook.png) | [eslint-plugin-storybook](https://www.npmjs.com/package/eslint-plugin-storybook) | `>=0.10.0` | |
9696
| ![vitest](./docs/icons/material/vitest.png) | [eslint-plugin-vitest](https://www.npmjs.com/package/eslint-plugin-vitest) | `>=0.5.0` | |

docs/playwright.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Config for projects using **Playwright** for testing.
88
2. Since this plugin requires additional peer dependencies, you have to install them as well:
99

1010
```sh
11-
npm install -D eslint-plugin-playwright
11+
npm install -D eslint-plugin-{jest-formatting,playwright}
1212
```
1313

1414
3. Add to your `eslint.config.js` file:
@@ -20,29 +20,29 @@ Config for projects using **Playwright** for testing.
2020
export default tseslint.config(...playwright);
2121
```
2222

23-
## 📏 Rules (38)
23+
## 📏 Rules (40)
2424

2525
> 🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).<br>💡 Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
2626
27-
### 🚨 Errors (10)
27+
### 🚨 Errors (8)
2828

2929
| Plugin | Rule | Options | Autofix | Overrides |
3030
| :-----------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ | :-----: | :-------: |
3131
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [missing-playwright-await](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/missing-playwright-await.md)<br />Identify false positives when async Playwright APIs are not properly awaited. | | 🔧 | |
32-
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-focused-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-focused-test.md)<br />Prevent usage of `.only()` focus test annotation | | 💡 | |
3332
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-networkidle](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-networkidle.md)<br />Prevent usage of the networkidle option | | | |
34-
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-standalone-expect](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-standalone-expect.md)<br />Disallow using `expect` outside of `test` blocks | | 🔧 | |
3533
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-unsafe-references](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-unsafe-references.md)<br />Prevent unsafe variable references in page.evaluate() | | 🔧 | |
3634
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [prefer-web-first-assertions](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-web-first-assertions.md)<br />Prefer web first assertions | | 🔧 | |
3735
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [valid-describe-callback](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/valid-describe-callback.md)<br />Enforce valid `describe()` callback | | | |
3836
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [valid-expect](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/valid-expect.md)<br />Enforce valid `expect()` usage | | | |
3937
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [valid-expect-in-promise](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/valid-expect-in-promise.md)<br />Require promises that have expectations in their chain to be valid | | | |
4038
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [valid-title](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/valid-title.md)<br />Enforce valid titles | | 🔧 | |
4139

42-
### ⚠️ Warnings (28)
40+
### ⚠️ Warnings (32)
4341

4442
| Plugin | Rule | Options | Autofix | Overrides |
4543
| :-----------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ | :-----: | :-------: |
44+
| [![jest-formatting](./icons/icons8/test.png)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme) | padding-around-describe-blocks<br /> | | 🔧 | |
45+
| [![jest-formatting](./icons/icons8/test.png)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme) | padding-around-test-blocks<br /> | | 🔧 | |
4646
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [expect-expect](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/expect-expect.md)<br />Enforce assertion to be made in a test body | | | |
4747
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [max-nested-describe](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/max-nested-describe.md)<br />Enforces a maximum depth to nested describe calls | | | |
4848
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-commented-out-tests](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-commented-out-tests.md)<br />Disallow commented out tests | | | |
@@ -51,10 +51,12 @@ Config for projects using **Playwright** for testing.
5151
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-duplicate-hooks](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-duplicate-hooks.md)<br />Disallow duplicate setup and teardown hooks | | | |
5252
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-element-handle](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-element-handle.md)<br />The use of ElementHandle is discouraged, use Locator instead | | 💡 | |
5353
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-eval](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-eval.md)<br />The use of `page.$eval` and `page.$$eval` are discouraged, use `locator.evaluate` or `locator.evaluateAll` instead | | | |
54+
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-focused-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-focused-test.md)<br />Prevent usage of `.only()` focus test annotation | | 💡 | |
5455
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-force-option](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-force-option.md)<br />Prevent usage of `{ force: true }` option. | | | |
5556
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-nested-step](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-nested-step.md)<br />Disallow nested `test.step()` methods | | | |
5657
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-page-pause](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-page-pause.md)<br />Prevent usage of page.pause() | | | |
5758
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-skipped-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-skipped-test.md)<br />Prevent usage of the `.skip()` skip test annotation. | | 💡 | |
59+
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-standalone-expect](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-standalone-expect.md)<br />Disallow using `expect` outside of `test` blocks | | 🔧 | |
5860
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-useless-await](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-useless-await.md)<br />Disallow unnecessary awaits for Playwright methods | | 🔧 | |
5961
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-useless-not](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-useless-not.md)<br />Disallow usage of 'not' matchers when a more specific matcher exists | | 🔧 | |
6062
| [![playwright](./icons/material/playwright.png)](https://github.com/playwright-community/eslint-plugin-playwright#readme) | [no-wait-for-selector](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-wait-for-selector.md)<br />Prevent usage of page.waitForSelector() | | 💡 | |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"eslint-plugin-jest": "^28.8.0",
5151
"eslint-plugin-jest-formatting": "^3.0.0",
5252
"eslint-plugin-n": ">=17.0.0",
53-
"eslint-plugin-playwright": ">=2.1.0",
53+
"eslint-plugin-playwright": "^2.1.0",
5454
"eslint-plugin-promise": ">=6.4.0",
5555
"eslint-plugin-rxjs-x": ">=0.6.0",
5656
"eslint-plugin-sonarjs": "^1.0.4",

src/configs/playwright.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import * as jestFormatting from 'eslint-plugin-jest-formatting';
34
import playwright from 'eslint-plugin-playwright';
45
import tseslint from 'typescript-eslint';
56
import { PLAYWRIGHT_FILE_PATTERNS } from '../lib/patterns.js';
@@ -8,19 +9,30 @@ export default tseslint.config({
89
files: PLAYWRIGHT_FILE_PATTERNS,
910
extends: [
1011
playwright.configs['flat/recommended'],
12+
{
13+
name: 'code-pushup/playwright/jest-formatting',
14+
plugins: {
15+
'jest-formatting': jestFormatting,
16+
},
17+
rules: {
18+
'jest-formatting/padding-around-describe-blocks': 'warn',
19+
'jest-formatting/padding-around-test-blocks': 'warn',
20+
},
21+
},
1122
{
1223
name: 'code-pushup/playwright/customized',
1324
rules: {
1425
'playwright/no-conditional-expect': 'warn',
1526
'playwright/no-conditional-in-test': 'warn',
27+
'playwright/no-focused-test': 'warn',
28+
'playwright/no-standalone-expect': 'warn',
1629
},
1730
},
1831
{
1932
name: 'code-pushup/playwright/additional',
2033
rules: {
2134
'playwright/no-commented-out-tests': 'warn',
2235
'playwright/no-duplicate-hooks': 'warn',
23-
'playwright/no-focused-test': 'warn',
2436
'playwright/no-nested-step': 'warn',
2537
'playwright/prefer-comparison-matcher': 'warn',
2638
'playwright/prefer-equality-matcher': 'warn',

src/lib/patterns.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ export const HTML_FILE_PATTERNS = ['**/*.html'];
6969

7070
export const CYPRESS_FILE_PATTERNS = [
7171
'**/*.cy.[jt]s?(x)',
72-
'**/e2e/**/*.[jt]s?(x)',
72+
'**/?(*-)e2e/**/*.[jt]s?(x)',
7373
];
7474

7575
export const PLAYWRIGHT_FILE_PATTERNS = [
7676
'**/*.+(test|spec).[jt]s?(x)',
7777
'**/*.po.[jt]s?(x)',
78-
'**/e2e/**/*.[jt]s?(x)',
78+
'**/?(*-)e2e/**/*.[jt]s?(x)',
7979
];
8080

8181
export const NODE_FILE_PATTERNS = ['**/*.ts', '**/*.js'];

tests/configs/cypress.spec.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
// @ts-check
22

3-
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
3+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
44
import { createLintUtils } from '../helpers/lint-utils';
55

66
describe('cypress config', () => {
77
const { setup, teardown, loadConfig } = createLintUtils('cypress', '*.cy.js');
88

99
beforeAll(setup);
10+
1011
afterAll(teardown);
1112

12-
test('should not include Cypress rules for non-Cypress file', async () => {
13+
it('should not include Cypress rules for non-Cypress file', async () => {
1314
const config = await loadConfig('auth.spec.js');
1415
expect(Object.keys(config.rules ?? {}).join(',')).not.toContain('cypress/');
1516
});
1617

17-
test('should include cypress rules for Cypress file', async () => {
18-
const config = await loadConfig('e2e/login.cy.js');
18+
it('should include cypress rules for Cypress file', async () => {
19+
const config = await loadConfig('app/submit-form.cy.js');
20+
expect(Object.keys(config.rules ?? {}).join(',')).toContain('cypress/');
21+
});
22+
23+
it('should include cypress rules for Cypress folder', async () => {
24+
const config = await loadConfig('app-e2e/login.js');
1925
expect(Object.keys(config.rules ?? {}).join(',')).toContain('cypress/');
2026
});
2127

22-
test('should have rule from extended recommended cypress config', async () => {
28+
it('should have rule from extended recommended cypress config', async () => {
2329
const config = await loadConfig();
2430
expect(config.rules).toHaveProperty('cypress/no-unnecessary-waiting');
2531
});
2632

27-
test('should have explicitly added rule', async () => {
33+
it('should have explicitly added rule', async () => {
2834
const config = await loadConfig();
2935
expect(config.rules).toHaveProperty('cypress/no-force');
3036
});

tests/configs/playwright.spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ describe('playwright config', () => {
2525
expect(Object.keys(config.rules ?? {}).join(',')).toContain('playwright/');
2626
});
2727

28+
it('should include playwright rules for page object file', async () => {
29+
const config = await loadConfig('components/login.po.ts');
30+
expect(Object.keys(config.rules ?? {}).join(',')).toContain('playwright/');
31+
});
32+
2833
it('should include playwright rules for test folder', async () => {
29-
const config = await loadConfig('e2e/dashboard/subscription.ts');
34+
const config = await loadConfig('website-e2e/dashboard/subscription.ts');
3035
expect(Object.keys(config.rules ?? {}).join(',')).toContain('playwright/');
3136
});
3237

@@ -40,6 +45,13 @@ describe('playwright config', () => {
4045
expect(config.rules).toHaveProperty('playwright/prefer-native-locators');
4146
});
4247

48+
it('should include jest formatting rule', async () => {
49+
const config = await loadConfig();
50+
expect(Object.keys(config.rules ?? {}).join(',')).toContain(
51+
'jest-formatting/',
52+
);
53+
});
54+
4355
it('should have customized severity level for rule from extended config', async () => {
4456
const config = await loadConfig();
4557
expect(config.rules?.['playwright/no-conditional-expect']).toEqual([1]);

0 commit comments

Comments
 (0)