Skip to content

Commit

Permalink
Enhancements to import linting
Browse files Browse the repository at this point in the history
  • Loading branch information
garyb committed Jan 10, 2016
1 parent 3eef41d commit d9d397e
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 88 deletions.
4 changes: 4 additions & 0 deletions src/Language/PureScript/AST/Declarations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ isImplicit :: ImportDeclarationType -> Bool
isImplicit Implicit = True
isImplicit _ = False

isExplicit :: ImportDeclarationType -> Bool
isExplicit (Explicit _) = True
isExplicit _ = False

-- |
-- The data type of declarations
--
Expand Down
15 changes: 15 additions & 0 deletions src/Language/PureScript/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ data SimpleErrorMessage
| DuplicateExportRef String
| IntOutOfRange Integer String Integer Integer
| RedundantEmptyHidingImport ModuleName
| ImplicitQualifiedImport ModuleName ModuleName [DeclarationRef]
| ImplicitImport ModuleName [DeclarationRef]
| HidingImport ModuleName [DeclarationRef]
| CaseBinderLengthDiffers Int [Binder]
deriving (Show)

Expand Down Expand Up @@ -309,7 +311,9 @@ errorCode em = case unwrapErrorMessage em of
DuplicateExportRef{} -> "DuplicateExportRef"
IntOutOfRange{} -> "IntOutOfRange"
RedundantEmptyHidingImport{} -> "RedundantEmptyHidingImport"
ImplicitQualifiedImport{} -> "ImplicitQualifiedImport"
ImplicitImport{} -> "ImplicitImport"
HidingImport{} -> "HidingImport"
CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"

-- |
Expand Down Expand Up @@ -858,11 +862,22 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
renderSimpleErrorMessage (RedundantEmptyHidingImport mn) =
line $ "The import for module " ++ runModuleName mn ++ " is redundant as all members have been explicitly hidden."

renderSimpleErrorMessage (ImplicitQualifiedImport importedModule asModule refs) =
paras [ line $ "Module " ++ runModuleName importedModule ++ " was imported as " ++ runModuleName asModule ++ " with unspecified imports."
, line $ "As there are multiple modules being imported as " ++ runModuleName asModule ++ ", consider using the explicit form:"
, indent $ line $ "import " ++ runModuleName importedModule ++ " (" ++ intercalate ", " (map prettyPrintRef refs) ++ ") as " ++ runModuleName asModule
]

renderSimpleErrorMessage (ImplicitImport mn refs) =
paras [ line $ "Module " ++ runModuleName mn ++ " has unspecified imports, consider using the explicit form: "
, indent $ line $ "import " ++ runModuleName mn ++ " (" ++ intercalate ", " (map prettyPrintRef refs) ++ ")"
]

renderSimpleErrorMessage (HidingImport mn refs) =
paras [ line $ "Module " ++ runModuleName mn ++ " has unspecified imports, consider using the inclusive form: "
, indent $ line $ "import " ++ runModuleName mn ++ " (" ++ intercalate ", " (map prettyPrintRef refs) ++ ")"
]

renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
paras $ [ line $ "Binder list length differs in case alternative:"
, indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
Expand Down

0 comments on commit d9d397e

Please sign in to comment.