package dunolint
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=b44119c96aeabb960e852711c2f20ae43f0011e796f05e012141ba980a5b58f6
sha512=5bf76732adc940db6cac0875e94c3eaff436288faba95388b9675c68b3f30f5362e01f289fc8a096325f7db812ace273773a1e051ab7d7ace3b8db4a57a0e070
doc/dunolint.dune_project_linter/Dune_project_linter/index.html
Module Dune_project_linter
Source
include Dunolinter.S with type t := t
Stanzas
Creation
val create :
path:Fpath_base.Relative_path.t ->
original_contents:Base.string ->
(t, Sexps_rewriter.Parse_error.t) Base.Result.t
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
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
If you need access to the internal sexps_rewriter, this accessor is exposed.
If you need access to the internal file_rewriter, this accessor is exposed.
Access the raw sexps that were parsed from the original contents.
Retrieve the path provided when t
was created.
type Stanza.t +=
| Generate_opam_files of Generate_opam_files.t
| Implicit_transitive_deps of Implicit_transitive_deps.t
| Name of Name.t