11open Ppxlib
22open Stdppx
33
4- let expand_cold = ref true
54let error ~loc fmt = Location. raise_errorf ~loc (Stdlib. ( ^^ ) " ppx_base_lint:" fmt)
65
76type suspicious_id = Stdlib_submodule of string
@@ -42,23 +41,6 @@ let rec is_stdlib_dot_something : Longident.t -> bool = function
4241 | _ -> false
4342;;
4443
45- let print_payload ppf = function
46- | PStr x -> Pprintast. structure ppf x
47- | PSig x -> Pprintast. signature ppf x
48- | PTyp x -> Pprintast. core_type ppf x
49- | PPat (x , None) -> Pprintast. pattern ppf x
50- | PPat (x , Some w ) ->
51- Stdlib.Format. fprintf ppf " %a@ when@ %a" Pprintast. pattern x Pprintast. expression w
52- ;;
53-
54- let remove_loc =
55- object
56- inherit Ast_traverse. map
57- method! location _ = Location. none
58- method! location_stack _ = []
59- end
60- ;;
61-
6244let check current_module =
6345 let zero_modules = zero_modules () in
6446 object
@@ -105,75 +87,6 @@ let check current_module =
10587 ~loc: mb.pmb_loc
10688 " you cannot alias [Stdlib] sub-modules, use them directly"
10789 | _ -> () )
108-
109- method! attributes attrs =
110- super#attributes attrs;
111- if ! expand_cold
112- then (
113- let is_cold attr = String. equal attr.attr_name.txt " cold" in
114- match List. find_opt attrs ~f: is_cold with
115- | None -> ()
116- | Some attr ->
117- let expansion =
118- Ppx_cold. expand_cold_attribute attr
119- |> List. map ~f: (fun a ->
120- { a with
121- attr_name =
122- { a.attr_name with
123- txt =
124- (let string = a.attr_name.txt
125- and prefix = " ocaml." in
126- if String. is_prefix string ~prefix
127- then String. drop_prefix string (String. length prefix)
128- else string )
129- }
130- })
131- in
132- let is_part_of_expansion attr =
133- List. exists expansion ~f: (fun a ->
134- String. equal a.attr_name.txt attr.attr_name.txt
135- || String. equal (" ocaml." ^ a.attr_name.txt) attr.attr_name.txt)
136- in
137- let new_attrs =
138- List. concat_map attrs ~f: (fun a ->
139- if is_cold a
140- then a :: expansion
141- else if is_part_of_expansion a
142- then []
143- else [ a ])
144- in
145- if not
146- (Poly. equal
147- (remove_loc#attributes attrs)
148- (remove_loc#attributes new_attrs))
149- then (
150- (* Remove attributes written by the user that correspond to attributes in the
151- expansion *)
152- List. iter attrs ~f: (fun a ->
153- if is_part_of_expansion a
154- then Driver. register_correction ~loc: a.attr_loc ~repl: " " );
155- let attribute_level =
156- String. make
157- (attr.attr_name.loc.loc_start.pos_cnum
158- - attr.attr_loc.loc_start.pos_cnum
159- - 1 )
160- '@'
161- in
162- let repl =
163- Stdlib.Format. asprintf
164- " @[<h>%a@]"
165- (Stdlib.Format. pp_print_list (fun ppf x ->
166- Stdlib.Format. fprintf
167- ppf
168- " [%s%s@ %a]"
169- attribute_level
170- x.attr_name.txt
171- print_payload
172- x.attr_payload))
173- (attr :: expansion)
174- in
175- Driver. register_correction ~loc: attr.attr_loc ~repl );
176- Ppxlib.Attribute. mark_as_handled_manually attr)
17790 end
17891;;
17992
@@ -183,10 +96,6 @@ let module_of_loc (loc : Location.t) =
18396;;
18497
18598let () =
186- Ppxlib.Driver. add_arg
187- " -do-not-correct-cold-attributes"
188- (Clear expand_cold)
189- ~doc: " do not automatically expand [@cold] attributes" ;
19099 Ppxlib.Driver. register_transformation
191100 " base_lint"
192101 ~impl: (function
0 commit comments