Skip to content

Commit ddee958

Browse files
committed
refactor: Rename state
1 parent 606c0ab commit ddee958

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

bin/dune

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
(modules Bin)
44
(public_name react-rules-of-hooks-ppx)
55
(libraries ReactRulesOfHooksPpx.lib)
6-
(ocamlopt_flags (-linkall))
76
(package ReactRulesOfHooksPpx)
87
)
98

109
(executable
1110
(name Standalone)
1211
(modules Standalone)
13-
(public_name react-rules-of-hooks-ppx)
1412
(libraries ReactRulesOfHooksPpx.lib)
15-
(ocamlopt_flags (-linkall))
16-
(package ReactRulesOfHooksPpx)
1713
)

src/Ppx.re

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Ppxlib;
22

3-
let lintExhaustiveDeps = ref(true);
4-
let lintOrder = ref(true);
3+
let exhaustiveDeps = ref(true);
4+
let orderOfHooks = ref(true);
55

66
let raiseWithLoc = (~loc, msg, variables) =>
77
Location.raise_errorf(~loc, msg, variables) |> ignore;
@@ -106,10 +106,8 @@ let useEffectLint = (e: Parsetree.expression) =>
106106
switch (e.pexp_desc) {
107107
| Pexp_apply(
108108
{
109-
pexp_desc: Pexp_ident({loc: _loc, txt: _, _}),
110-
pexp_loc: _,
111-
pexp_attributes: _,
112-
pexp_loc_stack: _,
109+
pexp_desc: Pexp_ident(_),
110+
_,
113111
},
114112
args,
115113
) =>
@@ -156,7 +154,7 @@ let useEffectLint = (e: Parsetree.expression) =>
156154
};
157155

158156
let useEffectExpand = (e: Parsetree.expression) =>
159-
if (lintExhaustiveDeps^ == true) {
157+
if (exhaustiveDeps^ == true) {
160158
useEffectLint(e);
161159
} else {
162160
None;
@@ -286,29 +284,30 @@ let conditionalHooksLinter = (structure: Parsetree.structure) => {
286284
)
287285
);
288286

289-
lintOrder^ == true ? lintErrors : ();
287+
orderOfHooks^ == true ? lintErrors : ();
290288

291289
structure;
292290
};
293291

294292
let () =
295293
Driver.add_arg(
296294
"-exhaustive-deps",
297-
Set(lintExhaustiveDeps),
295+
Set(exhaustiveDeps),
298296
~doc="If set, checks for 'exhaustive dependencies' in UseEffects",
299297
);
300298

301299
let () =
302300
Driver.add_arg(
303-
"-order-of-hooks",
304-
Set(lintOrder),
301+
"-orderOfHooks-of-hooks",
302+
Set(orderOfHooks),
305303
~doc="If set, checks for hooks being called at the top level",
306304
);
307305

308306
let () =
309307
Driver.register_transformation(
310308
~impl=conditionalHooksLinter,
311309
~rules=[
310+
/* useEffect */
312311
Context_free.Rule.special_function("React.useEffect", useEffectExpand),
313312
Context_free.Rule.special_function("useEffect", useEffectExpand),
314313
Context_free.Rule.special_function("React.useEffect1", useEffectExpand),

0 commit comments

Comments
 (0)