@@ -30,6 +30,17 @@ module DisallowStringOfIntRuleWarning =
3030 end )
3131 (TestingLinterOptionsWarning )
3232
33+ module DisallowJsLogRule =
34+ DisallowedFunctionRule. Make
35+ (struct
36+ type options = DisallowedFunctionRule.Options .options
37+
38+ let options =
39+ { DisallowedFunctionRule.Options. disallowed_function= " Js.log"
40+ ; DisallowedFunctionRule.Options. suggested_function= Some " Console.log" }
41+ end )
42+ (TestingLinterOptions )
43+
3344module DisallowInOfStringOptRule =
3445 DisallowedFunctionRule. Make
3546 (struct
@@ -74,6 +85,28 @@ module NoCSSModuleRule =
7485 end )
7586 (TestingLinterOptions )
7687
88+ module DisallowBeltResultRule =
89+ DisallowModuleRule. Make
90+ (struct
91+ type options = DisallowModuleRule.Options .options
92+
93+ let options =
94+ { DisallowModuleRule.Options. disallowed_module= " Belt.Result"
95+ ; DisallowModuleRule.Options. suggested_module= Some " Result" }
96+ end )
97+ (TestingLinterOptions )
98+
99+ module DisallowBeltRule =
100+ DisallowModuleRule. Make
101+ (struct
102+ type options = DisallowModuleRule.Options .options
103+
104+ let options =
105+ { DisallowModuleRule.Options. disallowed_module= " Belt"
106+ ; DisallowModuleRule.Options. suggested_module= Some " Core" }
107+ end )
108+ (TestingLinterOptions )
109+
77110module DisallowedEmbeddedRegexLiteralRule =
78111 DisallowedEmbeddedRegexLiteralRule. Make
79112 (struct
@@ -139,10 +172,10 @@ module Tests = struct
139172 in
140173 match (errors, warnings) with
141174 | [] , [(msg, _); _] ->
142- Alcotest. (check string ) " Same error message" DisallowStringOfIntRule . meta.ruleDescription msg
175+ Alcotest. (check string ) " Same error message" DisallowStringOfIntRuleWarning . meta.ruleDescription msg
143176 | errors , warnings ->
144177 Alcotest. fail
145- ( " Should only have two lint warnings, there were "
178+ ( " Should only have two lint warnings for string_of_int , there were "
146179 ^ string_of_int (List. length errors)
147180 ^ " errors found and "
148181 ^ string_of_int (List. length warnings)
@@ -246,6 +279,44 @@ module Tests = struct
246279 | [_; _] -> Alcotest. (check pass) " Same error message" [] []
247280 | _ -> Alcotest. fail " Should only have two lint error"
248281
282+ let disallow_qualified_function_test () =
283+ let parseResult = parseAst " testData/disallowed_function_rule_test_1.res" in
284+ let errors, _warnings =
285+ Linter. lint [(module DisallowJsLogRule : Rule.HASRULE )] parseResult.ast parseResult.comments
286+ in
287+ match errors with
288+ | [_] -> Alcotest. (check pass) " Same error message" [] []
289+ | errors ->
290+ Alcotest. fail
291+ (" Should only have one lint error, but got " ^ string_of_int (List. length errors) ^ " errors" )
292+
293+ let disallow_module_test_4 () =
294+ let parseResult = parseAst " testData/disallow_module_test_4.res" in
295+ let errors, _warnings =
296+ Linter. lint [(module DisallowBeltResultRule : Rule.HASRULE )] parseResult.ast parseResult.comments
297+ in
298+ match errors with
299+ | [_; _; _; _; _] -> Alcotest. (check pass) " Same error message" [] []
300+ | errors ->
301+ Alcotest. fail
302+ ( " Should have five lint errors (2 Ok + 2 Error in expressions/patterns, plus map function), but \
303+ got "
304+ ^ string_of_int (List. length errors)
305+ ^ " errors" )
306+
307+ let disallow_module_test_5 () =
308+ let parseResult = parseAst " testData/disallow_module_test_5.res" in
309+ let errors, _warnings =
310+ Linter. lint [(module DisallowBeltRule : Rule.HASRULE )] parseResult.ast parseResult.comments
311+ in
312+ match errors with
313+ | [_; _; _] -> Alcotest. (check pass) " Same error message" [] []
314+ | errors ->
315+ Alcotest. fail
316+ ( " Should have three lint errors (Belt.List, Belt.Array, Belt.Option), but got "
317+ ^ string_of_int (List. length errors)
318+ ^ " errors" )
319+
249320 let disallowed_embedded_regex_literal_test () =
250321 let parseResult = parseAst " testData/disallowed_embedded_regex_literal_test.res" in
251322 let errors, _warnings =
@@ -316,7 +387,8 @@ let () =
316387 run " ReScript Linter"
317388 [ ( " Disallow Function Rule"
318389 , [ test_case " Lint only functions" `Quick Tests. disallow_test_1
319- ; test_case " Does not lint variable with the same function name" `Quick Tests. disallow_test_2 ] )
390+ ; test_case " Does not lint variable with the same function name" `Quick Tests. disallow_test_2
391+ ; test_case " Lint qualified functions (Js.log)" `Quick Tests. disallow_qualified_function_test ] )
320392 ; ( " Warning Lint Rule"
321393 , [test_case " Lint only functions (as warning)" `Quick Tests. disallow_test_1_warning] )
322394 ; ( " Disable lint test"
@@ -330,7 +402,9 @@ let () =
330402 ; ( " Disallow module"
331403 , [ test_case " open module" `Quick Tests. disallow_module_test_1
332404 ; test_case " alias module" `Quick Tests. disallow_module_test_2
333- ; test_case " direct access module" `Quick Tests. disallow_module_test_3 ] )
405+ ; test_case " direct access module" `Quick Tests. disallow_module_test_3
406+ ; test_case " qualified module with constructors (Belt.Result)" `Quick Tests. disallow_module_test_4
407+ ; test_case " module prefix matching (Belt.*)" `Quick Tests. disallow_module_test_5 ] )
334408 ; ( " Disallowed embedded regex literal"
335409 , [test_case " Disallowed embedded regex literal" `Quick Tests. disallowed_embedded_regex_literal_test] )
336410 ; (" Disallowed dead code" , [test_case " Disallowed dead code" `Quick Tests. disallowed_dead_code_test]) ]
0 commit comments