Skip to content

Commit d4c63ee

Browse files
committed
feat: add eslint-plugin-regexp
1 parent d2dc0ee commit d4c63ee

File tree

7 files changed

+104
-0
lines changed

7 files changed

+104
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"eslint-plugin-no-only-tests": "^3.1.0",
9595
"eslint-plugin-perfectionist": "^2.10.0",
9696
"eslint-plugin-prettier": "^5.1.3",
97+
"eslint-plugin-regexp": "^2.5.0",
9798
"eslint-plugin-tailwindcss": "^3.15.1",
9899
"eslint-plugin-unicorn": "^53.0.0",
99100
"eslint-plugin-unused-imports": "^3.2.0",

pnpm-lock.yaml

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/typegen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
perfectionist,
1414
prettier,
1515
react,
16+
regexp,
1617
sortPackageJson,
1718
svelte,
1819
test,
@@ -49,6 +50,7 @@ const configs = await combine(
4950
unocss(),
5051
vue(),
5152
command(),
53+
regexp(),
5254
)
5355

5456
const configNames = configs.map(i => i.name).filter(Boolean) as string[]

src/configs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export * from './formatter'
1818
export * from './svelte'
1919
export * from './tailwindcss'
2020
export * from './command'
21+
export * from './regexp'

src/configs/regexp.ts

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

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
perfectionist,
1515
prettier,
1616
react,
17+
regexp,
1718
sortPackageJson,
1819
sortTsconfig,
1920
svelte,
@@ -87,6 +88,7 @@ export async function defineConfig(
8788
gitignore: enableGitignore = true,
8889
isInEditor = defaultIsInEditor,
8990
react: enableReact = false,
91+
regexp: enableRegexp = true,
9092
svelte: enableSvelte = false,
9193
tailwindcss: enableTailwindCSS = hasTailwindCSS,
9294
typescript: enableTypeScript = hasTypeScript,
@@ -144,6 +146,9 @@ export async function defineConfig(
144146
)
145147
}
146148

149+
if (enableRegexp)
150+
configs.push(regexp(typeof enableRegexp === 'boolean' ? {} : enableRegexp))
151+
147152
if (options.test ?? true) {
148153
configs.push(
149154
test({

src/types/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ export interface OptionsOverrides {
9595
overrides?: TypedFlatConfigItem['rules']
9696
}
9797

98+
export interface OptionsRegExp {
99+
/**
100+
* Override rulelevels
101+
*/
102+
level?: 'error' | 'warn'
103+
}
104+
98105
export interface OptionsUnoCSS extends OptionsOverrides {
99106
/**
100107
* Enable attributify support.
@@ -209,6 +216,14 @@ export interface OptionsConfig extends OptionsComponentExts {
209216
*/
210217
unocss?: boolean | OptionsUnoCSS
211218

219+
/**
220+
* Enable regexp rules.
221+
*
222+
* @see https://ota-meshi.github.io/eslint-plugin-regexp/
223+
* @default true
224+
*/
225+
regexp?: boolean | (OptionsRegExp & OptionsOverrides)
226+
212227
/**
213228
* Whether to use prettierrc
214229
*

0 commit comments

Comments
 (0)