Skip to content

Commit

Permalink
Do not geenrate DIFF fixes by default
Browse files Browse the repository at this point in the history
Signed-off-by: Kakadu <kakadu@pm.me>
  • Loading branch information
Kakadu committed Jan 3, 2024
1 parent 2626cca commit b1a84f6
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/Config.ml
Expand Up @@ -25,6 +25,7 @@ type t =
; mutable prefix_to_add : string option
; mutable extra_includes : string list
; mutable verbose : bool
; mutable gen_replacements : bool
; enabled_lints : string Hash_set.t
; mutable skip_level_allow : bool
; mutable check_filesystem : bool
Expand All @@ -40,6 +41,7 @@ let opts =
; prefix_to_add = None
; extra_includes = []
; verbose = false
; gen_replacements = false
; enabled_lints = Hash_set.create (module String)
; skip_level_allow = true
; check_filesystem = true
Expand Down Expand Up @@ -75,6 +77,7 @@ let out_golint () = opts.outgolint
let out_rdjsonl () = opts.out_rdjsonl
let unset_check_filesystem () = opts.check_filesystem <- false
let verbose () = opts.verbose
let gen_replacements () = opts.gen_replacements
let set_verbose () = opts.verbose <- true
let set_skip_level_allow b = opts.skip_level_allow <- b

Expand Down Expand Up @@ -136,6 +139,9 @@ let parse_args () =
"version: %s\n"
(Option.fold ~none:"n/a" ~some:Version.to_string (version ())))
, " print version" )
; ( "-diffs-with-fixes"
, Arg.Unit (fun () -> opts.gen_replacements <- true)
, " Do generate DIFFs with replacements" )
; "-fix", Arg.String set_fix, "Apply all found lints available for correction"
]
in
Expand Down
6 changes: 4 additions & 2 deletions src/fix/replacement/refill.ml
Expand Up @@ -75,12 +75,14 @@ let apply_all repls fcontent =

open Log

let apply_all _ =
let apply_all () =
let () = prepare_env () in
let new_payloads =
FileRepl.fold
(fun fname frepls fr_acc ->
(fname, apply_all frepls (file_content fname)) :: fr_acc)
if Sys.file_exists fname
then (fname, apply_all frepls (file_content fname)) :: fr_acc
else fr_acc)
!repls
[]
in
Expand Down
4 changes: 2 additions & 2 deletions src/main.ml
Expand Up @@ -244,15 +244,15 @@ let () =
| File file ->
process_untyped file;
CollectedLints.report ();
Replacement.Refill.apply_all ()
if Config.gen_replacements () then Replacement.Refill.apply_all ()
| Dir path ->
LoadDune.analyze_dir
~untyped:process_untyped
~cmt:process_cmt_typedtree
~cmti:process_cmti_typedtree
path;
CollectedLints.report ();
Replacement.Refill.apply_all ()
if Config.gen_replacements () then Replacement.Refill.apply_all ()
| Fix path -> Replacement.Log.promote path
in
()
Expand Down
2 changes: 1 addition & 1 deletion tests/fix/FalseProposeFunction.t/run.t
@@ -1,5 +1,5 @@
$ dune build
$ zanuda -no-top_file_license -dir .
$ zanuda -no-top_file_license -dir . -diffs-with-fixes
File '_build/default/FalseProposeFunction.ml' doesn't have corresponding .mli interface
File "FalseProposeFunction.ml", lines 2-5, characters 0-43:
Expand Down
2 changes: 1 addition & 1 deletion tests/fix/IfBool.t/run.t
@@ -1,5 +1,5 @@
$ dune build
$ zanuda -dir . > /dev/null
$ zanuda -dir . -diffs-with-fixes > /dev/null
$ cat fix_gen/diffs.log
Diffs for file IfBool.ml
2c2
Expand Down
2 changes: 1 addition & 1 deletion tests/fix/NestedComments.t/run.t
@@ -1,5 +1,5 @@
$ dune build
$ zanuda -dir . > /dev/null
$ zanuda -dir . -diffs-with-fixes > /dev/null
$ cat fix_gen/diffs.log
Diffs for file BugDemo.ml
2c2
Expand Down
2 changes: 1 addition & 1 deletion tests/fix/ProposeFunction.t/run.t
@@ -1,5 +1,5 @@
$ dune build
$ zanuda -dir . > /dev/null
$ zanuda -dir . -diffs-with-fixes > /dev/null
$ cat fix_gen/diffs.log
Diffs for file ProposeFunction.ml
6,8c6,8
Expand Down
2 changes: 1 addition & 1 deletion tests/fix/Record1.t/run.t
@@ -1,5 +1,5 @@
$ dune build
$ zanuda -dir . > /dev/null
$ zanuda -dir . -diffs-with-fixes > /dev/null
$ cat fix_gen/diffs.log
Diffs for file Record1.ml
6,8c6
Expand Down

0 comments on commit b1a84f6

Please sign in to comment.