-
Notifications
You must be signed in to change notification settings - Fork 0
fix: sync hardcoded rule values and add auto-sync tooling #112
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
740bcc4
fix: sync hardcoded rule values with rule-config.ts
let-sunny c58d68f
feat: auto-sync rule docs and add validation tests
let-sunny 724c9a0
fix: address CodeRabbit review feedback
let-sunny 2ab2e40
fix: address CodeRabbit round-2 review
let-sunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /** | ||
| * Auto-generate rule tables in docs/REFERENCE.md from rule-config.ts + rule registry. | ||
| * | ||
| * Usage: npx tsx scripts/sync-rule-docs.ts | ||
| * | ||
| * Replaces content between RULE_TABLE_START and RULE_TABLE_END markers in REFERENCE.md. | ||
| */ | ||
|
|
||
| // Import rules to populate registry | ||
| import "../src/core/rules/index.js"; | ||
| import { ruleRegistry } from "../src/core/rules/rule-registry.js"; | ||
| import { RULE_CONFIGS } from "../src/core/rules/rule-config.js"; | ||
| import { CATEGORIES } from "../src/core/contracts/category.js"; | ||
| import type { Category } from "../src/core/contracts/category.js"; | ||
| import type { RuleId } from "../src/core/contracts/rule.js"; | ||
| import { readFileSync, writeFileSync } from "node:fs"; | ||
| import { resolve, dirname } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const REFERENCE_PATH = resolve(__dirname, "../docs/REFERENCE.md"); | ||
| const START_MARKER = "<!-- RULE_TABLE_START"; | ||
| const END_MARKER = "<!-- RULE_TABLE_END -->"; | ||
|
|
||
| function generateTables(): string { | ||
| const lines: string[] = []; | ||
|
|
||
| for (const category of CATEGORIES) { | ||
| const rules = ruleRegistry | ||
| .getByCategory(category as Category) | ||
| .map((r) => { | ||
| const id = r.definition.id as RuleId; | ||
| const config = RULE_CONFIGS[id]; | ||
| if (!config) { | ||
| throw new Error(`Missing RULE_CONFIGS entry for rule "${id}"`); | ||
| } | ||
| return { id, config }; | ||
| }); | ||
|
|
||
| const label = category.charAt(0).toUpperCase() + category.slice(1); | ||
| lines.push(`**${label} (${rules.length} rules)**`); | ||
| lines.push(""); | ||
| lines.push("| Rule ID | Default Score | Default Severity |"); | ||
| lines.push("|---------|--------------|-----------------|"); | ||
|
|
||
| for (const { id, config } of rules) { | ||
| lines.push(`| \`${id}\` | ${config.score} | ${config.severity} |`); | ||
| } | ||
|
|
||
| lines.push(""); | ||
| } | ||
|
|
||
| // Remove trailing empty line | ||
| if (lines.at(-1) === "") lines.pop(); | ||
|
|
||
| return lines.join("\n"); | ||
| } | ||
|
|
||
| const content = readFileSync(REFERENCE_PATH, "utf-8"); | ||
| const startIdx = content.indexOf(START_MARKER); | ||
| const endIdx = content.indexOf(END_MARKER); | ||
|
|
||
| if (startIdx === -1 || endIdx === -1) { | ||
| console.error("RULE_TABLE markers not found in REFERENCE.md"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const before = content.slice(0, startIdx); | ||
| const after = content.slice(endIdx + END_MARKER.length); | ||
| const tables = generateTables(); | ||
|
|
||
| const updated = | ||
| before + | ||
| `${START_MARKER} — auto-generated by scripts/sync-rule-docs.ts, do not edit manually -->\n` + | ||
| tables + | ||
| "\n" + | ||
| END_MARKER + | ||
| after; | ||
|
|
||
| if (content === updated) { | ||
| console.log("docs/REFERENCE.md is already up to date."); | ||
| } else { | ||
| writeFileSync(REFERENCE_PATH, updated, "utf-8"); | ||
| console.log("docs/REFERENCE.md updated."); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fail fast when markers are misordered.
The current guard misses the
endIdx <= startIdxcase, which can corrupt the rewritten section.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents