create-linter-rule
Skill27 starsChanged 2 years agoMITView on GitHub
Create a new TypeSpec linter rule, lint diagnostic, or design guideline checker with a TDD approach, including implementation, tests, documentation, ruleset registration, and changeset. Use this skill when asked to create, add, implement, or write a new linter rule, lint warning, validation rule, or design guideline enforcement for TypeSpec Azure libraries.
In this repository8 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- code-reviewSkill
- doc-example-generatorSkill
- hotfix-releaseSkill
- tcgc-newsletterSkill
- typespec-go-add-spector-testSkill
- typespec-python-releaseSkill
- typespec-ts-add-spector-testSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
38 rules. About 0 are common, 16 are distinctive, and 22 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
22
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Follow these steps in order to create a complete, high-quality linter rule.
- Distinctive: line 21
Rule name: Must follow these naming conventions:
- Distinctive: line 22
Use kebab-case (lowercase letters, numbers, hyphens)
- Distinctive: line 23
DO NOT include the package name in the rule ID (the package is already part of the fully-qualified diagnostic code)
- Very specific: line 24
Use no-<thing> when the rule bans a construct or usage (e.g., no-nullable, no-enum, no-format)
- Very specific: line 25
Use use-<preferred-thing> when the rule points users to a standard/preferred TypeSpec pattern (e.g., use-standard-operations, …
- Very specific: line 26
Keep names short and concise — prefer no-enum over no-enum-type-usage
- Distinctive: line 27
Severity: All linter rules are warnings.
- Very specific: line 56
Write tests for valid code that should produce no diagnostics (.toBeValid())
- Very specific: line 57
Write tests for invalid code that should produce specific diagnostics (.toEmitDiagnostics())
- Distinctive: line 58
Create equivalence classes for the input and write tests covering at least one instance of each class:
- Distinctive: line 63
Add boundary conditions specific to the rule logic (e.g., for a name-prefix rule):
- Very specific: line 67
Always include at least one test verifying that library types in Azure.Core and Azure.ResourceManager are not subject to the rule
- Distinctive: line 91
Verify tests fail before implementing:
- Very specific: line 111
Use context.reportDiagnostic({ target }) to report violations
- Very specific: line 112
Use paramMessage from @typespec/compiler for interpolated messages
- Very specific: line 113
Add codefixes array to reportDiagnostic() if a fix is possible
- Distinctive: line 122
All tests should pass. If not, fix the implementation until they do.
- Distinctive: line 126
Add the rule to the appropriate ruleset(s):
- Very specific: line 133
Add an entry: "@azure-tools/typespec-<pkg>/<rule-name>": true,
- Very specific: line 135
Every rule MUST be explicitly listed (enabled or disabled).
- Distinctive: line 149
Write a clear description of what the rule checks and why
- Very specific: line 151
Add a required ## Impact section: a bulleted Area: line (e.g.
- Very specific: line 152
Add a required ## Suppression section: state whether suppression is acceptable and why, and point to the correct fix.
- Very specific: line 153
Add a ## LintDiff Equivalent section when an equivalent LintDiff (azure-openapi-validator) rule exists, deep-linking to the specific rule …
- Very specific: line 179
Write a concise description: "Add <rule-name> linter rule that <what it does>"
- Distinctive: line 183
Run the general pre-PR validation to ensure everything is ready:
- Very specific: line 191
If any check fails, fix the issue and re-run.
- Very specific: line 198
If the agent cannot apply the label automatically, tell the user to apply the int:azure-specs label manually in the GitHub UI
- Very specific: line 199
After applying the label, the External Integration workflow will start.
- Distinctive: line 201
Wait for the check to pass before requesting review
- Distinctive: line 203
If the check fails, your rule produces diagnostics on existing specs.
- Very specific: line 206
Suppress the rule: If the spec cannot be fixed without changing API behavior, add a #suppress "<rule-id>" "<justification-string>" …
- Distinctive: line 207
Fix on typespec-next: If the fix requires unreleased TypeSpec APIs or behavior, submit to the typespec-next branch (uses nightly builds).
- Distinctive: line 208
Link your spec fix PR: Always link the spec fix PR in your linter rule PR description.
- Very specific: line 220
Import extensions: Always use .js extensions in imports (e.g., from "./rules/my-rule.js")
- Very specific: line 221
Rule URL: Must match https://azure.github.io/typespec-azure/docs/libraries/<pkg>/rules/<rule-name>
- Very specific: line 223
Existing patterns: Look at similar existing rules in packages/<pkg>/src/rules/ for reference
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Create a TypeSpec Linter Rule
Follow these steps in order to create a complete, high-quality linter rule.
Step 1: IDENTIFY
Determine the rule metadata before writing any code:
- Package:
typespec-azure-core(data-plane rules),typespec-azure-resource-manager(ARM rules), ortypespec-client-generator-core(client SDK generation rules) - Rule name: Must follow these naming conventions:
- Use kebab-case (lowercase letters, numbers, hyphens)
- DO NOT include the package name in the rule ID (the package is already part of the fully-qualified diagnostic code)
- Use
no-<thing>when the rule bans a construct or usage (e.g.,no-nullable,no-enum,no-format) - Use
use-<preferred-thing>when the rule points users to a standard/preferred TypeSpec pattern (e.g.,use-standard-operations,use-extensible-enum) - Keep names short and concise — prefer
no-enumoverno-enum-type-usage
- Severity: All linter rules are warnings; no severity choice is needed
- Target ruleset(s):
data-plane,resource-manager, or both - Description: One-line explanation of what the rule enforces
Choose the package by scope:
- Decorators from
typespec-client-generator-core, or rules only about client SDK generation →typespec-client-generator-core - Rules specific to ARM APIs →
typespec-azure-resource-manager - Rules that apply to both data-plane and ARM, or only data-plane →
typespec-azure-core
Step 2: SCAFFOLD
Generate all required files using the repo's scaffolding tool:
pnpm create:linter-rule < rule-name > --package < azure-core | azure-resource-manager | client-generator-core > --description "<description>"This creates:
packages/<pkg>/src/rules/<rule-name>.ts— rule skeletonpackages/<pkg>/test/rules/<rule-name>.test.ts— test skeletonpackages/<pkg>/src/rules/<rule-name>.md— docs skeleton (referenced from the rule viadocs: fileRef.fromPackageRoot(...))- Updates
packages/<pkg>/src/linter.ts— registers the rule
Step 3: WRITE FAILING TESTS FIRST (TDD)
Edit packages/<pkg>/test/rules/<rule-name>.test.ts:
- Write tests for valid code that should produce no diagnostics (
.toBeValid()) - Write tests for invalid code that should produce specific diagnostics (
.toEmitDiagnostics()) - Create equivalence classes for the input and write tests covering at least one instance of each class:
- Group inputs by how the rule handles them (e.g., for a rule targeting
ModelProperty):- Simply defined properties
- Properties defined using
spreadoris - Properties inherited from a base class
- Add boundary conditions specific to the rule logic (e.g., for a name-prefix rule):
- Properties with the forbidden prefix
- Properties with the prefix text in the middle or end of the name
- Properties with names shorter than the prefix
- Group inputs by how the rule handles them (e.g., for a rule targeting
- Always include at least one test verifying that library types in
Azure.CoreandAzure.ResourceManagerare not subject to the rule
Test API reference:
// No diagnostics expected
await tester.expect(`model Foo {}`).toBeValid();
// Specific diagnostic expected
await tester.expect(`model foo {}`).toEmitDiagnostics([
{
code: "@azure-tools/typespec-<pkg>/<rule-name>",
severity: "warning",
message: "Expected message text",
},
]);
// Test code fix (if rule provides one)
await tester
.expect(`enum Color { red }`)
.applyCodeFix("fix-id")
.toEqual(`union Color { string, red: "red" }`);Verify tests fail before implementing:
pnpm --filter "@azure-tools/typespec-<pkg>..." build
pnpm --filter "@azure-tools/typespec-<pkg>..." testStep 4: IMPLEMENT THE RULE
Edit packages/<pkg>/src/rules/<rule-name>.ts:
- Implement visitor logic in the
create(context)function - Return a
SemanticNodeListenerwith the appropriate hooks:model— for model-level checksmodelProperty— for property-level checksoperation— for operation-level checksenum— for enum checksnamespace— for namespace-level checksinterface— for interface checksunion/unionVariant— for union checks
- Use
context.reportDiagnostic({ target })to report violations - Use
paramMessagefrom@typespec/compilerfor interpolated messages - Add
codefixesarray toreportDiagnostic()if a fix is possible
Step 5: VERIFY TESTS PASS
pnpm --filter "@azure-tools/typespec-<pkg>..." build
pnpm --filter "@azure-tools/typespec-<pkg>..." testAll tests should pass. If not, fix the implementation until they do.
Step 6: REGISTER IN RULESETS
Add the rule to the appropriate ruleset(s):
- Data-plane rules: Edit
packages/typespec-azure-rulesets/src/rulesets/data-plane.ts - ARM rules: Edit
packages/typespec-azure-rulesets/src/rulesets/resource-manager.ts
TCGC rules generally go in both rulesets. Rules in typespec-azure-core that apply to both ARM and data-plane specs also go in both rulesets. Only rules that are truly ARM-specific go exclusively in resource-manager.ts; otherwise, add the rule to both resource-manager.ts and data-plane.ts as appropriate.
Add an entry: "@azure-tools/typespec-<pkg>/<rule-name>": true,
Every rule MUST be explicitly listed (enabled or disabled). The validate-rules-defined.test.ts test will fail otherwise.
Verify:
pnpm --filter "@azure-tools/typespec-azure-rulesets..." build
pnpm --filter "@azure-tools/typespec-azure-rulesets..." testStep 7: WRITE DOCUMENTATION AND REGENERATE DOCS
Edit packages/<pkg>/src/rules/<rule-name>.md:
- Replace all placeholder text
- Write a clear description of what the rule checks and why
- Provide realistic ❌ Incorrect and ✅ Correct examples using actual TypeSpec patterns
- Add a required
## Impactsection: a bulleted**Area:**line (e.g.API,SDK,Emitters) followed by a short paragraph describing what breaks or degrades when the rule is violated - Add a required
## Suppressionsection: state whether suppression is acceptable and why, and point to the correct fix. Suppressions use the#suppress "<rule-id>" "<justification-string>"directive placed on the line above the target — NOT a// suppresscomment - Add a
## LintDiff Equivalentsection when an equivalent LintDiff (azure-openapi-validator) rule exists, deep-linking to the specific rule id in the OpenAPI authoring automated guidelines. Omit only when no equivalent exists - This file holds only the extended documentation body — the page title, rule id, and
short description are generated from the rule definition.
tspdrenders the page atwebsite/src/content/docs/docs/libraries/<pkg>/rules/<rule-name>.md - For ARM rules, also update the alphabetized rule table in
website/src/content/docs/docs/howtos/ARM/arm-rules.mdwith the documentation URL, LintDiff equivalent, and impact. This table is authored manually and is not updated byregen-docs.
Then regenerate the library's reference docs (updates the rule listing):
pnpm --filter "@azure-tools/typespec-<pkg>..." build
pnpm --filter "@azure-tools/typespec-<pkg>" regen-docsStep 8: CREATE CHANGESET
pnpm change addWhen prompted:
- Select change kind:
feature(new rule) orfix(bugfix to existing rule) - Select affected package:
@azure-tools/typespec-<pkg> - Write a concise description: "Add
<rule-name>linter rule that<what it does>"
Step 9: FINAL VALIDATION
Run the general pre-PR validation to ensure everything is ready:
pnpm validate:prThis checks: branch is up to date, build passes, tests pass, lint passes, format is clean, spelling is clean, regen-docs is clean, changeset exists, and diff only contains expected files.
If any check fails, fix the issue and re-run. Use pnpm validate:pr --fix to auto-fix formatting and lint issues.
Step 10: EXTERNAL INTEGRATION CHECK
New linter rules MUST NOT break existing Azure service specs. After pushing your PR:
- Apply the
int:azure-specslabel to the PR to trigger the External Integration check:gh pr edit --add-label "int:azure-specs" - If the agent cannot apply the label automatically, tell the user to apply the
int:azure-specslabel manually in the GitHub UI - After applying the label, the External Integration workflow will start. Monitor it via
gh run list --workflow=external-integration.yml - This workflow packages your changes and runs TypeSpec validation against all specs in
Azure/azure-rest-api-specs - Wait for the check to pass before requesting review
If the check fails, your rule produces diagnostics on existing specs. To resolve:
- Apply an API-neutral fix to the spec (preferred): If the fix doesn't change API behavior, submit a PR to
Azure/azure-rest-api-specson the main branch. - Suppress the rule: If the spec cannot be fixed without changing API behavior, add a
#suppress "<rule-id>" "<justification-string>"directive on the line above the target (NOT a// suppresscomment). Suppressions always go to the main branch. - Fix on typespec-next: If the fix requires unreleased TypeSpec APIs or behavior, submit to the typespec-next branch (uses nightly builds).
- Link your spec fix PR: Always link the spec fix PR in your linter rule PR description.
The External Integration workflow:
- Builds and packs all typespec-azure packages from your PR
- Checks out
Azure/azure-rest-api-specs(main branch) - Patches in your packaged changes
- Runs
tsp-integration azure-specs --stage validate - Checks for unexpected git changes
Important Notes
- Import extensions: Always use
.jsextensions in imports (e.g.,from "./rules/my-rule.js") - Rule URL: Must match
https://azure.github.io/typespec-azure/docs/libraries/<pkg>/rules/<rule-name> - Test coverage: Aim for ≥ 95% branch coverage of the rule file
- Existing patterns: Look at similar existing rules in
packages/<pkg>/src/rules/for reference - ARM rules can import from azure-core:
import { ... } from "@azure-tools/typespec-azure-core"
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

