Skip to content

Commit 1e18906

Browse files
committedMay 13, 2024·
feat: add regexp plugin and enable by default
1 parent 159faf1 commit 1e18906

File tree

8 files changed

+102
-2
lines changed

8 files changed

+102
-2
lines changed
 

‎eslint.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// @ts-expect-error missing types
2-
// @eslint-ts-patch-loader tsx
32
import styleMigrate from '@stylistic/eslint-plugin-migrate'
43
import { antfu } from './src'
54

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"eslint-plugin-n": "^17.6.0",
111111
"eslint-plugin-no-only-tests": "^3.1.0",
112112
"eslint-plugin-perfectionist": "^2.10.0",
113+
"eslint-plugin-regexp": "^2.5.0",
113114
"eslint-plugin-toml": "^0.11.0",
114115
"eslint-plugin-unicorn": "^52.0.0",
115116
"eslint-plugin-unused-imports": "^3.2.0",

‎pnpm-lock.yaml

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/typegen.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'node:fs/promises'
22
import { flatConfigsToRulesDTS } from 'eslint-typegen/core'
33
import { builtinRules } from 'eslint/use-at-your-own-risk'
4-
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'
4+
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'
55

66
const configs = await combine(
77
{
@@ -28,6 +28,7 @@ const configs = await combine(
2828
svelte(),
2929
test(),
3030
toml(),
31+
regexp(),
3132
typescript(),
3233
unicorn(),
3334
unocss(),

‎src/configs/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export * from './unicorn'
2222
export * from './unocss'
2323
export * from './vue'
2424
export * from './yaml'
25+
export * from './regexp'

‎src/configs/regexp.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { configs } from 'eslint-plugin-regexp'
2+
import type { OptionsOverrides, OptionsRegExp, TypedFlatConfigItem } from '../types'
3+
4+
export async function regexp(
5+
options: OptionsRegExp & OptionsOverrides = {},
6+
): Promise<TypedFlatConfigItem[]> {
7+
const config = configs['flat/recommended'] as TypedFlatConfigItem
8+
9+
const rules = {
10+
...config.rules,
11+
}
12+
13+
if (options.level === 'warn') {
14+
for (const key in rules) {
15+
if (rules[key] === 'error')
16+
rules[key] = 'warn'
17+
}
18+
}
19+
20+
return [
21+
{
22+
...config,
23+
name: 'antfu/regexp/rules',
24+
rules: {
25+
...rules,
26+
...options.overrides,
27+
},
28+
},
29+
]
30+
}

‎src/factory.ts

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from './configs'
3333
import { interopDefault } from './utils'
3434
import { formatters } from './configs/formatters'
35+
import { regexp } from './configs/regexp'
3536

3637
const flatConfigProps: (keyof TypedFlatConfigItem)[] = [
3738
'name',
@@ -87,6 +88,7 @@ export function antfu(
8788
gitignore: enableGitignore = true,
8889
isInEditor = !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM) && !process.env.CI),
8990
react: enableReact = false,
91+
regexp: enableRegexp = true,
9092
solid: enableSolid = false,
9193
svelte: enableSvelte = false,
9294
typescript: enableTypeScript = isPackageExists('typescript'),
@@ -156,6 +158,9 @@ export function antfu(
156158
}))
157159
}
158160

161+
if (enableRegexp)
162+
configs.push(regexp(typeof enableRegexp === 'boolean' ? {} : enableRegexp))
163+
159164
if (options.test ?? true) {
160165
configs.push(test({
161166
isInEditor,

‎src/types.ts

+16
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ export interface OptionsOverrides {
156156
overrides?: TypedFlatConfigItem['rules']
157157
}
158158

159+
export interface OptionsRegExp {
160+
/**
161+
* Override rulelevels
162+
*/
163+
level?: 'error' | 'warn'
164+
}
165+
159166
export interface OptionsIsInEditor {
160167
isInEditor?: boolean
161168
}
@@ -278,10 +285,19 @@ export interface OptionsConfig extends OptionsComponentExts {
278285
/**
279286
* Enable stylistic rules.
280287
*
288+
* @see https://eslint.style/
281289
* @default true
282290
*/
283291
stylistic?: boolean | (StylisticConfig & OptionsOverrides)
284292

293+
/**
294+
* Enable regexp rules.
295+
*
296+
* @see https://ota-meshi.github.io/eslint-plugin-regexp/
297+
* @default true
298+
*/
299+
regexp?: boolean | (OptionsRegExp & OptionsOverrides)
300+
285301
/**
286302
* Enable react rules.
287303
*

0 commit comments

Comments
 (0)
Please sign in to comment.