|
1 | 1 | open Ppxlib; |
2 | 2 |
|
3 | | -let lintExhaustiveDeps = ref(true); |
4 | | -let lintOrder = ref(true); |
| 3 | +let exhaustiveDeps = ref(true); |
| 4 | +let orderOfHooks = ref(true); |
5 | 5 |
|
6 | 6 | let raiseWithLoc = (~loc, msg, variables) => |
7 | 7 | Location.raise_errorf(~loc, msg, variables) |> ignore; |
@@ -106,10 +106,8 @@ let useEffectLint = (e: Parsetree.expression) => |
106 | 106 | switch (e.pexp_desc) { |
107 | 107 | | Pexp_apply( |
108 | 108 | { |
109 | | - pexp_desc: Pexp_ident({loc: _loc, txt: _, _}), |
110 | | - pexp_loc: _, |
111 | | - pexp_attributes: _, |
112 | | - pexp_loc_stack: _, |
| 109 | + pexp_desc: Pexp_ident(_), |
| 110 | + _, |
113 | 111 | }, |
114 | 112 | args, |
115 | 113 | ) => |
@@ -156,7 +154,7 @@ let useEffectLint = (e: Parsetree.expression) => |
156 | 154 | }; |
157 | 155 |
|
158 | 156 | let useEffectExpand = (e: Parsetree.expression) => |
159 | | - if (lintExhaustiveDeps^ == true) { |
| 157 | + if (exhaustiveDeps^ == true) { |
160 | 158 | useEffectLint(e); |
161 | 159 | } else { |
162 | 160 | None; |
@@ -286,29 +284,30 @@ let conditionalHooksLinter = (structure: Parsetree.structure) => { |
286 | 284 | ) |
287 | 285 | ); |
288 | 286 |
|
289 | | - lintOrder^ == true ? lintErrors : (); |
| 287 | + orderOfHooks^ == true ? lintErrors : (); |
290 | 288 |
|
291 | 289 | structure; |
292 | 290 | }; |
293 | 291 |
|
294 | 292 | let () = |
295 | 293 | Driver.add_arg( |
296 | 294 | "-exhaustive-deps", |
297 | | - Set(lintExhaustiveDeps), |
| 295 | + Set(exhaustiveDeps), |
298 | 296 | ~doc="If set, checks for 'exhaustive dependencies' in UseEffects", |
299 | 297 | ); |
300 | 298 |
|
301 | 299 | let () = |
302 | 300 | Driver.add_arg( |
303 | | - "-order-of-hooks", |
304 | | - Set(lintOrder), |
| 301 | + "-orderOfHooks-of-hooks", |
| 302 | + Set(orderOfHooks), |
305 | 303 | ~doc="If set, checks for hooks being called at the top level", |
306 | 304 | ); |
307 | 305 |
|
308 | 306 | let () = |
309 | 307 | Driver.register_transformation( |
310 | 308 | ~impl=conditionalHooksLinter, |
311 | 309 | ~rules=[ |
| 310 | + /* useEffect */ |
312 | 311 | Context_free.Rule.special_function("React.useEffect", useEffectExpand), |
313 | 312 | Context_free.Rule.special_function("useEffect", useEffectExpand), |
314 | 313 | Context_free.Rule.special_function("React.useEffect1", useEffectExpand), |
|
0 commit comments