{-# LANGUAGE CPP #-}
module Stan.Inspection.Partial
(
stan0001
, stan0002
, stan0003
, stan0004
, stan0005
, stan0006
, stan0007
, stan0008
, stan0009
, stan0010
, stan0011
, stan0012
, stan0013
, stan0014
, stan0015
, stan0016
, stan0017
, stan0018
, stan0019
, stan0020
, stan0021
, partialInspectionsMap
) where
import Prelude hiding ((&&&))
import Relude.Extra.Lens ((%~), (.~))
import Relude.Extra.Tuple (fmapToFst)
import Stan.Core.Id (Id (..))
import Stan.Inspection (Inspection (..), InspectionAnalysis (..), InspectionsMap, analysisL,
categoryL, descriptionL, solutionL)
import Stan.NameMeta (NameMeta (..), baseNameFrom, mkBaseFoldableMeta, mkBaseListMeta,
mkBaseOldListMeta)
import Stan.Pattern.Ast (PatternAst (PatternAstName), namesToPatternAst)
import Stan.Pattern.Edsl (PatternBool (..))
import Stan.Pattern.Type (PatternType (..), integerPattern, listFunPattern, listPattern,
naturalPattern, nonEmptyPattern, (|->))
import Stan.Severity (Severity (..))
import qualified Stan.Category as Category
partialInspectionsMap :: InspectionsMap
partialInspectionsMap :: InspectionsMap
partialInspectionsMap = [Item InspectionsMap] -> InspectionsMap
forall l. IsList l => [Item l] -> l
fromList ([Item InspectionsMap] -> InspectionsMap)
-> [Item InspectionsMap] -> InspectionsMap
forall a b. (a -> b) -> a -> b
$ (Inspection -> Id Inspection)
-> [Inspection] -> [(Id Inspection, Inspection)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f (b, a)
fmapToFst Inspection -> Id Inspection
inspectionId
[ Inspection
stan0001
, Inspection
stan0002
, Inspection
stan0003
, Inspection
stan0004
, Inspection
stan0005
, Inspection
stan0006
, Inspection
stan0007
, Inspection
stan0008
, Inspection
stan0009
, Inspection
stan0010
, Inspection
stan0011
, Inspection
stan0012
, Inspection
stan0013
, Inspection
stan0014
, Inspection
stan0015
, Inspection
stan0016
, Inspection
stan0017
, Inspection
stan0018
, Inspection
stan0019
, Inspection
stan0020
, Inspection
stan0021
]
mkPartialInspectionPattern
:: Id Inspection
-> NameMeta
-> PatternType
-> Text
-> Inspection
mkPartialInspectionPattern :: Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern Id Inspection
insId nameMeta :: NameMeta
nameMeta@NameMeta{Text
ModuleName
nameMetaPackage :: Text
nameMetaModuleName :: ModuleName
nameMetaName :: Text
nameMetaPackage :: NameMeta -> Text
nameMetaModuleName :: NameMeta -> ModuleName
nameMetaName :: NameMeta -> Text
..} PatternType
pat Text
typeName = Inspection
{ inspectionId :: Id Inspection
inspectionId = Id Inspection
insId
, inspectionName :: Text
inspectionName = Text
"Partial: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
nameMetaPackage Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
nameMetaName
, inspectionDescription :: Text
inspectionDescription = Text -> Text -> Text
usage Text
nameMetaName Text
typeName
, inspectionSolution :: [Text]
inspectionSolution = []
, inspectionCategory :: NonEmpty Category
inspectionCategory = OneItem (NonEmpty Category) -> NonEmpty Category
forall x. One x => OneItem x -> x
one OneItem (NonEmpty Category)
Category
Category.partial
, inspectionSeverity :: Severity
inspectionSeverity = Severity
Warning
, inspectionAnalysis :: InspectionAnalysis
inspectionAnalysis = PatternAst -> InspectionAnalysis
FindAst (PatternAst -> InspectionAnalysis)
-> PatternAst -> InspectionAnalysis
forall a b. (a -> b) -> a -> b
$ NameMeta -> PatternType -> PatternAst
PatternAstName NameMeta
nameMeta PatternType
pat
}
mkPartialInspection
:: Id Inspection
-> NameMeta
-> Text
-> Inspection
mkPartialInspection :: Id Inspection -> NameMeta -> Text -> Inspection
mkPartialInspection Id Inspection
insId NameMeta
nameMeta =
Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern Id Inspection
insId NameMeta
nameMeta PatternType
forall a. PatternBool a => a
(?)
usage :: Text -> Text -> Text
usage :: Text -> Text -> Text
usage Text
funName Text
forWhat =
Text
"Usage of partial function '" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
funName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"' for " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
forWhat
mkPartialInspectionList :: Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList :: Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList Id Inspection
insId NameMeta
nameMeta = Id Inspection -> NameMeta -> Text -> Inspection
mkPartialInspection Id Inspection
insId NameMeta
nameMeta Text
"lists"
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& (NonEmpty Category -> f (NonEmpty Category))
-> Inspection -> f Inspection
Lens' Inspection (NonEmpty Category)
categoryL Lens' Inspection (NonEmpty Category)
-> (NonEmpty Category -> NonEmpty Category)
-> Inspection
-> Inspection
forall s a. Lens' s a -> (a -> a) -> s -> s
%~ (NonEmpty Category -> NonEmpty Category -> NonEmpty Category
forall a. Semigroup a => a -> a -> a
<> OneItem (NonEmpty Category) -> NonEmpty Category
forall x. One x => OneItem x -> x
one OneItem (NonEmpty Category)
Category
Category.list)
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& ([Text] -> f [Text]) -> Inspection -> f Inspection
Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~
[ Text
"Replace list with 'NonEmpty' from 'Data.List.NonEmpty'"
, Text
"Use explicit pattern-matching over lists"
]
mkPartialInspectionEnum :: Id Inspection -> Text -> PatternType -> [Text] -> Inspection
mkPartialInspectionEnum :: Id Inspection -> Text -> PatternType -> [Text] -> Inspection
mkPartialInspectionEnum Id Inspection
insId Text
funName PatternType
pat [Text]
solution =
Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern Id Inspection
insId NameMeta
enumMeta PatternType
pat Text
""
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& (Text -> f Text) -> Inspection -> f Inspection
Lens' Inspection Text
descriptionL Lens' Inspection Text -> Text -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~ Text -> Text -> Text
usage Text
funName Text
"enumerable types"
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& ([Text] -> f [Text]) -> Inspection -> f Inspection
Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~ [Text]
solution
where
enumMeta :: NameMeta
enumMeta :: NameMeta
enumMeta = Text
funName Text -> ModuleName -> NameMeta
`baseNameFrom` ModuleName
"GHC.Enum"
stan0001 :: Inspection
stan0001 :: Inspection
stan0001 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0001") (Text -> NameMeta
mkBaseListMeta Text
"head")
stan0002 :: Inspection
stan0002 :: Inspection
stan0002 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0002") (Text -> NameMeta
mkBaseListMeta Text
"tail")
stan0003 :: Inspection
stan0003 :: Inspection
stan0003 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0003") (Text -> NameMeta
mkBaseListMeta Text
"init")
stan0004 :: Inspection
stan0004 :: Inspection
stan0004 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0004") (Text -> NameMeta
mkBaseListMeta Text
"last")
stan0005 :: Inspection
stan0005 :: Inspection
stan0005 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0005") (Text -> NameMeta
mkBaseListMeta Text
"!!")
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& ([Text] -> f [Text]) -> Inspection -> f Inspection
Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~ []
stan0006 :: Inspection
stan0006 :: Inspection
stan0006 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0006") (Text -> NameMeta
mkBaseListMeta Text
"cycle")
stan0007 :: Inspection
stan0007 :: Inspection
stan0007 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0007") (Text -> NameMeta
mkBaseOldListMeta Text
"genericIndex")
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& ([Text] -> f [Text]) -> Inspection -> f Inspection
Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~ []
stan0008 :: Inspection
stan0008 :: Inspection
stan0008 = Id Inspection -> NameMeta -> Text -> Inspection
mkPartialInspection (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0008") NameMeta
fromJustNameMeta Text
"'Maybe'"
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& ([Text] -> f [Text]) -> Inspection -> f Inspection
Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~
[ Text
"Use explicit pattern-matching over Maybe"
, Text
"Use one of the standard functions: 'maybe', 'fromMaybe'"
]
where
fromJustNameMeta :: NameMeta
fromJustNameMeta :: NameMeta
fromJustNameMeta = Text
"fromJust" Text -> ModuleName -> NameMeta
`baseNameFrom` ModuleName
"Data.Maybe"
stan0009 :: Inspection
stan0009 :: Inspection
stan0009 = Id Inspection -> NameMeta -> Text -> Inspection
mkPartialInspection (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0009") NameMeta
readNameMeta Text
""
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& (Text -> f Text) -> Inspection -> f Inspection
Lens' Inspection Text
descriptionL Lens' Inspection Text -> Text -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~ Text -> Text -> Text
usage Text
"read" Text
"parsing 'String'"
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& ([Text] -> f [Text]) -> Inspection -> f Inspection
Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~
[ Text
"Use 'readMaybe' or 'readEither' to handle failed parsing"
]
where
readNameMeta :: NameMeta
readNameMeta :: NameMeta
readNameMeta = Text
"read" Text -> ModuleName -> NameMeta
`baseNameFrom` ModuleName
"Text.Read"
stan0010 :: Inspection
stan0010 :: Inspection
stan0010 = Id Inspection -> Text -> PatternType -> [Text] -> Inspection
mkPartialInspectionEnum
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0010")
Text
"succ"
(PatternType -> PatternType
forall a. PatternBool a => a -> a
neg (PatternType
integerPattern PatternType -> PatternType -> PatternType
|-> PatternType
forall a. PatternBool a => a
(?)) PatternType -> PatternType -> PatternType
forall a. PatternBool a => a -> a -> a
&&& PatternType -> PatternType
forall a. PatternBool a => a -> a
neg (PatternType
naturalPattern PatternType -> PatternType -> PatternType
|-> PatternType
forall a. PatternBool a => a
(?)))
[ Text
"Use '(+ 1)' for integral types (but be aware of arithmetic overflow)"
, Text
"{Extra dependency} Use 'next' from 'Relude.Extra.Enum' in 'relude'"
]
stan0011 :: Inspection
stan0011 :: Inspection
stan0011 = Id Inspection -> Text -> PatternType -> [Text] -> Inspection
mkPartialInspectionEnum
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0011")
Text
"pred"
(PatternType -> PatternType
forall a. PatternBool a => a -> a
neg (PatternType
integerPattern PatternType -> PatternType -> PatternType
|-> PatternType
forall a. PatternBool a => a
(?)))
[ Text
"Use '(- 1)' for integral types (but be aware of arithmetic overflow)"
, Text
"{Extra dependency} Use 'prev' from 'Relude.Extra.Enum' in 'relude'"
]
stan0012 :: Inspection
stan0012 :: Inspection
stan0012 = Id Inspection -> Text -> PatternType -> [Text] -> Inspection
mkPartialInspectionEnum (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0012") Text
"toEnum" PatternType
forall a. PatternBool a => a
(?)
[ Text
"{Extra dependency} Use 'safeToEnum' from 'Relude.Extra.Enum' in 'relude'"
]
stan0013 :: Inspection
stan0013 :: Inspection
stan0013 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0013") (Text -> NameMeta
mkBaseFoldableMeta Text
"maximum") PatternType
listFunPattern Text
""
stan0014 :: Inspection
stan0014 :: Inspection
stan0014 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0014") (Text -> NameMeta
mkBaseFoldableMeta Text
"minimum") PatternType
listFunPattern Text
""
orderingFunPattern :: PatternType
orderingFunPattern :: PatternType
orderingFunPattern = PatternType
forall a. PatternBool a => a
(?) PatternType -> PatternType -> PatternType
|-> PatternType
listFunPattern
stan0015 :: Inspection
stan0015 :: Inspection
stan0015 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0015") (Text -> NameMeta
mkBaseFoldableMeta Text
"maximumBy") PatternType
orderingFunPattern Text
""
stan0016 :: Inspection
stan0016 :: Inspection
stan0016 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0016") (Text -> NameMeta
mkBaseFoldableMeta Text
"minimumBy") PatternType
orderingFunPattern Text
""
stan0017 :: Inspection
stan0017 :: Inspection
stan0017 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0017") (Text -> NameMeta
mkBaseFoldableMeta Text
"foldl1") PatternType
orderingFunPattern Text
""
stan0018 :: Inspection
stan0018 :: Inspection
stan0018 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0018") (Text -> NameMeta
mkBaseListMeta Text
"foldl1'")
stan0019 :: Inspection
stan0019 :: Inspection
stan0019 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0019") (Text -> NameMeta
mkBaseFoldableMeta Text
"foldr1") PatternType
orderingFunPattern Text
""
stan0020 :: Inspection
stan0020 :: Inspection
stan0020 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern (Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0020") NameMeta
exts PatternType
pat Text
""
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& (InspectionAnalysis -> f InspectionAnalysis)
-> Inspection -> f Inspection
Lens' Inspection InspectionAnalysis
analysisL Lens' Inspection InspectionAnalysis
-> InspectionAnalysis -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~ PatternAst -> InspectionAnalysis
FindAst (NonEmpty (NameMeta, PatternType) -> PatternAst
namesToPatternAst (NonEmpty (NameMeta, PatternType) -> PatternAst)
-> NonEmpty (NameMeta, PatternType) -> PatternAst
forall a b. (a -> b) -> a -> b
$ (NameMeta
exts, PatternType
pat) (NameMeta, PatternType)
-> [(NameMeta, PatternType)] -> NonEmpty (NameMeta, PatternType)
forall a. a -> [a] -> NonEmpty a
:| [(NameMeta
ne, PatternType
pat)])
where
pat :: PatternType
pat = PatternType
listPattern PatternType -> PatternType -> PatternType
|-> PatternType
nonEmptyPattern
#if __GLASGOW_HASKELL__ < 904
exts = "fromList" `baseNameFrom` "GHC.Exts"
#else
exts :: NameMeta
exts = Text
"fromList" Text -> ModuleName -> NameMeta
`baseNameFrom` ModuleName
"GHC.IsList"
#endif
ne :: NameMeta
ne = Text
"fromList" Text -> ModuleName -> NameMeta
`baseNameFrom` ModuleName
"Data.List.NonEmpty"
stan0021 :: Inspection
stan0021 :: Inspection
stan0021 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id Text
"STAN-0021")
(Text
"fromInteger" Text -> ModuleName -> NameMeta
`baseNameFrom` ModuleName
"GHC.Num")
(PatternType
integerPattern PatternType -> PatternType -> PatternType
|-> PatternType
naturalPattern)
Text
""