Skip to content

Commit

Permalink
feat: add regexp plugin and enable by default
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 13, 2024
1 parent 159faf1 commit 1e18906
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
1 change: 0 additions & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-expect-error missing types
// @eslint-ts-patch-loader tsx
import styleMigrate from '@stylistic/eslint-plugin-migrate'
import { antfu } from './src'

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"eslint-plugin-n": "^17.6.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-perfectionist": "^2.10.0",
"eslint-plugin-regexp": "^2.5.0",
"eslint-plugin-toml": "^0.11.0",
"eslint-plugin-unicorn": "^52.0.0",
"eslint-plugin-unused-imports": "^3.2.0",
Expand Down
47 changes: 47 additions & 0 deletions pnpm-lock.yaml

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

3 changes: 2 additions & 1 deletion scripts/typegen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises'
import { flatConfigsToRulesDTS } from 'eslint-typegen/core'
import { builtinRules } from 'eslint/use-at-your-own-risk'
import { astro, combine, comments, formatters, imports, javascript, jsdoc, jsonc, markdown, node, perfectionist, react, solid, sortPackageJson, stylistic, svelte, test, toml, typescript, unicorn, unocss, vue, yaml } from '../src'
import { astro, combine, comments, formatters, imports, javascript, jsdoc, jsonc, markdown, node, perfectionist, react, regexp, solid, sortPackageJson, stylistic, svelte, test, toml, typescript, unicorn, unocss, vue, yaml } from '../src'

const configs = await combine(
{
Expand All @@ -28,6 +28,7 @@ const configs = await combine(
svelte(),
test(),
toml(),
regexp(),
typescript(),
unicorn(),
unocss(),
Expand Down
1 change: 1 addition & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './unicorn'
export * from './unocss'
export * from './vue'
export * from './yaml'
export * from './regexp'
30 changes: 30 additions & 0 deletions src/configs/regexp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { configs } from 'eslint-plugin-regexp'
import type { OptionsOverrides, OptionsRegExp, TypedFlatConfigItem } from '../types'

export async function regexp(
options: OptionsRegExp & OptionsOverrides = {},
): Promise<TypedFlatConfigItem[]> {
const config = configs['flat/recommended'] as TypedFlatConfigItem

const rules = {
...config.rules,
}

if (options.level === 'warn') {
for (const key in rules) {
if (rules[key] === 'error')
rules[key] = 'warn'
}
}

return [
{
...config,
name: 'antfu/regexp/rules',
rules: {
...rules,
...options.overrides,
},
},
]
}
5 changes: 5 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from './configs'
import { interopDefault } from './utils'
import { formatters } from './configs/formatters'
import { regexp } from './configs/regexp'

const flatConfigProps: (keyof TypedFlatConfigItem)[] = [
'name',
Expand Down Expand Up @@ -87,6 +88,7 @@ export function antfu(
gitignore: enableGitignore = true,
isInEditor = !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM) && !process.env.CI),
react: enableReact = false,
regexp: enableRegexp = true,
solid: enableSolid = false,
svelte: enableSvelte = false,
typescript: enableTypeScript = isPackageExists('typescript'),
Expand Down Expand Up @@ -156,6 +158,9 @@ export function antfu(
}))
}

if (enableRegexp)
configs.push(regexp(typeof enableRegexp === 'boolean' ? {} : enableRegexp))

if (options.test ?? true) {
configs.push(test({
isInEditor,
Expand Down
16 changes: 16 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ export interface OptionsOverrides {
overrides?: TypedFlatConfigItem['rules']
}

export interface OptionsRegExp {
/**
* Override rulelevels
*/
level?: 'error' | 'warn'
}

export interface OptionsIsInEditor {
isInEditor?: boolean
}
Expand Down Expand Up @@ -278,10 +285,19 @@ export interface OptionsConfig extends OptionsComponentExts {
/**
* Enable stylistic rules.
*
* @see https://eslint.style/
* @default true
*/
stylistic?: boolean | (StylisticConfig & OptionsOverrides)

/**
* Enable regexp rules.
*
* @see https://ota-meshi.github.io/eslint-plugin-regexp/
* @default true
*/
regexp?: boolean | (OptionsRegExp & OptionsOverrides)

/**
* Enable react rules.
*
Expand Down

0 comments on commit 1e18906

Please sign in to comment.