Skip to content

Commit e60a1b2

Browse files
committed
Commit new files
1 parent 3b6408f commit e60a1b2

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

lib/dunolint_cli/src/import.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(*********************************************************************************)
2+
(* Dunolint - A tool to lint and help manage files in dune projects *)
3+
(* Copyright (C) 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com> *)
4+
(* *)
5+
(* This file is part of Dunolint. *)
6+
(* *)
7+
(* Dunolint is free software; you can redistribute it and/or modify it *)
8+
(* under the terms of the GNU Lesser General Public License as published by *)
9+
(* the Free Software Foundation either version 3 of the License, or any later *)
10+
(* version, with the LGPL-3.0 Linking Exception. *)
11+
(* *)
12+
(* Dunolint is distributed in the hope that it will be useful, but WITHOUT *)
13+
(* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *)
14+
(* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *)
15+
(* and the file `NOTICE.md` at the root of this repository for more details. *)
16+
(* *)
17+
(* You should have received a copy of the GNU Lesser General Public License *)
18+
(* and the LGPL-3.0 Linking Exception along with this library. If not, see *)
19+
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
20+
(*********************************************************************************)
21+
22+
module Path_in_workspace = Dunolint_engine.Private.Path_in_workspace

lib/dunolint_cli/src/import.mli

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(*_********************************************************************************)
2+
(*_ Dunolint - A tool to lint and help manage files in dune projects *)
3+
(*_ Copyright (C) 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com> *)
4+
(*_ *)
5+
(*_ This file is part of Dunolint. *)
6+
(*_ *)
7+
(*_ Dunolint is free software; you can redistribute it and/or modify it *)
8+
(*_ under the terms of the GNU Lesser General Public License as published by *)
9+
(*_ the Free Software Foundation either version 3 of the License, or any later *)
10+
(*_ version, with the LGPL-3.0 Linking Exception. *)
11+
(*_ *)
12+
(*_ Dunolint is distributed in the hope that it will be useful, but WITHOUT *)
13+
(*_ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *)
14+
(*_ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *)
15+
(*_ and the file `NOTICE.md` at the root of this repository for more details. *)
16+
(*_ *)
17+
(*_ You should have received a copy of the GNU Lesser General Public License *)
18+
(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *)
19+
(*_ <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
20+
(*_********************************************************************************)
21+
22+
module Path_in_workspace = Dunolint_engine.Private.Path_in_workspace
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
(*********************************************************************************)
2+
(* Dunolint - A tool to lint and help manage files in dune projects *)
3+
(* Copyright (C) 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com> *)
4+
(* *)
5+
(* This file is part of Dunolint. *)
6+
(* *)
7+
(* Dunolint is free software; you can redistribute it and/or modify it *)
8+
(* under the terms of the GNU Lesser General Public License as published by *)
9+
(* the Free Software Foundation either version 3 of the License, or any later *)
10+
(* version, with the LGPL-3.0 Linking Exception. *)
11+
(* *)
12+
(* Dunolint is distributed in the hope that it will be useful, but WITHOUT *)
13+
(* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *)
14+
(* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *)
15+
(* and the file `NOTICE.md` at the root of this repository for more details. *)
16+
(* *)
17+
(* You should have received a copy of the GNU Lesser General Public License *)
18+
(* and the LGPL-3.0 Linking Exception along with this library. If not, see *)
19+
(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
20+
(*********************************************************************************)
21+
22+
let load_config_exn ~filename =
23+
let contents = In_channel.read_all filename in
24+
match Parsexp.Many_and_positions.parse_string contents with
25+
| Error parse_error ->
26+
let position = Parsexp.Parse_error.position parse_error in
27+
let message = Parsexp.Parse_error.message parse_error in
28+
let loc =
29+
Sexp_handler.loc_of_parsexp_range
30+
~filename
31+
{ start_pos = position; end_pos = position }
32+
in
33+
Err.raise ~loc [ Pp.text message ]
34+
| Ok (sexps, positions) ->
35+
(match Dunolint.Config.of_stanzas sexps with
36+
| t -> t
37+
| exception Sexp.Of_sexp_error (exn, sub) ->
38+
let range =
39+
match Parsexp.Positions.find_sub_sexp_in_list_phys positions sexps ~sub with
40+
| Some _ as range -> range
41+
| None -> None [@coverage off]
42+
in
43+
let loc =
44+
match range with
45+
| Some range -> Sexp_handler.loc_of_parsexp_range ~filename range
46+
| None -> Loc.of_file ~path:(Fpath.v filename) [@coverage off]
47+
in
48+
let message =
49+
match exn with
50+
| Failure str ->
51+
Pp.text (if String.is_suffix str ~suffix:"." then str else str ^ ".")
52+
| exn -> Err.exn exn [@coverage off]
53+
in
54+
Err.raise ~loc [ message ])
55+
;;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(*_********************************************************************************)
2+
(*_ Dunolint - A tool to lint and help manage files in dune projects *)
3+
(*_ Copyright (C) 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com> *)
4+
(*_ *)
5+
(*_ This file is part of Dunolint. *)
6+
(*_ *)
7+
(*_ Dunolint is free software; you can redistribute it and/or modify it *)
8+
(*_ under the terms of the GNU Lesser General Public License as published by *)
9+
(*_ the Free Software Foundation either version 3 of the License, or any later *)
10+
(*_ version, with the LGPL-3.0 Linking Exception. *)
11+
(*_ *)
12+
(*_ Dunolint is distributed in the hope that it will be useful, but WITHOUT *)
13+
(*_ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *)
14+
(*_ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *)
15+
(*_ and the file `NOTICE.md` at the root of this repository for more details. *)
16+
(*_ *)
17+
(*_ You should have received a copy of the GNU Lesser General Public License *)
18+
(*_ and the LGPL-3.0 Linking Exception along with this library. If not, see *)
19+
(*_ <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)
20+
(*_********************************************************************************)
21+
22+
(** A utility module to help with the loading and parsing of dunolint config
23+
files. *)
24+
25+
(** A helper for loading the config with some effort regarding producing located
26+
error messages when able. *)
27+
val load_config_exn : filename:string -> Dunolint.Config.t

0 commit comments

Comments
 (0)