@@ -59,27 +59,26 @@ rule badFunctions = emptyRule { onExpr = onExpr }
5959 | Just mods <- Map .lookup { function } badFunctions -> -- This function is on the list of undesirables.
6060 currentModule \m -> do
6161 let report message = reportViolation { source: Just $ rangeOf e, message }
62- case findImport m mod function of
62+ importedFrom = explicitOrQualifiedImport m mod function <|> loneOpenImport m
63+ case importedFrom of
6364 Just imprt -> do -- Found whence this function is imported.
6465 let message =
6566 Map .lookup (Just imprt) mods -- See if we have a message for this specific import.
6667 <|> Map .lookup Nothing mods -- If not, see if we have a module-agnostic message for this function.
6768 report `traverse_` message
69+
6870 Nothing -> -- Couldn't find this function in any imports. It could have been imported via an "open" import.
69- case Map .lookup Nothing mods of
70- Just message -> -- Found a module-agnostic message for this function => report it.
71- report message
72- Nothing -> -- No message found for this function => report all messages just in case.
73- report `traverse_` mods
71+ for_ (Map .lookup Nothing mods) \message -> -- Report a module-agnostic message for this function, if defined.
72+ report message
7473
7574 _ -> do
7675 pure unit
7776
7877 -- Look through imports in the header of the module and find one that either
7978 -- (1) is qualified with the given qualifier `mod` or (2) lists the given
8079 -- identifier `ident` among imported values or operators.
81- findImport :: ∀ e . Module e -> Maybe ModuleName -> String -> Maybe ModuleName
82- findImport (Module { header: ModuleHeader { imports } }) mod ident =
80+ explicitOrQualifiedImport :: ∀ e . Module e -> Maybe ModuleName -> String -> Maybe ModuleName
81+ explicitOrQualifiedImport (Module { header: ModuleHeader { imports } }) mod ident =
8382 imports # findMap \(ImportDecl i@{ module: Name { name } }) -> case i of
8483 { qualified: Just (_ /\ Name { name: qualifier }) }
8584 | Just qualifier == mod
@@ -96,6 +95,18 @@ rule badFunctions = emptyRule { onExpr = onExpr }
9695 sameIdentifier (ImportOp (Name { name: Operator op })) = op == ident
9796 sameIdentifier _ = false
9897
98+ loneOpenImport :: ∀ e . Module e -> Maybe ModuleName
99+ loneOpenImport (Module { header: ModuleHeader { imports } }) =
100+ let candidates =
101+ imports # mapMaybe \(ImportDecl i@{ module: Name { name } }) -> case i of
102+ { qualified: Nothing , names: Nothing } -> Just name
103+ _ -> Nothing
104+
105+ in
106+ case candidates of
107+ [name] -> Just name
108+ _ -> Nothing
109+
99110
100111codec :: CJ.Codec Args
101112codec =
0 commit comments