Skip to content

Commit

Permalink
Generate string literal types for configs (#740)
Browse files Browse the repository at this point in the history
* Generate string literal types for configs

* Add and share SeverityString type

* Create grumpy-waves-warn.md

---------

Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
  • Loading branch information
karlhorky and ota-meshi committed May 21, 2024
1 parent 7cb329d commit 9f1bd50
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
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

0 comments on commit 9f1bd50

Please sign in to comment.