Skip to content

Commit

Permalink
[mrkkrp#183] Rename Ignore constructor to Exclude and rename CLI …
Browse files Browse the repository at this point in the history
…command to `ignore` (mrkkrp#194)

Resolves mrkkrp#183
  • Loading branch information
vrom911 committed May 31, 2020
1 parent cdd8ed9 commit 2ff9609
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 96 deletions.
4 changes: 2 additions & 2 deletions src/Stan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ runStan StanArgs{..} = do
-- get checks for each file
let checksMap = applyConfig (map hie_hs_file hieFiles) config

let analysis = runAnalysis cabalExtensionsMap checksMap (configObservations config) hieFiles
let analysis = runAnalysis cabalExtensionsMap checksMap (configIgnored config) hieFiles
-- show what observations are ignored
putText $ prettyShowIgnoredObservations
(configObservations config)
(configIgnored config)
(analysisIgnoredObservations analysis)
-- show the result
let res = prettyShowAnalysis analysis stanArgsReportSettings
Expand Down
30 changes: 15 additions & 15 deletions src/Stan/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ toggleSolutionP = flag ShowSolution HideSolution $ mconcat
data ConfigCommand
= CheckCommand Check
| RemoveCommand Scope
| ObservationCommand (Id Observation)
| IgnoreCommand (Id Observation)

partitionCommands :: [ConfigCommand] -> ([Check], [Scope], [Id Observation])
partitionCommands [] = ([], [], [])
partitionCommands (cmd : rest) =
let (check, remove, obs) = partitionCommands rest
in case cmd of
CheckCommand ch -> (ch:check, remove, obs)
RemoveCommand r -> (check, r:remove, obs)
ObservationCommand o -> (check, remove, o:obs)
CheckCommand ch -> (ch:check, remove, obs)
RemoveCommand r -> (check, r:remove, obs)
IgnoreCommand o -> (check, remove, o:obs)

configP :: Parser PartialConfig
configP = do
Expand All @@ -196,14 +196,14 @@ configP = do
(info (CheckCommand <$> checkP) (progDesc "Specify list of checks"))
<> command "remove"
(info (RemoveCommand <$> scopeP) (progDesc "Specify list of removed scope"))
<> command "observation"
(info (ObservationCommand <$> idP "Observation") (progDesc "Specify list of ignored observations"))
<> command "ignore"
(info (IgnoreCommand <$> idP "Observation") (progDesc "Specify list of ignored observations"))
pure $
let (checks, removed, observations) = partitionCommands res
let (checks, removed, ignored) = partitionCommands res
in ConfigP
{ configChecks = whenEmpty checks "checks"
, configRemoved = whenEmpty removed "remove"
, configObservations = whenEmpty observations "observation"
, configIgnored = whenEmpty ignored "ignore"
}
where
whenEmpty :: [a] -> Text -> TaggedTrial Text [a]
Expand All @@ -227,9 +227,9 @@ checkP = do

checkTypeP :: Parser CheckType
checkTypeP =
-- QUESTION: is it better than --type=Ignore or --type=Include
-- QUESTION: is it better than --type=Exclude or --type=Include
flag' Include (long "include" <> help "Include check")
<|> flag' Ignore (long "ignore" <> help "Ignore check")
<|> flag' Exclude (long "exclude" <> help "Exclude check")

checkFilterP :: Parser CheckFilter
checkFilterP =
Expand All @@ -238,25 +238,25 @@ checkFilterP =
-- TODO: how to specify all possible values here in help?
(long "severity"
<> metavar "SEVERITY"
<> help "Inspection Severity to ignore or include")
<> help "Inspection Severity to exclude or include")
<|> CheckCategory . Category <$> strOption
(long "category"
<> metavar "CATEGORY"
<> help "Inspection Category to ignore or include")
<> help "Inspection Category to exclude or include")
<|> flag' CheckAll
(long "filter-all"
<> help "Inspection ID to ignore or include")
<> help "Exclude or include ALL inspections")

scopeP :: Parser Scope
scopeP =
ScopeFile <$> strOption
(long "file"
<> metavar "FILE_PATH"
<> help "File to ignore or include")
<> help "File to exclude or include")
<|> ScopeDirectory <$> strOption
(long "directory"
<> metavar "DIRECTORY_PATH"
<> help "Directory to ignore or include")
<> help "Directory to exclude or include")
<|> flag' ScopeAll
(long "scope-all"
<> help "Apply check to all files")
Expand Down
70 changes: 36 additions & 34 deletions src/Stan/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ import qualified Data.Text as T
directory, all)
-}
data ConfigP (p :: Phase Text) = ConfigP
{ configChecks :: !(p ::- [Check])
, configRemoved :: !(p ::- [Scope])
, configObservations :: !(p ::- [Id Observation])
{ configChecks :: !(p ::- [Check])
, configRemoved :: !(p ::- [Scope])
, configIgnored :: !(p ::- [Id Observation])
-- , configGroupBy :: !GroupBy
}

Expand All @@ -86,15 +86,15 @@ type PartialConfig = ConfigP 'Partial
instance Semigroup PartialConfig where
(<>) :: PartialConfig -> PartialConfig -> PartialConfig
x <> y = ConfigP
{ configChecks = configChecks x <> configChecks y
{ configChecks = configChecks x <> configChecks y
, configRemoved = configRemoved x <> configRemoved y
, configObservations = configObservations x <> configObservations y
, configIgnored = configIgnored x <> configIgnored y
}

-- | Type of 'Check': 'Include' or 'Ignore' 'Inspection's.
-- | Type of 'Check': 'Include' or 'Exclude' 'Inspection's.
data CheckType
= Include
| Ignore
| Exclude
deriving stock (Show, Eq, Enum, Bounded)

-- | Rule to control the set of inspections per scope.
Expand Down Expand Up @@ -123,14 +123,14 @@ defaultConfig :: PartialConfig
defaultConfig = ConfigP
{ configChecks = withTag "Default" $ pure []
, configRemoved = withTag "Default" $ pure []
, configObservations = withTag "Default" $ pure []
, configIgnored = withTag "Default" $ pure []
}

finaliseConfig :: PartialConfig -> Trial Text Config
finaliseConfig config = do
configChecks <- #configChecks config
configRemoved <- #configRemoved config
configObservations <- #configObservations config
configIgnored <- #configIgnored config
pure ConfigP {..}


Expand All @@ -139,17 +139,19 @@ be copy-pasted to get the same results as using the TOML config.
@
ⓘ Reading Configurations from \/home\/vrom911\/Kowainik\/stan\/.stan.toml ...
stan check --ignore --directory=test/ \\
stan check --exclude --directory=test/ \\
check --include \\
check --ignore --inspectionId=STAN-0002 \\
check --ignore --inspectionId=STAN-0001 --file=src/MyFile.hs
check --exclude --inspectionId=STAN-0002 \\
check --exclude --inspectionId=STAN-0001 --file=src/MyFile.hs
remove --file=src/Secret.hs
ignore --id="STAN0001-asdfgh42:42"
@
-}
configToCliCommand :: Config -> Text
configToCliCommand ConfigP{..} = "stan " <> T.intercalate " \\\n "
( map checkToCli configChecks
<> map removedToCli configRemoved
<> map observationsToCli configObservations
<> map ignoredToCli configIgnored
)
where
checkToCli :: Check -> Text
Expand All @@ -162,8 +164,8 @@ configToCliCommand ConfigP{..} = "stan " <> T.intercalate " \\\n "
removedToCli scope = "remove"
<> scopeToCli scope

observationsToCli :: Id Observation -> Text
observationsToCli obsId = "observation"
ignoredToCli :: Id Observation -> Text
ignoredToCli obsId = "ignore"
<> idToCli obsId

idToCli :: Id a -> Text
Expand All @@ -172,7 +174,7 @@ configToCliCommand ConfigP{..} = "stan " <> T.intercalate " \\\n "
checkTypeToCli :: CheckType -> Text
checkTypeToCli = \case
Include -> " --include"
Ignore -> " --ignore"
Exclude -> " --exclude"

checkFilterToCli :: CheckFilter -> Text
checkFilterToCli = \case
Expand Down Expand Up @@ -258,10 +260,10 @@ applyChecksFor = foldl' useCheck
-> HashSet (Id Inspection)
applyFilter = \case
Include -> includeFilter
Ignore -> ignoreFilter
Exclude -> excludeFilter

ignoreFilter :: CheckFilter -> HashSet (Id Inspection) -> HashSet (Id Inspection)
ignoreFilter cFilter = HashSet.filter (not . satisfiesFilter cFilter)
excludeFilter :: CheckFilter -> HashSet (Id Inspection) -> HashSet (Id Inspection)
excludeFilter cFilter = HashSet.filter (not . satisfiesFilter cFilter)

includeFilter :: CheckFilter -> HashSet (Id Inspection) -> HashSet (Id Inspection)
includeFilter cFilter ins = case cFilter of
Expand Down Expand Up @@ -326,10 +328,10 @@ three key-value pairs:
type = \"Include\"
@
* 'Ignore'
* 'Exclude'
@
type = \"Ignore\"
type = \"Exclude\"
@
2. 'CheckFilter' — how to filter inspections
Expand Down Expand Up @@ -379,7 +381,7 @@ three key-value pairs:
@
The algorithm doesn't remove any files or inspections from the
consideration completely. So, for example, if you ignore all
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.
Expand All @@ -396,40 +398,40 @@ file = "src\/Autogenerated.hs"
This section contains examples of custom configuration (in TOML) for
common cases.
1. Ignore all 'Inspection's.
1. Exclude all 'Inspection's.
@
[[check]]
type = \"Ignore\"
type = \"Exclude\"
filter = "all"
scope = "all"
@
2. Ignore all 'Inspection's only for specific file.
2. Exclude all 'Inspection's only for specific file.
@
[[check]]
type = \"Ignore\"
type = \"Exclude\"
filter = "all"
file = "src/MyModule.hs"
@
3. Ignore a specific 'Inspection' in all files:
3. Exclude a specific 'Inspection' in all files:
@
[[check]]
type = \"Ignore\"
type = \"Exclude\"
id = "STAN-0001"
scope = "all"
@
4. Ignore all 'Inspection's for specific file except 'Inspection's
4. Exclude all 'Inspection's for specific file except 'Inspection's
that have a category @Partial@.
@
# ignore all inspections for a file
# exclude all inspections for a file
[[check]]
type = \"Ignore\"
type = \"Exclude\"
filter = "all"
file = "src/MyModule.hs"
Expand All @@ -444,9 +446,9 @@ that have a category @Partial@.
except a single one.
@
# ignore all inspections
# exclude all inspections
[[check]]
type = \"Ignore\"
type = \"Exclude\"
filter = "all"
scope = "all"
Expand All @@ -458,7 +460,7 @@ except a single one.
# finally, disable all inspections for a specific file
[[check]]
type = \"Ignore\"
type = \"Exclude\"
filter = "all"
file = "src/MyModule.hs"
@
Expand Down
2 changes: 1 addition & 1 deletion src/Stan/Observation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ prettyShowIgnoredObservations ids obs = ignored <> unknown
(ignoredIds, unknownIds) = partition (`HS.member` obsIds) ids

showIds :: [Id Observation] -> Text
showIds = Text.unlines . map ((<>) " - " . unId)
showIds = unlines . map ((<>) " - " . unId)

{- | Create a stable 'Observation' 'Id' in a such way that:
Expand Down
4 changes: 1 addition & 3 deletions src/Stan/Report.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ module Stan.Report

import Stan.Core.Toggle (ToggleSolution)

import qualified Data.Text as T


{- | Settings for produced report.
-}
Expand All @@ -25,4 +23,4 @@ data ReportSettings = ReportSettings

generateReport :: Text -> IO ()
generateReport = writeFileText "stan.html"
. T.unlines . ("<pre>":) . map (<> "<br/>") . T.lines
. unlines . ("<pre>":) . map (<> "<br/>") . lines
10 changes: 5 additions & 5 deletions src/Stan/Toml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ defaultCurConfigFile = (</> defaultTomlFile) <$> getCurrentDirectory

configCodec :: TomlCodec PartialConfig
configCodec = ConfigP
<$> checksCodec .= configChecks
<*> removedCodec .= configRemoved
<*> observationsCodec .= configObservations
<$> checksCodec .= configChecks
<*> removedCodec .= configRemoved
<*> ignoredCodec .= configIgnored

removedCodec :: TomlCodec (TaggedTrial Text [Scope])
removedCodec = taggedTrialListCodec "remove" scopeCodec

observationsCodec :: TomlCodec (TaggedTrial Text [Id Observation])
observationsCodec = taggedTrialListCodec "observation" idCodec
ignoredCodec :: TomlCodec (TaggedTrial Text [Id Observation])
ignoredCodec = taggedTrialListCodec "ignore" idCodec

checksCodec :: TomlCodec (TaggedTrial Text [Check])
checksCodec = taggedTrialListCodec "check" checkCodec
Expand Down
12 changes: 6 additions & 6 deletions test/.stan-example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ignore everything in the test/ directory
# exclude everything in the test/ directory
[[check]]
type = "Ignore"
type = "Exclude"
filter = "all"
directory = "test/"

Expand All @@ -9,14 +9,14 @@ type = "Include"
filter = "all"
scope = "all"

# ignore specific inspection everywhere
# exclude specific inspection everywhere
[[check]]
type = "Ignore"
type = "Exclude"
id = "STAN-0002"
scope = "all"

# ignore specific inspection only in a specific file
# exclude specific inspection only in a specific file
[[check]]
type = "Ignore"
type = "Exclude"
id = "STAN-0001"
file = "src/MyFile.hs"
Loading

0 comments on commit 2ff9609

Please sign in to comment.