| Copyright | (c) 2020 Kowainik |
|---|---|
| License | MPL-2.0 |
| Maintainer | Kowainik <xrom.xkov@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Stan.Config
Description
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 :: Phase Text)
- type PartialConfig = ConfigP ('Partial :: Phase Text)
- 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) #
Main configuration type for the following purposes:
- Filtering inspections (including or ignoring) per scope (file, directory, all)
Constructors
| ConfigP | |
Fields
| |
Instances
| Semigroup PartialConfig # | |
Defined in Stan.Config Methods (<>) :: PartialConfig -> PartialConfig -> PartialConfig # sconcat :: NonEmpty PartialConfig -> PartialConfig # stimes :: Integral b => b -> PartialConfig -> PartialConfig # | |
| (Show (p ::- [Check]), Show (p ::- [Scope]), Show (p ::- [Id Observation])) => Show (ConfigP p) # | |
| (Eq (p ::- [Check]), Eq (p ::- [Scope]), Eq (p ::- [Id Observation])) => Eq (ConfigP p) # | |
Rule to control the set of inspections per scope.
Constructors
| Check | |
Fields
| |
Type of Check: Include or Exclude Inspections.
Instances
| Bounded CheckType # | |
| Enum CheckType # | |
Defined in Stan.Config Methods 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] # | |
| Show CheckType # | |
| Eq CheckType # | |
data CheckFilter #
Criterion for inspections filtering.
Constructors
| CheckInspection !(Id Inspection) | |
| CheckSeverity !Severity | |
| CheckCategory !Category | |
| CheckAll |
Instances
| Show CheckFilter # | |
Defined in Stan.Config Methods showsPrec :: Int -> CheckFilter -> ShowS # show :: CheckFilter -> String # showList :: [CheckFilter] -> ShowS # | |
| Eq CheckFilter # | |
Defined in Stan.Config | |
Where to apply the rule for controlling inspection set.
Constructors
| ScopeFile !FilePath | |
| ScopeDirectory !FilePath | |
| ScopeAll |
Default
mkDefaultChecks :: [FilePath] -> HashMap FilePath (HashSet (Id Inspection)) #
Final stage
finaliseConfig :: PartialConfig -> Trial Text Config #
Printing
configToCliCommand :: Config -> Text #
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 Inspections for
each module.
By default, stan runs all Inspections for all modules in the
Haskell project and outputs all Observations it finds. Using
Config, you can adjust the default setting using your preferences.
Algorithm
The algorithm for figuring out the resulting set of Inspections 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 specificInspectionIdid = "STAN-0001"
CheckSeverity: by specificSeverityseverity = "Warning"
CheckCategory: by specificCategorycategory = "Partial"
CheckAll: applied to allInspectionsfilter = "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
Inspections.[[check]] type = "Exclude" filter = "all" scope = "all"
Exclude all
Inspections only for specific file.[[check]] type = "Exclude" filter = "all" file = "src/MyModule.hs"
Exclude a specific
Inspectionin all files:[[check]] type = "Exclude" id = "STAN-0001" scope = "all"
Exclude all
Inspections for specific file exceptInspections 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
Inspections only with the categoryPartialfor 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"
Arguments
| :: [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
removeoption. - Run
applyCheckson the remaining files.
Arguments
| :: [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 Checks from Config to data structure that
allows filtering of Inspections for given files.