Copyright | (c) 2020 Kowainik |
---|---|
License | MPL-2.0 |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
stan
runtime configuration that allows customizing the set of
inspections to check the code against.
Synopsis
- data ConfigP (p :: Phase Text) = ConfigP {
- configChecks :: !(p ::- [Check])
- configRemoved :: !(p ::- [Scope])
- configIgnored :: !(p ::- [Id Observation])
- type Config = ConfigP 'Final
- type PartialConfig = ConfigP 'Partial
- data Check = Check {
- checkType :: !CheckType
- checkFilter :: !CheckFilter
- checkScope :: !Scope
- data CheckType
- data CheckFilter
- data Scope
- defaultConfig :: PartialConfig
- mkDefaultChecks :: [FilePath] -> HashMap FilePath (HashSet (Id Inspection))
- finaliseConfig :: PartialConfig -> Trial Text Config
- configToCliCommand :: Config -> Text
- applyConfig :: [FilePath] -> Config -> HashMap FilePath (HashSet (Id Inspection))
- applyChecks :: [FilePath] -> [Check] -> HashMap FilePath (HashSet (Id Inspection))
- applyChecksFor :: HashMap FilePath (HashSet (Id Inspection)) -> [Check] -> HashMap FilePath (HashSet (Id Inspection))
Data types
data ConfigP (p :: Phase Text) Source #
Main configuration type for the following purposes:
- Filtering inspections (including or ignoring) per scope (file, directory, all)
ConfigP | |
|
Instances
Semigroup PartialConfig Source # | |
Defined in Stan.Config (<>) :: PartialConfig -> PartialConfig -> PartialConfig # sconcat :: NonEmpty PartialConfig -> PartialConfig # stimes :: Integral b => b -> PartialConfig -> PartialConfig # | |
(Eq (p ::- [Check]), Eq (p ::- [Scope]), Eq (p ::- [Id Observation])) => Eq (ConfigP p) Source # | |
(Show (p ::- [Check]), Show (p ::- [Scope]), Show (p ::- [Id Observation])) => Show (ConfigP p) Source # | |
type PartialConfig = ConfigP 'Partial Source #
Rule to control the set of inspections per scope.
Check | |
|
Type of Check
: Include
or Exclude
Inspection
s.
Instances
Bounded CheckType Source # | |
Enum CheckType Source # | |
Defined in Stan.Config succ :: CheckType -> CheckType # pred :: CheckType -> CheckType # fromEnum :: CheckType -> Int # enumFrom :: CheckType -> [CheckType] # enumFromThen :: CheckType -> CheckType -> [CheckType] # enumFromTo :: CheckType -> CheckType -> [CheckType] # enumFromThenTo :: CheckType -> CheckType -> CheckType -> [CheckType] # | |
Eq CheckType Source # | |
Show CheckType Source # | |
data CheckFilter Source #
Criterion for inspections filtering.
Instances
Eq CheckFilter Source # | |
Defined in Stan.Config (==) :: CheckFilter -> CheckFilter -> Bool # (/=) :: CheckFilter -> CheckFilter -> Bool # | |
Show CheckFilter Source # | |
Defined in Stan.Config showsPrec :: Int -> CheckFilter -> ShowS # show :: CheckFilter -> String # showList :: [CheckFilter] -> ShowS # |
Where to apply the rule for controlling inspection set.
Default
mkDefaultChecks :: [FilePath] -> HashMap FilePath (HashSet (Id Inspection)) Source #
Final stage
Printing
configToCliCommand :: Config -> Text Source #
Convert TOML configuration to the equivalent CLI command that can be copy-pasted to get the same results as using the TOML config.
ⓘ Reading Configurations from /home/vrom911/Kowainik/stan/.stan.toml ... stan check --exclude --directory=test/ \ check --include \ check --exclude --inspectionId=STAN-0002 \ check --exclude --inspectionId=STAN-0001 --file=src/MyFile.hs remove --file=src/Secret.hs ignore --id="STAN0001-asdfgh42:42"
Apply config
The applyConfig
function transforms the list of rules defined in the
Config
(either via TOML or CLI) to get the list of Inspection
s for
each module.
By default, stan
runs all Inspection
s for all modules in the
Haskell project and outputs all Observation
s it finds. Using
Config
, you can adjust the default setting using your preferences.
Algorithm
The algorithm for figuring out the resulting set of Inspection
s per
module applies each Check
one-by-one in order of their appearance.
When introducing a new Check
in the config, you must always specify
three key-value pairs:
CheckType
— control inclusion and exclusion criteriaCheckFilter
— how to filter inspectionsCheckInspection
: by specificInspection
Id
id = "STAN-0001"
CheckSeverity
: by specificSeverity
severity = "Warning"
CheckCategory
: by specificCategory
category = "Partial"
CheckAll
: applied to allInspection
sfilter = "all"
Scope
— where to apply checkScopeFile
: only to the specific filefile = "src/MyModule.hs"
ScopeDirectory
: to all files in the specified directorydirectory = "text/"
ScopeAll
: to all filesscope = "all"
The algorithm doesn't remove any files or inspections from the consideration completely. So, for example, if you exclude all inspections in a specific file, new inspections can be added for this file later by the follow up rules.
However, if you want to completely remove some files or directory from
analysis, you can use the remove
key:
[[remove]] file = "src/Autogenerated.hs"
Common examples
This section contains examples of custom configuration (in TOML) for common cases.
Exclude all
Inspection
s.[[check]] type = "Exclude" filter = "all" scope = "all"
Exclude all
Inspection
s only for specific file.[[check]] type = "Exclude" filter = "all" file = "src/MyModule.hs"
Exclude a specific
Inspection
in all files:[[check]] type = "Exclude" id = "STAN-0001" scope = "all"
Exclude all
Inspection
s for specific file exceptInspection
s that have a categoryPartial
.# exclude all inspections for a file [[check]] type = "Exclude" filter = "all" file = "src/MyModule.hs" # return back only required inspections [[check]] type = "Include" category = "Partial" file = "src/MyModule.hs"
Keep
Inspection
s only with the categoryPartial
for all files except a single one.# exclude all inspections [[check]] type = "Exclude" filter = "all" scope = "all" # return back inspections with the category Partial [[check]] type = "Include" category = "Partial" scope = "all" # finally, disable all inspections for a specific file [[check]] type = "Exclude" filter = "all" file = "src/MyModule.hs"
:: [FilePath] | Paths to project files |
-> Config | Stan runtime configuration |
-> HashMap FilePath (HashSet (Id Inspection)) | Resulting set of inspections for each file |
Apply configuration to the given list of files to get the set of inspections for each file.
The algorithm:
- Remove all files specified by the
remove
option. - Run
applyChecks
on the remaining files.
:: [FilePath] | Paths to project files |
-> [Check] | List of rules |
-> HashMap FilePath (HashSet (Id Inspection)) | Resulting set of inspections for each file |
Convert the list of Check
s from Config
to data structure that
allows filtering of Inspection
s for given files.