Skip to content

Commit

Permalink
Support flat config (#169)
Browse files Browse the repository at this point in the history
* feat: Support flat config

* chore: Update examples to flat config

* chore: Update docs

* chore: Fix docs
  • Loading branch information
mskelton committed Oct 15, 2023
1 parent a62b551 commit 01bd627
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 115 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ This plugin bundles two configurations to work with both `@playwright/test` or

### With [Playwright test runner](https://playwright.dev/docs/writing-tests)

[Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new)
(**eslint.config.js**)

```javascript
import playwright from 'eslint-plugin-playwright';

export default [
playwright.configs['flat/recommended'],
{
rules: {
// Customize Playwright rules
// ...
},
},
];
```

[Legacy config](https://eslint.org/docs/latest/use/configure/configuration-files)
(**.eslintrc**)

```json
{
"extends": ["plugin:playwright/recommended"]
Expand All @@ -41,6 +61,30 @@ This plugin bundles two configurations to work with both `@playwright/test` or

### With [Jest Playwright](https://github.com/playwright-community/jest-playwright)

[Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new)
(**eslint.config.js**)

```javascript
import playwright from 'eslint-plugin-playwright';
import jest from 'eslint-plugin-jest';

export default [
playwright.configs['flat/jest-playwright'],
{
plugins: {
jest,
},
rules: {
// Customize Playwright rules
// ...
},
},
];
```

[Legacy config](https://eslint.org/docs/latest/use/configure/configuration-files)
(**.eslintrc**)

```json
{
"extends": ["plugin:playwright/jest-playwright"]
Expand All @@ -63,6 +107,24 @@ under the `playwright` key. It supports the following settings:

You can configure these settings like so:

[Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new)
(**eslint.config.js**)

```javascript
export default [
{
settings: {
playwright: {
additionalAssertFunctionNames: ['assertCustomCondition'],
},
},
},
];
```

[Legacy config](https://eslint.org/docs/latest/use/configure/configuration-files)
(**.eslintrc**)

```json
{
"settings": {
Expand Down
21 changes: 0 additions & 21 deletions examples/.eslintrc

This file was deleted.

25 changes: 25 additions & 0 deletions examples/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import playwright from 'eslint-plugin-playwright';

export default [
playwright.configs['flat/recommended'],
{
languageOptions: {
sourceType: 'module',
ecmaVersion: 2022,
},
rules: {
'playwright/prefer-lowercase-title': 'warn',
'playwright/prefer-to-be': 'warn',
'playwright/prefer-to-have-length': 'warn',
'playwright/prefer-strict-equal': 'warn',
'playwright/max-nested-describe': ['warn', { max: 1 }],
'playwright/no-restricted-matchers': [
'error',
{
toBeFalsy: 'Use `toBe(false)` instead.',
not: null,
},
],
},
},
];
4 changes: 2 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"@playwright/test": "^1.38.1",
"eslint": "^8.50.0",
"eslint-plugin-playwright": "workspace:*"
"eslint": "^8.51.0",
"eslint-plugin-playwright": "file:../"
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
"eslint-plugin-jest": {
"optional": true
}
},
"dependencies": {
"globals": "^13.23.0"
}
}
Loading

0 comments on commit 01bd627

Please sign in to comment.