
Add Dart Lint Validation Rule
FreeEasily create and manage custom lint rules for Dart skills.
Free ยท Opens the source repo
What Add Dart Lint Validation Rule does
The Add Dart Lint Validation Rule skill provides a structured approach for developers looking to implement custom validation rules within the dart_skills_lint package. This skill is particularly useful for those who need to enforce specific guidelines or checks on Dart skills, such as validating the frontmatter metadata in YAML files. By following the step-by-step instructions, users can create new rule classes, register them as CLI flags, and ensure their functionality through automated testing.
To create a new validation rule, developers will extend the SkillRule class and implement the necessary validation logic. The skill includes clear guidelines on how to access YAML frontmatter data, allowing for flexible rule definitions based on the skill's metadata. Additionally, the registration process is straightforward, involving the addition of the new rule to the RuleRegistry, which automatically exposes it as a toggleable CLI flag for easy use.
Testing is a critical component of this skill, and users are encouraged to write in-memory unit tests to verify their rules without the overhead of file I/O. The provided examples illustrate how to set up tests using mock contexts, ensuring that rules are correctly triggered or bypassed based on the input provided. For rules that interact with the file system, the skill also outlines how to use temporary directories for testing, maintaining a clean testing environment.
Overall, this skill is designed for Dart developers who want to enhance their linting capabilities by adding custom rules that cater to their specific needs. It streamlines the process of rule creation, registration, and testing, making it an essential tool for maintaining code quality in Dart projects.
When to use it
Use this skill when you need to implement a new validation rule for Dart skills, especially for validating YAML frontmatter metadata.
When not to use it
This skill is not suitable for users who do not require custom lint rules or those who are not working within the Dart ecosystem.
What you can build with it
Creating a New Validation Rule
You need to enforce a new coding standard across your Dart skills and decide to create a validation rule that checks for specific metadata in the YAML frontmatter.
Testing Validation Logic
After implementing a new lint rule, you write unit tests to ensure it correctly identifies errors in various skill configurations.
Integrating with CLI Tools
You want to expose your new validation rule as a CLI flag, making it easy for users to enable or disable it when running lint checks.
How to install Add Dart Lint Validation Rule
View source1. Install with the skills CLI
npx skills add flutter/agent-plugins/add-dart-lint-validation-rule --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by flutterAdd a New Validation Rule and Flag
Use this skill when you need to add a new validation rule to the dart_skills_lint package, expose it as a toggleable CLI flag, and verify its behavior.
๐ ๏ธ Step-by-Step Implementation
1. Create the Rule Class
Create a new file in lib/src/rules/ extending SkillRule.
[!TIP] If your rule expects a specific structure in the skill's YAML frontmatter (e.g., inside
metadata), document this structure clearly in the class Dart docstring.
// lib/src/rules/my_new_rule.dart
import '../models/analysis_severity.dart';
import '../models/skill_context.dart';
import '../models/skill_rule.dart';
import '../models/validation_error.dart';
class MyNewRule extends SkillRule {
MyNewRule({super.severity});
@override
Future<List<ValidationError>> validate(SkillContext context) async {
final errors = <ValidationError>[];
// Add validation logic here using context.rawContent or context.directory
return errors;
}
}
Accessing YAML Frontmatter
If your rule needs configuration from the skill's YAML frontmatter, you can access it via context.parsedYaml.
@override
Future<List<ValidationError>> validate(SkillContext context) async {
final errors = <ValidationError>[];
final yaml = context.parsedYaml;
if (yaml != null) {
final metadata = yaml['metadata'];
if (metadata is Map) {
// Read your custom config here
}
}
return errors;
}
2. Register the Rule in lib/src/rule_registry.dart
Add a new CheckType instance to RuleRegistry.allChecks list. This automatically exposes it as a CLI flag.
// lib/src/rule_registry.dart in allChecks list
const CheckType(
name: MyNewRule.ruleName,
defaultSeverity: MyNewRule.defaultSeverity,
help: 'Description of what the rule does for CLI help.',
),
Then, add a case to RuleRegistry.createRule to instantiate your rule:
// lib/src/rule_registry.dart in createRule method
static SkillRule? createRule(String name, AnalysisSeverity severity) {
switch (name) {
// ... other rules
case MyNewRule.ruleName:
return MyNewRule(severity: severity);
default:
return null;
}
}
3. Handle Disabled by Default Rules (If applicable)
If the rule is disabled by default (defaultSeverity: AnalysisSeverity.disabled), passing the flag --check-my-new-rule will automatically enable it with AnalysisSeverity.error severity (handled in entry_point.dart).
๐งช Testing the New Rule
You must write automated tests verifying your rule triggers when it should and skips when it shouldn't.
Preferred Approach: In-Memory Unit Tests
Instead of writing files to disk, test the rule directly using a mock SkillContext. This is faster and avoids I/O dependencies.
// test/my_new_rule_test.dart
import 'dart:io';
import 'package:dart_skills_lint/src/models/analysis_severity.dart';
import 'package:dart_skills_lint/src/models/skill_context.dart';
import 'package:dart_skills_lint/src/models/validation_error.dart';
import 'package:dart_skills_lint/src/rules/my_new_rule.dart';
import 'package:test/test.dart';
void main() {
group('MyNewRule', () {
test('flags invalid content', () async {
final rule = MyNewRule(severity: AnalysisSeverity.warning);
final context = SkillContext(
directory: Directory('dummy'),
rawContent: 'Invalid content',
);
final List<ValidationError> errors = await rule.validate(context);
expect(errors, isNotEmpty);
expect(errors.first.message, contains('Expected error message'));
});
test('passes valid content', () async {
final rule = MyNewRule(severity: AnalysisSeverity.warning);
final context = SkillContext(
directory: Directory('dummy'),
rawContent: 'Valid content',
);
final List<ValidationError> errors = await rule.validate(context);
expect(errors, isEmpty);
});
});
}
Alternative Approach: File System Interaction
If the rule interacts with the file system or wraps an external CLI tool (like popmark), you should use a temporary directory for testing instead of in-memory mocks.
late Directory tempDir;
setUp(() async {
tempDir = await Directory.systemTemp.createTemp('my_rule_test.');
});
tearDown(() async {
if (tempDir.existsSync()) {
await tempDir.delete(recursive: true);
}
});
test('flags invalid file content', () async {
final Directory skillDir = await Directory('${tempDir.path}/test-skill').create();
await File('${skillDir.path}/SKILL.md').writeAsString('Invalid content');
final rule = MyNewRule(severity: AnalysisSeverity.warning);
final context = SkillContext(directory: skillDir, rawContent: 'Invalid content');
final List<ValidationError> errors = await rule.validate(context);
expect(errors, isNotEmpty);
});
Integration Tests
If the rule interacts with CLI flags or configuration files, add a test in test/cli_integration_test.dart using TestProcess.
[!IMPORTANT] When writing integration tests that use config files and
TestProcess, ensure that paths in the config file and paths passed to the CLI match in style (both relative or both absolute) to avoid issues with path matching inentry_point.dart.
๐ Documentation Updates
When a new rule is introduced, verify that you synchronize sibling markdown files!
README.md:- Add your flag under the Flags section (under Usage) so users know it exists.
- CRITICAL FORMATTING: You MUST use the exact format
- \--[no-]<rule-name>`: <brief description>. (Disabled by default if applicable)`. - CRITICAL NAMING: Ensure the flag string matches the
ruleNameEXACTLY. For example, if theruleNameisfile-existence, the flag MUST be documented as--[no-]file-existence(do NOT hallucinate acheck-prefix like--[no-]check-file-existence). Do NOT add empty bullet points.
RULES.md:- Add a new entry for your rule documenting its default severity, fixability, what it checks, diagnostic shape, auto-fix behavior, and how to disable it. This is strictly required by the
rules_md_consistency_test.darttest.
- Add a new entry for your rule documenting its default severity, fixability, what it checks, diagnostic shape, auto-fix behavior, and how to disable it. This is strictly required by the
documentation/knowledge/SPECIFICATION.md:- Document the formal constraint in the specification if it defines a standard for skill files.
๐ฆ Checklist Before Submitting PR
- Rule class created in
lib/src/rules/. - Rule registered in
lib/src/rule_registry.dart. - Unit tests added in
test/using in-memorySkillContext. - CRITICAL: Usage flag correctly documented in
README.mdunder Flags (ensure flag string matchesruleNameEXACTLY and format is correct). - Rule documented in
RULES.md. - Schema documented in
documentation/knowledge/SPECIFICATION.md(if applicable). - Run
dart format .to format code. - Run
dart analyze --fatal-infosto ensure no issues. - Run
dart testto ensure tests passing.
Frequently asked questions about Add Dart Lint Validation Rule
Similar skills
Quality Playbook Generator
Run comprehensive quality audits on any codebase.
PR Draft Summary
Automate PR summary generation for openai-agents-python.
Final Release Review
Streamline your release candidate audits with ease.
Unit Test Vue Pinia
Efficiently write and review unit tests for Vue 3 applications.
Slang Shader Expert
Optimize and integrate Slang shaders with ease.
Telemetry Standards
Ensure consistent event tracking in Supabase Studio.
