git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Import suggestions for UnusedDctorImport's (#2282)
0213e0bSimon Van Casteren
src/Language/PureScript/AST/Declarations.hs+2−2
@@ -108,8 +108,8 @@ data SimpleErrorMessage
108 | ImportHidingModule ModuleName
108 | ImportHidingModule ModuleName
109 | UnusedImport ModuleName
109 | UnusedImport ModuleName
110 | UnusedExplicitImport ModuleName [String] (Maybe ModuleName) [DeclarationRef]
110 | UnusedExplicitImport ModuleName [String] (Maybe ModuleName) [DeclarationRef]
111− | UnusedDctorImport (ProperName 'TypeName)
111+ | UnusedDctorImport ModuleName (ProperName 'TypeName) (Maybe ModuleName) [DeclarationRef]
112− | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
112+ | UnusedDctorExplicitImport ModuleName (ProperName 'TypeName) [ProperName 'ConstructorName] (Maybe ModuleName) [DeclarationRef]
113 | DuplicateSelectiveImport ModuleName
113 | DuplicateSelectiveImport ModuleName
114 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
114 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
115 | DuplicateImportRef Name
115 | DuplicateImportRef Name
src/Language/PureScript/Errors.hs+13−5
@@ -288,6 +288,8 @@ errorSuggestion err = case err of
288 UnusedImport{} -> emptySuggestion
288 UnusedImport{} -> emptySuggestion
289 DuplicateImport{} -> emptySuggestion
289 DuplicateImport{} -> emptySuggestion
290 UnusedExplicitImport mn _ qual refs -> suggest $ importSuggestion mn refs qual
290 UnusedExplicitImport mn _ qual refs -> suggest $ importSuggestion mn refs qual
291+ UnusedDctorImport mn _ qual refs -> suggest $ importSuggestion mn refs qual
292+ UnusedDctorExplicitImport mn _ _ qual refs -> suggest $ importSuggestion mn refs qual
291 ImplicitImport mn refs -> suggest $ importSuggestion mn refs Nothing
293 ImplicitImport mn refs -> suggest $ importSuggestion mn refs Nothing
292 ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
294 ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
293 HidingImport mn refs -> suggest $ importSuggestion mn refs Nothing
295 HidingImport mn refs -> suggest $ importSuggestion mn refs Nothing
@@ -756,12 +758,18 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
756 , line "It could be replaced with:"
758 , line "It could be replaced with:"
757 , indent $ line $ markCode $ showSuggestion msg ]
759 , indent $ line $ markCode $ showSuggestion msg ]
758
760
759− renderSimpleErrorMessage (UnusedDctorImport name) =
761+ renderSimpleErrorMessage msg@(UnusedDctorImport mn name _ _) =
760− line $ "The import of type " ++ markCode (runProperName name) ++ " includes data constructors but only the type is used"
762+ paras [line $ "The import of type " ++ markCode (runProperName name)
763+ ++ " from module " ++ markCode (runModuleName mn) ++ " includes data constructors but only the type is used"
764+ , line "It could be replaced with:"
765+ , indent $ line $ markCode $ showSuggestion msg ]
761
766
762− renderSimpleErrorMessage (UnusedDctorExplicitImport name names) =
767+ renderSimpleErrorMessage msg@(UnusedDctorExplicitImport mn name names _ _) =
763− paras [ line $ "The import of type " ++ markCode (runProperName name) ++ " includes the following unused data constructors:"
768+ paras [ line $ "The import of type " ++ markCode (runProperName name)
769+ ++ " from module " ++ markCode (runModuleName mn) ++ " includes the following unused data constructors:"
764− , indent $ paras $ map (line . markCode . runProperName) names ]
770+ , indent $ paras $ map (line . markCode . runProperName) names
771+ , line "It could be replaced with:"
772+ , indent $ line $ markCode $ showSuggestion msg ]
765
773
766 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
774 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
767 line $ "There is an existing import of " ++ markCode (runModuleName name) ++ ", consider merging the import lists"
775 line $ "There is an existing import of " ++ markCode (runModuleName name) ++ ", consider merging the import lists"
src/Language/PureScript/Linter/Imports.hs+2−2
@@ -245,10 +245,10 @@ lintImportDecl env mni qualifierName names declType allowImplicit =
245 -- If we've not already warned a type is unused, check its data constructors
245 -- If we've not already warned a type is unused, check its data constructors
246 unless' (runProperName tn `notElem` usedNames) $
246 unless' (runProperName tn `notElem` usedNames) $
247 case (c, dctors `intersect` allCtors) of
247 case (c, dctors `intersect` allCtors) of
248− (_, []) | c /= Just [] -> warn (UnusedDctorImport tn)
248+ (_, []) | c /= Just [] -> warn (UnusedDctorImport mni tn qualifierName allRefs)
249 (Just ctors, dctors') ->
249 (Just ctors, dctors') ->
250 let ddiff = ctors \\ dctors'
250 let ddiff = ctors \\ dctors'
251− in unless' (null ddiff) $ warn $ UnusedDctorExplicitImport tn ddiff
251+ in unless' (null ddiff) $ warn $ UnusedDctorExplicitImport mni tn ddiff qualifierName allRefs
252 _ -> return False
252 _ -> return False
253
253
254 return (didWarn || or didWarn')
254 return (didWarn || or didWarn')