git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Import suggestions for UnusedDctorImport's (#2282)
commit0213e0b916454e0d66a2089c35c217ef74f665df authorSimon Van Casteren <simon.van.casteren@gmail.com> dateSat 20 Aug 2016, 21:58 (10 years ago) parent8dab1e8
3 files changed+17−9
src/Language/PureScript/AST/Declarations.hs+2−2 src/Language/PureScript/Errors.hs+13−5 src/Language/PureScript/Linter/Imports.hs+2−2
src/Language/PureScript/AST/Declarations.hs+2−2
@@ -108,8 +108,8 @@ data SimpleErrorMessage
108108 | ImportHidingModule ModuleName
109109 | UnusedImport ModuleName
110110 | UnusedExplicitImport ModuleName [String] (Maybe ModuleName) [DeclarationRef]
111− | UnusedDctorImport (ProperName 'TypeName)
112− | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
111+ | UnusedDctorImport ModuleName (ProperName 'TypeName) (Maybe ModuleName) [DeclarationRef]
112+ | UnusedDctorExplicitImport ModuleName (ProperName 'TypeName) [ProperName 'ConstructorName] (Maybe ModuleName) [DeclarationRef]
113113 | DuplicateSelectiveImport ModuleName
114114 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
115115 | DuplicateImportRef Name
src/Language/PureScript/Errors.hs+13−5
@@ -288,6 +288,8 @@ errorSuggestion err = case err of
288288 UnusedImport{} -> emptySuggestion
289289 DuplicateImport{} -> emptySuggestion
290290 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
291293 ImplicitImport mn refs -> suggest $ importSuggestion mn refs Nothing
292294 ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
293295 HidingImport mn refs -> suggest $ importSuggestion mn refs Nothing
@@ -756,12 +758,18 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
756758 , line "It could be replaced with:"
757759 , indent $ line $ markCode $ showSuggestion msg ]
758760
759− renderSimpleErrorMessage (UnusedDctorImport name) =
760− line $ "The import of type " ++ markCode (runProperName name) ++ " includes data constructors but only the type is used"
761+ renderSimpleErrorMessage msg@(UnusedDctorImport mn name _ _) =
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 ]
761766
762− renderSimpleErrorMessage (UnusedDctorExplicitImport name names) =
763− paras [ line $ "The import of type " ++ markCode (runProperName name) ++ " includes the following unused data constructors:"
764− , indent $ paras $ map (line . markCode . runProperName) names ]
767+ renderSimpleErrorMessage msg@(UnusedDctorExplicitImport mn name names _ _) =
768+ paras [ line $ "The import of type " ++ markCode (runProperName name)
769+ ++ " from module " ++ markCode (runModuleName mn) ++ " includes the following unused data constructors:"
770+ , indent $ paras $ map (line . markCode . runProperName) names
771+ , line "It could be replaced with:"
772+ , indent $ line $ markCode $ showSuggestion msg ]
765773
766774 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
767775 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 =
245245 -- If we've not already warned a type is unused, check its data constructors
246246 unless' (runProperName tn `notElem` usedNames) $
247247 case (c, dctors `intersect` allCtors) of
248− (_, []) | c /= Just [] -> warn (UnusedDctorImport tn)
248+ (_, []) | c /= Just [] -> warn (UnusedDctorImport mni tn qualifierName allRefs)
249249 (Just ctors, dctors') ->
250250 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
252252 _ -> return False
253253
254254 return (didWarn || or didWarn')