Skip to main content

Crate normalize_syntax_rules

Crate normalize_syntax_rules 

Source
Expand description

Syntax-based linting with tree-sitter queries.

This crate provides:

  • Rule loading from multiple sources (builtins, user global, project)
  • Rule execution with combined query optimization
  • Pluggable data sources for rule conditionals

§Rule File Format

# ---
# id = "no-unwrap"
# severity = "warning"
# message = "Avoid unwrap() on user input"
# allow = ["**/tests/**"]
# requires = { "rust.edition" = ">=2024" }
# enabled = true  # set to false to disable a builtin
# fix = ""  # empty = delete match, or use "$capture" to substitute
# ---

(call_expression
  function: (field_expression
    field: (field_identifier) @method)
  (#eq? @method "unwrap")) @match

Structs§

BuiltinRule
A builtin rule definition (id, content).
DebugFlags
Debug output categories.
EnvSource
Environment variable source.
Finding
A finding from running a rule.
GitSource
Git repository state source.
GoSource
Go project source - parses go.mod for module metadata.
PathSource
Path-based source for glob matching.
PythonSource
Python project source - parses pyproject.toml for project metadata.
Rule
A syntax rule definition.
RuleOverride
Per-rule configuration override.
RulesConfig
Configuration for syntax rules analysis. Maps rule ID to per-rule configuration. e.g., { “rust/unnecessary-let” = { severity = “warning” } }
RustSource
Rust project source - parses Cargo.toml for edition, resolver, etc.
SourceContext
Context passed to sources for evaluation.
SourceRegistry
Registry of all available rule sources.
TypeScriptSource
TypeScript/JavaScript project source - parses tsconfig.json and package.json.

Enums§

Severity
Severity level for rule findings.

Constants§

BUILTIN_RULES
All embedded builtin rules.

Traits§

RuleSource
A source of data for rule conditionals.

Functions§

apply_fixes
Apply fixes to findings, returning the number of files modified. Fixes are applied in reverse order within each file to preserve byte offsets.
builtin_registry
Create a registry with all built-in sources.
evaluate_predicates
Evaluate predicates for a match.
load_all_rules
Load all rules from all sources, merged by ID. Order: builtins → ~/.config/moss/rules/ → .normalize/rules/ Then applies config overrides (severity, disable).
parse_rule_content
Parse rule content string with TOML frontmatter.
run_rules
Run rules against files in a directory. Optimized: combines all rules into single query per grammar for single-traversal matching.