glinter/rule

Types

Full lint result with file path and severity, produced by the orchestrator.

pub type LintResult {
  LintResult(
    rule: String,
    severity: Severity,
    file: String,
    location: glance.Span,
    message: String,
    details: String,
  )
}

Constructors

  • LintResult(
      rule: String,
      severity: Severity,
      file: String,
      location: glance.Span,
      message: String,
      details: String,
    )

Builder type for module rules. Generic over the context type.

pub opaque type ModuleRuleSchema(context)

Builder type for project rules. Generic over project and module context types.

pub opaque type ProjectRuleSchema(project_context, module_context)

A fully-built rule. Opaque – context types are erased via closures. The orchestrator holds List(Rule) without knowing context types.

pub opaque type Rule

An error produced by a rule visitor. Opaque – use error() to create.

pub opaque type RuleError
pub type Severity {
  Error
  Warning
  Off
}

Constructors

  • Error
  • Warning
  • Off

Values

pub fn default_severity(rule: Rule) -> Severity
pub fn error(
  message message: String,
  details details: String,
  location location: glance.Span,
) -> RuleError

Create an error with a message, details, and source location.

pub fn error_details(err: RuleError) -> String
pub fn error_location(err: RuleError) -> glance.Span
pub fn error_message(err: RuleError) -> String
pub fn is_project_rule(rule: Rule) -> Bool
pub fn module_rule_from_fn(
  name name: String,
  default_severity default_severity: Severity,
  run run: fn(glance.Module, String) -> List(RuleError),
) -> Rule

Build a module Rule from a custom run function. Use this when a rule needs access to the full module before visitor traversal (e.g. pre-collecting function signatures).

pub fn name(rule: Rule) -> String
pub fn new(name name: String) -> ModuleRuleSchema(Nil)

Create a new module rule schema with no context.

pub fn new_project(
  name name: String,
  initial initial: project_context,
) -> ProjectRuleSchema(project_context, module_context)

Create a new project rule schema with an initial project context.

pub fn new_with_context(
  name name: String,
  initial initial: context,
) -> ModuleRuleSchema(context)

Create a new module rule schema with an initial context value.

pub fn run_on_module(
  rule rule: Rule,
  module module: glance.Module,
  source source: String,
) -> List(RuleError)

Run a module rule on a single parsed module. Returns errors.

pub fn run_on_project(
  rule rule: Rule,
  files files: List(#(glance.Module, String)),
) -> List(RuleError)

Run a project rule on all files. Returns errors.

pub fn to_module_rule(schema: ModuleRuleSchema(context)) -> Rule

Build a Rule from a ModuleRuleSchema, erasing the context type via closures.

pub fn to_project_rule(schema: ProjectRuleSchema(pc, mc)) -> Rule

Build a Rule from a ProjectRuleSchema, erasing context types via closures.

pub fn visit_module(
  module module: glance.Module,
  schema schema: ModuleRuleSchema(context),
  source source: String,
) -> #(List(RuleError), context)

Visit a module with a rule schema, returning errors and final context. Drives all registered visitors through a depth-first AST traversal.

pub fn with_default_severity(
  schema schema: ModuleRuleSchema(context),
  severity severity: Severity,
) -> ModuleRuleSchema(context)
pub fn with_expression_enter_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(glance.Expression, glance.Span, context) -> #(
    List(RuleError),
    context,
  ),
) -> ModuleRuleSchema(context)
pub fn with_expression_exit_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(glance.Expression, glance.Span, context) -> #(
    List(RuleError),
    context,
  ),
) -> ModuleRuleSchema(context)
pub fn with_final_evaluation(
  schema schema: ModuleRuleSchema(context),
  evaluator evaluator: fn(context) -> List(RuleError),
) -> ModuleRuleSchema(context)
pub fn with_final_project_evaluation(
  schema schema: ProjectRuleSchema(pc, mc),
  evaluator evaluator: fn(pc) -> List(RuleError),
) -> ProjectRuleSchema(pc, mc)
pub fn with_function_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(
    glance.Definition(glance.Function),
    glance.Span,
    context,
  ) -> #(List(RuleError), context),
) -> ModuleRuleSchema(context)
pub fn with_import_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(glance.Definition(glance.Import), context) -> #(
    List(RuleError),
    context,
  ),
) -> ModuleRuleSchema(context)
pub fn with_module_context(
  schema schema: ProjectRuleSchema(pc, mc),
  from_project_to_module from_project_to_module: fn(pc) -> mc,
  from_module_to_project from_module_to_project: fn(mc, pc) -> pc,
) -> ProjectRuleSchema(pc, mc)
pub fn with_module_visitor(
  schema schema: ProjectRuleSchema(pc, mc),
  builder builder: fn(ModuleRuleSchema(mc)) -> ModuleRuleSchema(
    mc,
  ),
) -> ProjectRuleSchema(pc, mc)
pub fn with_project_default_severity(
  schema schema: ProjectRuleSchema(pc, mc),
  severity severity: Severity,
) -> ProjectRuleSchema(pc, mc)
pub fn with_simple_expression_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(glance.Expression, glance.Span) -> List(
    RuleError,
  ),
) -> ModuleRuleSchema(context)
pub fn with_simple_function_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(
    glance.Definition(glance.Function),
    glance.Span,
  ) -> List(RuleError),
) -> ModuleRuleSchema(context)
pub fn with_simple_import_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(glance.Definition(glance.Import)) -> List(
    RuleError,
  ),
) -> ModuleRuleSchema(context)
pub fn with_simple_statement_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(glance.Statement) -> List(RuleError),
) -> ModuleRuleSchema(context)
pub fn with_statement_visitor(
  schema schema: ModuleRuleSchema(context),
  visitor visitor: fn(glance.Statement, context) -> #(
    List(RuleError),
    context,
  ),
) -> ModuleRuleSchema(context)
Search Document