package dunolint
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=1b064927c9e1ef5352a1886ae34a206fef0ce6a913c19a77b0162acc108e0e50
sha512=6cbc08ba318bef6584d15a4491e3dde1bf436109ce0f8b7c400a9f91bbcee64c5785bc924df11eafe98243ec2f188a7f92c58c5062729f3e2af1e9977f1a5e67
doc/dunolint.dunolinter/Dunolinter/Sections_handler/index.html
Module Dunolinter.Sections_handler
Source
A utility module to help with the management of fields containing separated sections.
Sections denote parts that are separated by comments or blank lines within a field. For example, in libraries:
(libraries ;; This is a first section aa bb ;; This is a second section cc zz)
We make use of this module, in addition to the the Comment_handler
to implement and share some functionality related to the handling of such sections in fields.
val are_in_different_sections :
previous:Parsexp.Positions.range ->
current:Parsexp.Positions.range ->
Base.bool
Tell whether two consecutive arguments are to be treated as belonging to different sections.
The way dunolint does this, is to look whether two consecutive entries are separated by more than 1 line. In particular this covers the case where entries are separated by a comment in its own line, in which case dunolint will consider that the dependencies are in different sections.
(libraries aa bb ;; this a comment cc zz)
are_in_different_section
must be called with two consecutive arguments, otherwise the returned value does not have any particular meaning.
val read_sections_fold :
field_name:Base.string ->
sexps_rewriter:Sexps_rewriter.t ->
field:Base.Sexp.t ->
init:'acc ->
f:
('acc ->
original_index:Base.int ->
loc:Loc.t ->
source:Base.string ->
arg:Base.Sexp.t ->
'acc * 'a) ->
'a Base.list Base.list
Read the arguments from an existing field, grouping them into sections according to the heuristic implemented by this module.
val read_sections :
field_name:Base.string ->
sexps_rewriter:Sexps_rewriter.t ->
field:Base.Sexp.t ->
f:
(original_index:Base.int ->
loc:Loc.t ->
source:Base.string ->
arg:Base.Sexp.t ->
'a) ->
'a Base.list Base.list
A simplified version of read_sections_fold
with no accumulator.
val rewrite_sections :
field_name:Base.string ->
sexps_rewriter:Sexps_rewriter.t ->
field:Base.Sexp.t ->
write_arg:('a -> Base.string) ->
sections:'a Base.list Base.list ->
Base.unit
This removes, replaces and inserts argument into sexps_rewriter
while computing the diff between the input sections
that we'd like to write, and the existing values found within field
that we'd like to modify. Typically, sections
is obtained from linting values according to rules, and field
is the existing contents that was loaded from disk that we'd like to modify.