Skip to content

Commit 42278b8

Browse files
committed
Short output format
1 parent 89d2720 commit 42278b8

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

dist/npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "whine",
3-
"version": "0.0.21",
3+
"version": "0.0.22",
44
"description": "PureScript linter, extensible, with configurable rules, and one-off escape hatches",
55
"keywords": ["purescript", "lint"],
66
"author": "Fyodor Soikin <name.fa@gmail.com>",

dist/vscode-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "collegevine",
44
"displayName": "Whine at PureScript",
55
"description": "PureScript linter, extensible, with configurable rules, and one-off escape hatches",
6-
"version": "0.0.21",
6+
"version": "0.0.22",
77
"repository": "https://github.com/collegevine/purescript-whine",
88
"engines": {
99
"vscode": "^1.95.0"

spago.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ package:
4848
main: Test.Main
4949
dependencies: []
5050
publish:
51-
version: 0.0.21
51+
version: 0.0.22
5252
license: MIT
5353
location:
5454
githubOwner: collegevine

src/Whine/Print.purs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ import Ansi.Codes (Color(..))
66
import Ansi.Output (foreground, withGraphics)
77
import Data.String as String
88
import Data.String.Utils (padStart')
9+
import Whine.Runner.Cli (OutputFormat(..))
910
import Whine.Types (Violation, WithFile, WithMuted, WithRule)
1011

11-
printViolation :: Violation (WithRule + WithMuted + WithFile + ()) -> Maybe String
12-
printViolation { muted: true } = Nothing
13-
printViolation { source, message, rule, file } = Just text
12+
type Args r = { outputFormat :: OutputFormat | r }
13+
14+
printViolation :: r. Args r -> Violation (WithRule + WithMuted + WithFile + ()) -> Maybe String
15+
printViolation _ { muted: true } = Nothing
16+
printViolation args { source, message, rule, file } = Just text
1417
where
15-
text = fold
16-
[ withGraphics (foreground Cyan) file.path, ":"
17-
, locationText
18-
, withGraphics (foreground Red) rule, ": "
19-
, message, "\n"
20-
, withGraphics (foreground BrightYellow) sourceText
21-
]
18+
text =
19+
case args.outputFormat of
20+
Short -> fileLocation <> " " <> ruleAndMessage
21+
Long -> fileLocation <> " " <> ruleAndMessage <> "\n" <> sourceCode
22+
where
23+
fileLocation = fold [withGraphics (foreground Cyan) file.path, ":", locationText]
24+
ruleAndMessage = fold [withGraphics (foreground Red) rule, ": ", message]
25+
sourceCode = withGraphics (foreground BrightYellow) sourceText
2226

2327
indent = " "
2428

src/Whine/Runner/Cli.purs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ data Command
1919
= JustWhine JustWhineArgs
2020
| LanguageServer LanguagServerArgs
2121

22-
type JustWhineArgs = { globs :: Maybe (NonEmptyArray NonEmptyString) }
22+
type JustWhineArgs =
23+
{ globs :: Maybe (NonEmptyArray NonEmptyString)
24+
, outputFormat :: OutputFormat
25+
}
2326

2427
type LanguagServerArgs = { checkWhen :: CheckFileWhen }
2528

2629
data CheckFileWhen = CheckOnSave | CheckOnChange
2730

31+
data OutputFormat = Short | Long
32+
2833
parseCliArgs :: m. MonadEffect m => m Args
2934
parseCliArgs = liftEffect $
3035
O.customExecParser
@@ -47,8 +52,10 @@ justWhineArgsParser = ado
4752
[ O.metavar "GLOB"
4853
, O.help "Glob patterns to match files to lint. When empty, all files are linted."
4954
]
55+
outputFormat <- outputFormatOption
5056
in
5157
{ globs: NEA.fromFoldable $ List.mapMaybe NES.fromString args
58+
, outputFormat: fromMaybe Long outputFormat
5259
}
5360

5461
languageServerArgsParser :: O.Parser LanguagServerArgs
@@ -92,12 +99,18 @@ quietFlag =
9299
, O.help "Print no output"
93100
]
94101

95-
languageServerFlag :: O.Parser Boolean
96-
languageServerFlag =
97-
O.switch $ fold
98-
[ O.long "language-server"
99-
, O.help "Start Whine as a language server"
102+
outputFormatOption :: O.Parser (Maybe OutputFormat)
103+
outputFormatOption =
104+
OT.optional $ O.option parseOutputFormat $ fold
105+
[ O.long "output"
106+
, O.short 'o'
107+
, O.help "Output format. Possible values are 'short' and 'long'. Default is 'long'."
100108
]
109+
where
110+
parseOutputFormat = O.eitherReader \s -> do
111+
if s == "short" then Right Short
112+
else if s == "long" then Right Long
113+
else Left $ "Invalid output format: " <> s
101114

102115
determineLogLevel :: Args -> LogSeverity
103116
determineLogLevel args =

src/Whine/Runner/Runner.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ runWhineAndPrintResultsAndExit factories = launchAff_ do
2727
let env = { logLevel: Cli.determineLogLevel args }
2828

2929
case args.command of
30-
Cli.JustWhine { globs } -> do
30+
Cli.JustWhine justWhineArgs@{ globs } -> do
3131
results <- runWhine { factories, globs, configFile: "whine.yaml", env }
32-
let output = printViolation `mapMaybe` results
32+
let output = nub $ printViolation justWhineArgs `mapMaybe` results
3333
unless args.quiet do
3434
Console.log `traverse_` output
3535
when (null output) $ Console.log "No violations found."

0 commit comments

Comments
 (0)