package dunolint

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

Module Dune_project_linterSource

Sourcemodule Generate_opam_files : sig ... end
Sourcemodule Implicit_transitive_deps : sig ... end
Sourcemodule Name : sig ... end
Sourcetype t
include Dunolinter.S with type t := t

Stanzas

Sourcemodule Stanza : sig ... end

Creation

A t shall be created from a string that would yield a successful parsing of many sexps and positions from a dune file, using the Parsexp library. The path is provided to create a Loc.t for error messages, as well as serve during condition evaluation based on paths, but no I/O is actually performed on disk - the sexps are parsed from the string provided by the parameter original_contents.

The type is intended to make it easy to connect to code using Err, such as shown below:

  match Dune_linter.create ~path ~original_contents with
  | Ok r -> r
  | Error { loc; message } -> Err.raise ~loc [ Pp.text message ]

Linting

Iter through the stanzas found in the file. The function f provided will be called on all the toplevel stanzas found in the file.

The expected way to use this function is to do some pattern matching on the Stanza.t currently at hand, and use the corresponding api if some rewrites are required. If the current stanza is not one you are targeting you may simply ignore and return unit, to be called again on the remaining stanzas of the input.

Note that you may visit the same file multiple times (that is, calling visit multiple times with different invocations of f), however be mindful that the file_rewriter that you manipulate is the same each time, thus the final computation of the output will fail if you enqueue incompatible rewrites in it. This is however not a recommended way to use this library, as this may be quite confusing. Indeed, the state you will match on will be that of the original contents, even though some rewrites have already happen. It shall be preferred to apply all the rewrites you wish in one path for each stanza, unless you are sure the rewrites are targeting parts of the input that are clearly independent.

If you need to apply low-level rewrites, you may do so with the Sexps_rewriter api, by accessing the original_sexp of the stanza. For example, you can do so with stanzas or rewrites that are not natively supported by this library.

Output

Sourceval contents : t -> Base.string

Produce the resulting buffer, with all the rewrites applied. Note that t may continue to be used further from here, and you can call contents again later. This raises File_rewriter.Invalid_rewrites if inconsistent rewrites have been submitted to t's file_rewriter.

Note that this library is a rather low-level util library. In particular, using this library does not get you auto-formatting of dune files, thus the output may be not particularly pretty or well indented. For a more ergonomic wrapper, and inclusion of auto-fmt, you should consider using via Dunolint_engine.

Getters

Sourceval sexps_rewriter : t -> Sexps_rewriter.t

If you need access to the internal sexps_rewriter, this accessor is exposed.

Sourceval file_rewriter : t -> File_rewriter.t

If you need access to the internal file_rewriter, this accessor is exposed.

Sourceval original_sexps : t -> Base.Sexp.t Base.list

Access the raw sexps that were parsed from the original contents.

Retrieve the path provided when t was created.

Sourcetype Stanza.t +=
  1. | Generate_opam_files of Generate_opam_files.t
  2. | Implicit_transitive_deps of Implicit_transitive_deps.t
  3. | Name of Name.t
OCaml

Innovation. Community. Security.