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 insId :: Id Inspection
insId nameMeta :: NameMeta
nameMeta@NameMeta{..} pat :: PatternType
pat typeName :: Text
typeName = $WInspection :: Id Inspection
-> Text
-> Text
-> [Text]
-> NonEmpty Category
-> Severity
-> InspectionAnalysis
-> Inspection
Inspection
{ inspectionId :: Id Inspection
inspectionId = Id Inspection
insId
, inspectionName :: Text
inspectionName = "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
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 insId :: Id Inspection
insId nameMeta :: 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 funName :: Text
funName forWhat :: Text
forWhat =
"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
<> "' for " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
forWhat
mkPartialInspectionList :: Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList :: Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList insId :: Id Inspection
insId nameMeta :: NameMeta
nameMeta = Id Inspection -> NameMeta -> Text -> Inspection
mkPartialInspection Id Inspection
insId NameMeta
nameMeta "lists"
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& 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
& Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~
[ "Replace list with 'NonEmpty' from 'Data.List.NonEmpty'"
, "Use explicit pattern-matching over lists"
]
mkPartialInspectionEnum :: Id Inspection -> Text -> PatternType -> [Text] -> Inspection
mkPartialInspectionEnum :: Id Inspection -> Text -> PatternType -> [Text] -> Inspection
mkPartialInspectionEnum insId :: Id Inspection
insId funName :: Text
funName pat :: PatternType
pat solution :: [Text]
solution =
Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern Id Inspection
insId NameMeta
enumMeta PatternType
pat ""
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& 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 "enumerable types"
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& 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` "GHC.Enum"
stan0001 :: Inspection
stan0001 :: Inspection
stan0001 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0001") (Text -> NameMeta
mkBaseListMeta "head")
stan0002 :: Inspection
stan0002 :: Inspection
stan0002 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0002") (Text -> NameMeta
mkBaseListMeta "tail")
stan0003 :: Inspection
stan0003 :: Inspection
stan0003 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0003") (Text -> NameMeta
mkBaseListMeta "init")
stan0004 :: Inspection
stan0004 :: Inspection
stan0004 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0004") (Text -> NameMeta
mkBaseListMeta "last")
stan0005 :: Inspection
stan0005 :: Inspection
stan0005 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0005") (Text -> NameMeta
mkBaseListMeta "!!")
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& 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 "STAN-0006") (Text -> NameMeta
mkBaseListMeta "cycle")
stan0007 :: Inspection
stan0007 :: Inspection
stan0007 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0007") (Text -> NameMeta
mkBaseOldListMeta "genericIndex")
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& 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 "STAN-0008") NameMeta
fromJustNameMeta "'Maybe'"
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~
[ "Use explicit pattern-matching over Maybe"
, "Use one of the standard functions: 'maybe', 'fromMaybe'"
]
where
fromJustNameMeta :: NameMeta
fromJustNameMeta :: NameMeta
fromJustNameMeta = "fromJust" Text -> ModuleName -> NameMeta
`baseNameFrom` "Data.Maybe"
stan0009 :: Inspection
stan0009 :: Inspection
stan0009 = Id Inspection -> NameMeta -> Text -> Inspection
mkPartialInspection (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0009") NameMeta
readNameMeta ""
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& Lens' Inspection Text
descriptionL Lens' Inspection Text -> Text -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~ Text -> Text -> Text
usage "read" "parsing 'String'"
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& Lens' Inspection [Text]
solutionL Lens' Inspection [Text] -> [Text] -> Inspection -> Inspection
forall s a. Lens' s a -> a -> s -> s
.~
[ "Use 'readMaybe' or 'readEither' to handle failed parsing"
]
where
readNameMeta :: NameMeta
readNameMeta :: NameMeta
readNameMeta = "read" Text -> ModuleName -> NameMeta
`baseNameFrom` "Text.Read"
stan0010 :: Inspection
stan0010 :: Inspection
stan0010 = Id Inspection -> Text -> PatternType -> [Text] -> Inspection
mkPartialInspectionEnum
(Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0010")
"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
(?)))
[ "Use '(+ 1)' for integral types (but be aware of arithmetic overflow)"
, "{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 "STAN-0011")
"pred"
(PatternType -> PatternType
forall a. PatternBool a => a -> a
neg (PatternType
integerPattern PatternType -> PatternType -> PatternType
|-> PatternType
forall a. PatternBool a => a
(?)))
[ "Use '(- 1)' for integral types (but be aware of arithmetic overflow)"
, "{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 "STAN-0012") "toEnum" PatternType
forall a. PatternBool a => a
(?)
[ "{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 "STAN-0013") (Text -> NameMeta
mkBaseFoldableMeta "maximum") PatternType
listFunPattern ""
stan0014 :: Inspection
stan0014 :: Inspection
stan0014 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0014") (Text -> NameMeta
mkBaseFoldableMeta "minimum") PatternType
listFunPattern ""
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 "STAN-0015") (Text -> NameMeta
mkBaseFoldableMeta "maximumBy") PatternType
orderingFunPattern ""
stan0016 :: Inspection
stan0016 :: Inspection
stan0016 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0016") (Text -> NameMeta
mkBaseFoldableMeta "minimumBy") PatternType
orderingFunPattern ""
stan0017 :: Inspection
stan0017 :: Inspection
stan0017 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0017") (Text -> NameMeta
mkBaseFoldableMeta "foldl1") PatternType
orderingFunPattern ""
stan0018 :: Inspection
stan0018 :: Inspection
stan0018 = Id Inspection -> NameMeta -> Inspection
mkPartialInspectionList (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0018") (Text -> NameMeta
mkBaseListMeta "foldl1'")
stan0019 :: Inspection
stan0019 :: Inspection
stan0019 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0019") (Text -> NameMeta
mkBaseFoldableMeta "foldr1") PatternType
orderingFunPattern ""
stan0020 :: Inspection
stan0020 :: Inspection
stan0020 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern (Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0020") NameMeta
exts PatternType
pat ""
Inspection -> (Inspection -> Inspection) -> Inspection
forall a b. a -> (a -> b) -> b
& 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
exts :: NameMeta
exts = "fromList" Text -> ModuleName -> NameMeta
`baseNameFrom` "GHC.Exts"
ne :: NameMeta
ne = "fromList" Text -> ModuleName -> NameMeta
`baseNameFrom` "Data.List.NonEmpty"
stan0021 :: Inspection
stan0021 :: Inspection
stan0021 = Id Inspection -> NameMeta -> PatternType -> Text -> Inspection
mkPartialInspectionPattern
(Text -> Id Inspection
forall a. Text -> Id a
Id "STAN-0021")
("fromInteger" Text -> ModuleName -> NameMeta
`baseNameFrom` "GHC.Num")
(PatternType
integerPattern PatternType -> PatternType -> PatternType
|-> PatternType
naturalPattern)
""