Skip to content

Commit

Permalink
Chore: Minor polishing after applying linter to compilers 2023 repo
Browse files Browse the repository at this point in the history
Signed-off-by: Kakadu <[email protected]>
  • Loading branch information
Kakadu committed Jul 28, 2024
1 parent 234a806 commit 26de476
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Load_dune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ let analyze_dir ~untyped:analyze_untyped ~cmt:analyze_cmt ~cmti:analyze_cmti pat
then on_module wrappedness m
else if (* Usually this happend with 'fake' wrapped modules from dune *)
not (String.equal name (String.lowercase m.name))
then printfn "module %S is omitted" m.name)))
then if Config.verbose () then printfn "module %S is omitted" m.name)))
in
loop_database ()
;;
31 changes: 13 additions & 18 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ let per_file_linters = [ (module TypedLints.License : LINT.TYPED) ]
let untyped_linters =
let open UntypedLints in
[ (module Casing : LINT.UNTYPED)
; (module UntypedLints.Dollar : LINT.UNTYPED)
; (module Manual_fold : LINT.UNTYPED)
; (module Manual_map : LINT.UNTYPED)
; (module Parsetree_has_docs : LINT.UNTYPED)
; (module UntypedLints.Propose_function : LINT.UNTYPED)
; (module Toplevel_eval : LINT.UNTYPED)
; (module UntypedLints.Propose_function : LINT.UNTYPED)
; (module Var_should_not_be_used : LINT.UNTYPED)
; (module UntypedLints.Dollar : LINT.UNTYPED)
]
;;

Expand All @@ -31,26 +31,26 @@ let typed_linters =
[ (* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *)
(module Ambiguous_constructors : LINT.TYPED)
; (module Exc_try_with_wildcard : LINT.TYPED)
; (module Failwith : LINT.TYPED)
; (module Equality : LINT.TYPED)
; (module Eta : LINT.TYPED)
; (module Equality_phys : LINT.TYPED)
; (module Failwith : LINT.TYPED)
; (module Eta : LINT.TYPED)
; (module Format : LINT.TYPED)
; (module Guard_instead_of_if : LINT.TYPED)
; (module Hashtables : LINT.TYPED)
; (module If_bool : LINT.TYPED)
; (module Ignore : LINT.TYPED)
; (module Hashtables : LINT.TYPED)
; (module List_fusion : LINT.TYPED)
; (module List_length : LINT.TYPED)
; (module Match_Bool : LINT.TYPED)
; (module Monad_laws : LINT.TYPED)
; (module Mutually_rec_types : LINT.TYPED)
; (module Nested_if : LINT.TYPED)
; (module Propose_function : LINT.TYPED)
; (module Record_punning : LINT.TYPED)
; (module String_concat : LINT.TYPED)
; (module String_concat_fold : LINT.TYPED)
; (module Guard_instead_of_if : LINT.TYPED)
; (module Tuple_matching : LINT.TYPED)
; (module Mutually_rec_types : LINT.TYPED)
; (module Nested_if : LINT.TYPED)
(* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *)
]
;;
Expand All @@ -74,6 +74,7 @@ let () =
()
;;

(* TODO(Kakadu): Functions below are a little bit copy-pasty. Rework them *)
let process_per_file_linters_str info parsetree =
let is_enabled = Config.is_enabled () in
List.iter per_file_linters ~f:(fun ((module L : LINT.TYPED) as lint) ->
Expand All @@ -92,7 +93,6 @@ let process_per_file_linters_sig info parsetree =
(L.run info default_iterator).signature default_iterator parsetree)
;;

(* TODO: Functions below are a little bit copy-pasty. Rework them *)
let build_iterator ~init ~compose ~f xs =
let o = List.fold_left ~f:(fun acc lint -> compose lint acc) ~init xs in
f o
Expand Down Expand Up @@ -120,23 +120,18 @@ let untyped_on_signature info =
untyped_linters
;;

let typed_on_structure info =
let run_typed_lints entry info =
let is_enabled = Config.is_enabled () in
build_iterator
~f:(fun o -> o.Tast_iterator.structure o)
~f:entry
~compose:(fun ((module L : LINT.TYPED) as lint) acc ->
if is_enabled (lint :> (module LINT.GENERAL)) then L.run info acc else acc)
~init:Tast_iterator.default_iterator
typed_linters
;;

let typed_on_signature info =
build_iterator
~f:(fun o -> o.Tast_iterator.signature o)
~compose:(fun (module L : LINT.TYPED) -> L.run info)
~init:Tast_iterator.default_iterator
typed_linters
;;
let typed_on_structure = run_typed_lints (fun o -> o.Tast_iterator.structure o)
let typed_on_signature = run_typed_lints (fun o -> o.Tast_iterator.signature o)

let with_info filename f =
Compile_common.with_info
Expand Down
3 changes: 3 additions & 0 deletions src/untyped/Propose_function.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

[@@@ocaml.text "/*"]

(* TODO(Kakadu): Think again: do we need both typed and untyped
version of this lint? *)

open Zanuda_core
open Zanuda_core.Utils

Expand Down
10 changes: 9 additions & 1 deletion src/untyped/Var_should_not_be_used.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ let documentation =
Report identifier starting with '_' and used later

### Why is this bad?
OCaml compiler has a tendency to report warning 26 about unused variables. Usually this warning could be supressed by adding '_' in the beginning of identifier to make it look like wildcard variable. But if that identifier is used later it contradicts the purpose of adding undescore in the beginnning.
OCaml compiler has a tendency to report warning 26 about unused variables.
Usually this warning could be supressed by adding '_' in the beginning of identifier to make it look like wildcard variable.
But if that identifier is used later it contradicts the purpose of adding undescore in the beginnning.
|}
|> Stdlib.String.trim
;;
Expand Down Expand Up @@ -84,7 +86,13 @@ let check_occurances_exn txt e =
;;

let is_name_suspicious txt =
(* TODO(Kakadu): Invent better solution to deal with menhir generated files. *)
String.is_prefix txt ~prefix:"_"
&& (not (String.equal txt "_startpos"))
&& (not (String.equal txt "_endpos"))
&& (not (String.equal txt "_2"))
&& (not (String.equal txt "_tok"))
&& (not (String.equal txt "_v"))
&& (not (String.is_prefix txt ~prefix:"__ocaml_lex"))
&& not (String.is_prefix txt ~prefix:"_menhir_")
;;
Expand Down
1 change: 0 additions & 1 deletion tests/typed/License.t/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
$ dune build @default ./REPL.exe

$ ../zanuda.exe -no-check-filesystem -dir . -ordjsonl /dev/null
module "Asdf__" is omitted
File "REPL.ml", line 1, characters 0-9:
1 | open List
^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/unused_func/Only_mli.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $ dune describe
$ dune exec ./only_mli_demo.exe #-j1 --verbose
my_id 5 = 5
$ ../zanuda.exe -unused-decls .
module "Only_mli_lib" is omitted
Unused declarations:
0: A.incr
1: B.my_id
Expand Down
1 change: 0 additions & 1 deletion tests/unused_func/Simple.t/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
$ dune build @check
$ dune describe
$ ../zanuda.exe -unused-decls .
module "Custom_lib" is omitted
Unused declarations:
0: Simple.Meow.meow
1: Simple.Meow.woof
Expand Down

0 comments on commit 26de476

Please sign in to comment.