Understanding Vibrant rules
Vibrant rules are TypeScript-based linting rules that analyze code using the TypeScript AST (Abstract Syntax Tree). Each rule follows a standard structure defined by theRule interface.
Rule interface
Fromapps/cli/src/core/types.ts:146-151:
meta: Metadata describing the rulecreate: Function that returns AST node listeners
Rule metadata
TheRuleMeta interface defines rule properties:
apps/cli/src/core/types.ts
Rule categories
Vibrant organizes rules into categories fromapps/cli/src/rules/index.ts:18-59:
Built-in rules
Vibrant includes these detection rules:| Rule | Category | Severity | Fixable |
|---|---|---|---|
no-explicit-any | Type Safety | error | ✓ |
unimplemented-error | Incomplete Code | error | ✗ |
empty-function-body | Incomplete Code | error | ✗ |
empty-catch-block | Error Handling | error | ✗ |
hardcoded-credentials | Security | error | ✗ |
no-sql-injection | Security | error | ✗ |
no-unsafe-inner-html | Security | error | ✗ |
no-await-in-loop | Performance | error | ✗ |
no-unreachable | Possible Bugs | error | ✗ |
use-isnan | Possible Bugs | error | ✗ |
console-log-debugging | Code Quality | warning | ✗ |
ai-comment-emojis | AI Telltales | warning | ✗ |
ai-todo-comments | AI Telltales | warning | ✗ |
magic-numbers | Best Practices | warning | ✗ |
Rule anatomy
Let’s examine a complete rule to understand how they work.Example: no-explicit-any rule
Fromapps/cli/src/rules/no-explicit-any.ts:
How rules are executed
The linter executes rules through AST traversal fromapps/cli/src/core/linter.ts:359-441:
Contributing rules
While Vibrant doesn’t support loading external custom rules, you can contribute new rules to the project.Rule contribution process
Identify a pattern
Find a common AI-generated code pattern worth detecting:
- Security vulnerabilities
- Performance issues
- Type safety problems
- Incomplete implementations
- AI telltale signs
Rule development tips
Rule context API
TheRuleContext provides utilities for rule authors:
apps/cli/src/core/types.ts
Report descriptor
apps/cli/src/core/types.ts
Future: Plugin system
Vibrant is planning to support a plugin system for loading custom rules. This will allow:
- Installing rules from npm packages
- Loading rules from local files
- Configuring custom rule sets
- Sharing rules across projects
Planned plugin interface
Future plugin system
Examples
Simple pattern detection
Detect eval() usage
Pattern with auto-fix
Fix console.log statements
Related
- Configuration - Configure rule severity
- Ignoring issues - Disable specific rules
- Contributing guide - Contribute rules