Skip to content

Commit

Permalink
feat: cypress config
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdehaven committed Jun 5, 2024
1 parent e42acd3 commit 07899f8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ The default config provides linting for files matching this pattern `**/*.{js,mj
- TypeScript recommended rules
- `eslint-plugin-vue`
- `eslint-plugin-promise`
- `eslint-plugin-cypress`
- [ESLint Stylistic](https://eslint.style/) rules configured for our preferred formatting settings
- ...and more. See [`index.mjs`](./configs/index.mjs) to view the configuration.

Expand All @@ -68,6 +67,19 @@ import eslintKongUiConfigJson from '@kong/eslint-config-kong-ui/json'
> [!Note]
> You will likely only want to apply the JSON config to a subset of file patterns in your project. See the section on [applying a config to a subset of files](#apply-a-config-to-a-subset-of-files) for detailed instructions.
#### Cypress config

The Cypress config provides linting for Cypress test files, given a pattern for `files` that your **host project provides**, and includes rules and preferred formatting settings configured via `eslint-plugin-cypress`, as well as the ESLint and TypeScript ESLint recommended settings. See [`cypress.mjs`](./configs/cypress.mjs) to view the configuration.

The Cypress config can be imported as shown here:

```javascript
import eslintKongUiConfigCypress from '@kong/eslint-config-kong-ui/cypress'
```

> [!Note]
> You will likely only want to apply the Cypress config to a subset of file patterns in your project. See the section on [applying a config to a subset of files](#apply-a-config-to-a-subset-of-files) for detailed instructions.
### Setup

To use the shared config, import the package inside of an `eslint.config.mjs` file and add it into the exported array, like this:
Expand Down Expand Up @@ -110,6 +122,7 @@ For example, you may only want to apply the [JSON config](#json-config) to `**/l
// eslint.config.mjs
import eslintKongUiConfig from '@kong/eslint-config-kong-ui'
import eslintKongUiConfigJson from '@kong/eslint-config-kong-ui/json'
import eslintKongUiConfigCypress from '@kong/eslint-config-kong-ui/cypress'

export default [
// Use the main config for all other files
Expand All @@ -119,6 +132,16 @@ export default [
...config,
files: ['**/locales/**/*.json']
})),
// Only apply the shared Cypress config to files that match the given pattern
...eslintKongUiConfigCypress.map(config => ({
...config,
files: [
'**/*.cy.ts',
'**/cypress/**',
'cypress/integration/**.spec.{js,ts,jsx,tsx}',
'cypress/integration/**.cy.{js,ts,jsx,tsx}',
]
})),
// your modifications
{
rules: {
Expand Down
24 changes: 24 additions & 0 deletions configs/cypress.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'

// Compatibility utils
import { FlatCompat } from '@eslint/eslintrc'
const compat = new FlatCompat()

export default [
eslint.configs.recommended,
...tseslint.configs.recommended,
...compat.config({
extends: ['plugin:cypress/recommended'],
}),
{
...compat.config({
extends: ['plugin:cypress/recommended'],
}),
rules: {
'promise/always-return': 'off',
'promise/catch-or-return': 'off',
'promise/no-nesting': 'off',
},
},
]
23 changes: 0 additions & 23 deletions configs/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export default [
extends: ['plugin:promise/recommended'],
}),
),
...compat.config({
extends: ['plugin:cypress/recommended'],
}),
// Global ignores
{
ignores: [
Expand Down Expand Up @@ -136,24 +133,4 @@ export default [
],
},
},
{
files: [
'**/*.cy.ts',
'**/cypress/**',
],
rules: {
'promise/always-return': 'off',
'promise/catch-or-return': 'off',
'promise/no-nesting': 'off',
},
},
{
files: [
'cypress/integration/**.spec.{js,ts,jsx,tsx}',
'cypress/integration/**.cy.{js,ts,jsx,tsx}',
],
...compat.config({
extends: ['plugin:cypress/recommended'],
}),
},
]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
".": "./configs/index.mjs",
"./default": "./configs/index.mjs",
"./json": "./configs/json.mjs",
"./cypress": "./configs/cypress.mjs",
"./package.json": "./package.json",
"./dist/*": "./dist/*"
},
Expand Down

0 comments on commit 07899f8

Please sign in to comment.