Skip to content

Commit

Permalink
feat(config): add regexp rule set for toolings preset (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 17, 2024
1 parent e41dff8 commit 59f1761
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 7 deletions.
16 changes: 15 additions & 1 deletion docs/content/1.packages/1.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,21 @@ export default createConfigForNuxt({
})
```

This will enable rules with `unicorn` and `jsdoc` plugins, to ensure your module is following best practices.
This will enable rules with `unicorn`, `regexp` and `jsdoc` plugins, to ensure your module is following best practices.

You can also turn them off individually by providing an object with the rule names set to `false`:

```js [eslint.config.mjs]
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'

export default createConfigForNuxt({
features: {
tooling: {
regexp: false,
}
}
})
```

## Legacy Config Format

Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"eslint-config-flat-gitignore": "^0.1.5",
"eslint-flat-config-utils": "^0.2.4",
"eslint-flat-config-utils": "^0.2.5",
"eslint-plugin-import-x": "^0.5.0",
"eslint-plugin-jsdoc": "^48.2.5",
"eslint-plugin-regexp": "^2.5.0",
"eslint-plugin-unicorn": "^53.0.0",
"eslint-plugin-vue": "^9.26.0",
"globals": "^15.2.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/eslint-config/src/flat/configs-tooling/regexp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Linter } from 'eslint'
import { configs } from 'eslint-plugin-regexp'

export default function regexp(): Linter.FlatConfig[] {
return [
{
...configs['flat/recommended'] as Linter.FlatConfig,
name: 'nuxt/tooling/regexp',
},
]
}
6 changes: 4 additions & 2 deletions packages/eslint-config/src/flat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export function createConfigForNuxt(
)

if (resolved.features.tooling) {
const toolingOptions = typeof resolved.features.tooling === 'boolean' ? {} : resolved.features.tooling
c.append(
import('./configs-tooling/jsdoc').then(m => m.default(resolved)),
import('./configs-tooling/unicorn').then(m => m.default()),
toolingOptions.jsdoc !== false && import('./configs-tooling/jsdoc').then(m => m.default(resolved)),
toolingOptions.unicorn !== false && import('./configs-tooling/unicorn').then(m => m.default()),
toolingOptions.regexp !== false && import('./configs-tooling/regexp').then(m => m.default()),
)
}

Expand Down
25 changes: 24 additions & 1 deletion packages/eslint-config/src/flat/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
import type { StylisticCustomizeOptions } from '@stylistic/eslint-plugin'

export interface ToolingOptions {
/**
* Enable RegExp rules
*
* @see https://github.com/ota-meshi/eslint-plugin-regexp
* @default true
*/
regexp?: boolean
/**
* Enable Unicorn rules
*
* @see https://github.com/sindresorhus/eslint-plugin-unicorn
* @default true
*/
unicorn?: boolean
/**
* Enable jsdoc rules
*
* @default true
*/
jsdoc?: boolean
}

export interface NuxtESLintFeaturesOptions {
/**
* Setup basic JavaScript, TypeScript and Vue plugins and rules.
Expand All @@ -16,7 +39,7 @@ export interface NuxtESLintFeaturesOptions {
* @experimental Changes might not follow semver
* @default false
*/
tooling?: boolean
tooling?: boolean | ToolingOptions

/**
* Enable stylistic ESLint rules for formatting and code style check
Expand Down
59 changes: 57 additions & 2 deletions pnpm-lock.yaml

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

0 comments on commit 59f1761

Please sign in to comment.