Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate string literal types for configs #740

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/grumpy-waves-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-regexp": minor
---

Improved compatibility of type information with typescript-eslint in config.
3 changes: 2 additions & 1 deletion lib/configs/rules/all.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { rules as ruleLint } from "../../all-rules"
import type { SeverityString } from "../../types"
import { rules as recommendedRules } from "./recommended"

const all: Record<string, string> = {}
const all: Record<string, SeverityString> = {}
for (const rule of ruleLint) {
all[rule.meta.docs.ruleId] = "error"
}
Expand Down
4 changes: 3 additions & 1 deletion lib/configs/rules/recommended.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const rules = {
import type { SeverityString } from "../../types"

export const rules: Record<string, SeverityString> = {
// ESLint core rules
"no-control-regex": "error",
"no-misleading-character-class": "error",
Expand Down
6 changes: 4 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export type RuleCategory =
| "Best Practices"
| "Stylistic Issues"

export type SeverityString = "error" | "warn" | "off"

export interface RuleMetaData {
docs: {
description: string
Expand All @@ -21,7 +23,7 @@ export interface RuleMetaData {
url: string
ruleId: string
ruleName: string
default?: "error" | "warn"
default?: Exclude<SeverityString, "off">
}
messages: { [messageId: string]: string }
fixable?: "code" | "whitespace"
Expand All @@ -42,7 +44,7 @@ export interface PartialRuleMetaData {
description: string
category: RuleCategory
recommended: boolean
default?: "error" | "warn"
default?: Exclude<SeverityString, "off">
}
messages: { [messageId: string]: string }
fixable?: "code" | "whitespace"
Expand Down
4 changes: 3 additions & 1 deletion tools/update-rulesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const coreRules = [
// "require-unicode-regexp", // modern
]

const content = `export const rules = {
const content = `import type { SeverityString } from "../../types"

export const rules: Record<string, SeverityString> = {
// ESLint core rules
${coreRules.map((ruleName) => `"${ruleName}": "error"`).join(",\n ")},
// The ESLint rule will report fewer cases than our rule
Expand Down
Loading