package dunolint

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Dunolint_engine.ContextSource

Auto-discovery and accumulation of contextual information during tree traversal.

This module provides a context that is built up as the linting engine traverses the directory tree, accumulating information that affects how linting is performed.

The context currently holds a list of dunolint configurations. The order follows the principle of a functional stack: data is added at the head as it is discovered when going deeper in the directory structure, and the configs function returns them in rule processing order (shallowest to deepest).

Planned evolution

The context is designed to support future enhancements:

  1. Config autoloading: Automatically discover and load dunolint config files from the workspace root and subdirectories during traversal, with location tracking to enable path-relative rule evaluation.
  2. Additional dune context: Include information from enclosing dune-project files and dune describe output to provide richer context for linting rules (e.g., project metadata, library dependencies).
Sourcetype t
Sourceval empty : t

An empty context.

Sourcemodule Config_with_location : sig ... end

Configuration with its location in the directory tree.

Sourceval add_config : t -> config:Dunolint.Config.t -> location:Fpath_sexp0.Relative_path.t -> t

Add a discovered config at the specified location.

Get the list of discovered configs with their locations. Returns configs in rule processing order: from least specific (root) to most specific (closest to current location), so that deeper configs can override rules from shallower configs.

Enclosing project metadata

During linting we aggregate "dune-project" files found in parent directories and retain some information used during linting.

An example of information used is the dune lang version in use in the project, which informs the dune format-dune-file --dune-version _ command used to perform the formatting of dune files.

Dunolint supports performing linting operations when the enclosing dune-project file is invalid. In particular this allows more flexibility during development workflows such as linting-on-save.

To achieve this, the information retained from a dune-project file is a result, and the code using this interface must handle the error case when querying the enclosing dune project context.

Sourcemodule Enclosing_result : sig ... end
Sourceval add_dune_project_context : t -> dune_project_context:Dune_project_context.t Enclosing_result.t -> location:Fpath_sexp0.Relative_path.t -> t

Add a discovered dune-project at the specified location.

Sourceval enclosing_dune_project_context : t -> Dune_project_context.t Enclosing_result.t Base.option

If known to be within the scope of an enclosing dune-project file, returns the context we saved for it. This is used in particular to know which dune version to use when formatting dune files. This returns None when no dune project file was found in the enclosing context.

A convenient wrapper for enclosing_dune_project_context which returns the lang version. If the "dune-project" is valid the dune lang version must have been found as its first line, otherwise we return None and rely on dune to report the missing stanza.