Skip to content

Commit 7978fc5

Browse files
committed
Make transitive reports configurable.
1 parent 7352ec5 commit 7978fc5

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

analysis/reanalyze/examples/deadcode/bsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"reanalyze": {
33
"analysis": ["dce"],
44
"suppress": [],
5-
"unsuppress": []
5+
"unsuppress": [],
6+
"transitive": false
67
},
78
"name": "sample-typescript-app",
89
"bsc-flags": ["-bs-super-errors -w a"],

analysis/reanalyze/src/DeadCommon.ml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module Config = struct
1313
let analyzeTypes = ref true
1414
let analyzeExternals = ref false
1515
let reportUnderscore = false
16-
let reportTransitive = false
1716
let reportTypesDeadOnlyInInterface = false
1817
let recursiveDebug = false
1918
let warnOnCircularDependencies = false
@@ -406,10 +405,9 @@ let emitWarning ~decl ~message deadWarning =
406405
WriteDeadAnnotations.addLineAnnotation ~decl
407406
else None
408407
in
409-
if Config.reportTransitive then
410-
decl.path
411-
|> Path.toModuleName ~isType:(decl.declKind |> DeclKind.isType)
412-
|> DeadModules.checkModuleDead ~fileName:decl.pos.pos_fname;
408+
decl.path
409+
|> Path.toModuleName ~isType:(decl.declKind |> DeclKind.isType)
410+
|> DeadModules.checkModuleDead ~fileName:decl.pos.pos_fname;
413411
Log_.warning ~loc
414412
(DeadWarning
415413
{
@@ -553,13 +551,12 @@ module Decl = struct
553551
&& (match decl.path with
554552
| name :: _ when name |> Name.isUnderscore -> Config.reportUnderscore
555553
| _ -> true)
556-
&& (Config.reportTransitive || not (hasRefBelow ()))
554+
&& (runConfig.transitive || not (hasRefBelow ()))
557555
in
558556
if shouldEmitWarning then (
559-
if Config.reportTransitive then
560-
decl.path
561-
|> Path.toModuleName ~isType:(decl.declKind |> DeclKind.isType)
562-
|> DeadModules.checkModuleDead ~fileName:decl.pos.pos_fname;
557+
decl.path
558+
|> Path.toModuleName ~isType:(decl.declKind |> DeclKind.isType)
559+
|> DeadModules.checkModuleDead ~fileName:decl.pos.pos_fname;
563560
emitWarning ~decl ~message name)
564561
end
565562

analysis/reanalyze/src/DeadModules.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let active () = true
1+
let active () = RunConfig.runConfig.transitive
22
let table = Hashtbl.create 1
33

44
let markDead ~isType ~loc path =

analysis/reanalyze/src/Paths.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ module Config = struct
7373
(* if no "analysis" specified, default to dce *)
7474
RunConfig.dce ()
7575

76+
let readTransitive conf =
77+
match Json.get "transitive" conf with
78+
| Some True -> RunConfig.transitive true
79+
| Some False -> RunConfig.transitive false
80+
| _ -> ()
81+
7682
(* Read the config from bsconfig.json and apply it to runConfig and suppress and unsuppress *)
7783
let processBsconfig () =
7884
Lazy.force setReScriptProjectRoot;
@@ -87,7 +93,8 @@ module Config = struct
8793
| Some conf ->
8894
readSuppress conf;
8995
readUnsuppress conf;
90-
readAnalysis conf
96+
readAnalysis conf;
97+
readTransitive conf
9198
| None ->
9299
(* if no "analysis" specified, default to dce *)
93100
RunConfig.dce ()))

analysis/reanalyze/src/RunConfig.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type t = {
55
mutable projectRoot: string;
66
mutable suppress: string list;
77
mutable termination: bool;
8+
mutable transitive: bool;
89
mutable unsuppress: string list;
910
}
1011

@@ -16,6 +17,7 @@ let runConfig =
1617
projectRoot = "";
1718
suppress = [];
1819
termination = false;
20+
transitive = true;
1921
unsuppress = [];
2022
}
2123

@@ -27,3 +29,5 @@ let all () =
2729
let dce () = runConfig.dce <- true
2830
let exception_ () = runConfig.exception_ <- true
2931
let termination () = runConfig.termination <- true
32+
33+
let transitive b = runConfig.transitive <- b
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
DCE src/Dce.res
2-
issues:0
2+
issues:2
33

0 commit comments

Comments
 (0)