name: new-rule
description: Scaffold the test structure, descriptor, and docs for a new rule (TDD — tests before analyzer). Use when adding a new diagnostic rule.
disable-model-invocation: true
user-invocable: true
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
argument-hint: [RuleId] [RuleTitle]
hooks:
Stop:
- command: "bash .claude/hooks/log-skill-usage.sh new-rule"
Scaffold a New Rule (TDD)
Arguments: $ARGUMENTS
Example: /new-rule {RuleId} "Large struct passed by value"
Validation
Parse $1 as the rule ID and everything after as the title
Verify the rule ID matches the prefix defined in CLAUDE.md followed by a numeric ID — reject otherwise
Verify no existing descriptor matches id: "$1" in src/Spire.Analyzers/Descriptors.cs — abort if duplicate
Scaffolding (TDD order — tests and descriptor BEFORE analyzer)
Add descriptor to src/Spire.Analyzers/Descriptors.cs
Field name: {RuleId}_{TitlePascalCase}
Add in sequential order
Create test folder: tests/Spire.Analyzers.Tests/{RuleId}/
Create test case folder: tests/Spire.Analyzers.Tests/{RuleId}/cases/
Use global using directives (not plain using) — they apply to all case files since _shared.cs is a separate syntax tree in the same compilation
Always include: global using System;, global using System.Collections.Generic;, global using System.Threading.Tasks;, global using Spire.Analyzers;
Add rule-specific global using directives as needed (e.g., global using System.Buffers;)
Include shared type definitions relevant to the rule
Create test runner from template: tests/Spire.Analyzers.Tests/{RuleId}/{RuleId}Tests.cs
Replace {{RULE_ID}}, {{ANALYZER_TYPE}}
Inherits AnalyzerTestBase<TAnalyzer> — cases discovered at runtime, no [InlineData] needed
Create docs: docs/rules/{RuleId}.md
Replace {{RULE_ID}}, {{RULE_TITLE}}
Follow docs/style-guide.md for documentation style
Verify
Run dotnet build — must succeed with zero warnings
Report all created files
What this skill does NOT do
Does NOT create the analyzer file — that is the implementer's job, after tests are written
Does NOT create test case files — the lead writes those based on the rule plan's spec tables
Only scaffolds the structure so the lead can immediately start writing test cases
Constraints
Do NOT implement detection logic — the analyzer file is not created at this stage
Do NOT modify existing analyzer files or descriptors (only append the new descriptor)
Do NOT proceed if validation fails — report the error and stop
1---2name: new-rule3description: Arguments: $ARGUMENTS4---56---
7name: new-rule
8description: Scaffold the test structure, descriptor, and docs for a new rule (TDD — tests before analyzer). Use when adding a new diagnostic rule.
9disable-model-invocation: true
10user-invocable: true
11allowed-tools: Read, Write, Edit, Glob, Grep, Bash
12argument-hint: [RuleId] [RuleTitle]
13hooks:
14 Stop:
15 - command: "bash .claude/hooks/log-skill-usage.sh new-rule"
16---
1718# Scaffold a New Rule (TDD)
1920Arguments: `$ARGUMENTS`
21Example: `/new-rule {RuleId} "Large struct passed by value"`
2223## Validation
24251. Parse `$1` as the rule ID and everything after as the title
262. Verify the rule ID matches the prefix defined in CLAUDE.md followed by a numeric ID — reject otherwise
273. Verify no existing descriptor matches `id: "$1"` in `src/Spire.Analyzers/Descriptors.cs` — abort if duplicate
2829## Scaffolding (TDD order — tests and descriptor BEFORE analyzer)
30314. Add descriptor to `src/Spire.Analyzers/Descriptors.cs`
32 - Field name: `{RuleId}_{TitlePascalCase}`
33 - Add in sequential order
345. Create test folder: `tests/Spire.Analyzers.Tests/{RuleId}/`
356. Create test case folder: `tests/Spire.Analyzers.Tests/{RuleId}/cases/`
367. Create shared preamble: `tests/Spire.Analyzers.Tests/{RuleId}/cases/_shared.cs`
37 - Use `global using` directives (not plain `using`) — they apply to all case files since `_shared.cs` is a separate syntax tree in the same compilation
38 - Always include: `global using System;`, `global using System.Collections.Generic;`, `global using System.Threading.Tasks;`, `global using Spire.Analyzers;`
39 - Add rule-specific `global using` directives as needed (e.g., `global using System.Buffers;`)
40 - Include shared type definitions relevant to the rule
418. Create test runner from template: `tests/Spire.Analyzers.Tests/{RuleId}/{RuleId}Tests.cs`
42 - Replace `{{RULE_ID}}`, `{{ANALYZER_TYPE}}`
43 - Inherits `AnalyzerTestBase<TAnalyzer>` — cases discovered at runtime, no `[InlineData]` needed
449. Create docs: `docs/rules/{RuleId}.md`
45 - Replace `{{RULE_ID}}`, `{{RULE_TITLE}}`
46 - Follow `docs/style-guide.md` for documentation style
4748## Verify
495010. Run `dotnet build` — must succeed with zero warnings
5111. Report all created files
5253## What this skill does NOT do
5455- **Does NOT create the analyzer file** — that is the implementer's job, after tests are written
56- **Does NOT create test case files** — the lead writes those based on the rule plan's spec tables
57- Only scaffolds the structure so the lead can immediately start writing test cases
5859## Constraints
6061- Do NOT implement detection logic — the analyzer file is not created at this stage
62- Do NOT modify existing analyzer files or descriptors (only append the new descriptor)
63- Do NOT proceed if validation fails — report the error and stop
Run npx skillmds add majiayu000/new-rule in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Arguments: $ARGUMENTS It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
majiayu000 (@majiayu000) published this skill. Their other Agent Skills are listed on their SkillMD profile.