Skip to content

Commit 28a5e02

Browse files
committed
Merge branch 'main' of github.com:haskell-actions/hlint-scan
2 parents 3606288 + bc65e17 commit 28a5e02

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ You only need to set them if the defaults do not work for your situation.
3535
`path`
3636
: Path of file or directory that HLint will be told to scan.
3737

38+
<!--
39+
Uncomment this when this is ready to be released:
40+
41+
`hints`
42+
: Path for HLint configuration file.
43+
-->
44+
3845
`category`
3946
: String used by GitHub code scanning for matching the analyses.
4047

action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ inputs:
2323
description: Path of file or directory that HLint will be told to scan.
2424
required: false
2525
default: .
26+
hints:
27+
# Change description when this is released.
28+
description: Path for HLint configuration file. Not available yet.
29+
required: false
2630
category:
2731
description: String used by GitHub code scanning for matching the analyses.
2832
required: false
@@ -39,6 +43,7 @@ outputs:
3943
runs:
4044
using: docker
4145
image: Dockerfile # docker://ghcr.io/haskell-actions/hlint-scan:main
46+
image: docker://ghcr.io/haskell-actions/hlint-scan:main
4247
args:
4348
- binary=${{ inputs.binary }}
4449
- path=${{ inputs.path }}

docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ the [Haskell Package Versioning Policy].
1010

1111
## Unreleased
1212

13+
* Support `hints` input for explicitly specifying the HLint configuration file.
14+
1315
## 0.4.1 - 2023-04-10
1416

1517
* Added automated testing.

src/Arguments.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ validate args
7676
-- | List of argument keywords which are allowed.
7777
-- In other words, these are arguments we know what to do with.
7878
allowedArgs :: [String]
79-
allowedArgs = ["binary", "path", "category", "token"]
79+
allowedArgs = ["binary", "path", "hints", "category", "token"]
8080

8181
-- | Translate program arguments to arguments for HLint.
8282
-- Also derives the category and access token from the arguments.
@@ -93,7 +93,7 @@ translate ::
9393
-- * Category to upload with.
9494
-- * GitHub access token.
9595
(FilePath, [String], Maybe String, Maybe String)
96-
translate args = (executable', path' : requiredFlags, category', token')
96+
translate args = (executable', path' : hints' ++ requiredFlags, category', token')
9797
where
9898
argsMap = map toTuple args
9999

@@ -109,6 +109,12 @@ translate args = (executable', path' : requiredFlags, category', token')
109109
| Just "" <- path = "."
110110
| Just s <- path = s
111111

112+
hints = lookup "hints" argsMap
113+
hints'
114+
| Nothing <- hints = []
115+
| Just "" <- hints = []
116+
| Just s <- hints = ["--hint=" <> s]
117+
112118
category = lookup "category" argsMap
113119
category'
114120
| Just "" <- category = Nothing

test/ArgumentsSpec.hs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ spec = do
3737
validate
3838
[ "binary=/hlint",
3939
"path=.",
40+
"hints=.hlint.yaml",
4041
"category=code-quality",
4142
"token=AB12CD"
4243
]
4344
`shouldBe` Nothing
4445

4546
prop "argument must have '=' character" $ \s ->
46-
'='
47-
`notElem` s
48-
==> validate [s]
49-
`shouldSatisfy` isJust
47+
'=' `notElem` s ==>
48+
validate [s] `shouldSatisfy` isJust
5049

5150
prop "argument must not have duplicate keyword" $ \key v v' ->
5251
'=' `notElem` key ==> \keyValues ->
@@ -56,23 +55,22 @@ spec = do
5655
validate args `shouldSatisfy` isJust
5756

5857
prop "argument must have explicitly allowed keyword" $ \key v ->
59-
'='
60-
`notElem` key
61-
==> key
62-
`notElem` ["binary", "path", "category", "token"]
63-
==> validate [key <> "=" <> v]
64-
`shouldSatisfy` isJust
58+
'=' `notElem` key ==>
59+
key `notElem` ["binary", "path", "hints", "category", "token"] ==>
60+
validate [key <> "=" <> v]
61+
`shouldSatisfy` isJust
6562

6663
describe "translate" $ do
6764
it "translates specific arguments" $
6865
translate
6966
[ "binary=/hlint",
7067
"path=.",
68+
"hints=.hlint.yaml",
7169
"category=code-quality",
7270
"token=XYZ123"
7371
]
7472
`shouldBe` ( "/hlint",
75-
[".", "-j", "--sarif", "--no-exit-code"],
73+
[".", "--hint=.hlint.yaml", "-j", "--sarif", "--no-exit-code"],
7674
Just "code-quality",
7775
Just "XYZ123"
7876
)
@@ -88,7 +86,11 @@ spec = do
8886
`shouldSatisfy` \(binary, _, _, _) -> binary == "/hlint"
8987

9088
prop "translates empty path to default path" $
91-
translate ["binary="]
89+
translate ["path="]
90+
`shouldSatisfy` \(_, args, _, _) -> args == [".", "-j", "--sarif", "--no-exit-code"]
91+
92+
prop "translates empty hints to omitted hints file flag" $
93+
translate ["hints="]
9294
`shouldSatisfy` \(_, args, _, _) -> args == [".", "-j", "--sarif", "--no-exit-code"]
9395

9496
prop "translates empty category to Nothing" $
@@ -99,27 +101,21 @@ spec = do
99101
translate ["token="]
100102
`shouldSatisfy` \(_, _, token, _) -> isNothing token
101103

102-
prop "translates general arguments" $ \binary path category token ->
103-
binary
104-
/= ""
105-
&& path
106-
/= ""
107-
&& category
108-
/= ""
109-
&& token
110-
/= ""
104+
prop "translates general arguments" $ \binary path hints category token ->
105+
binary /= "" && path /= "" && hints /= "" && category /= "" && token /= ""
111106
==> forAll
112107
( shuffle
113108
[ "binary=" <> binary,
114109
"path=" <> path,
110+
"hints=" <> hints,
115111
"category=" <> category,
116112
"token=" <> token
117113
]
118114
)
119115
$ \args ->
120116
translate args
121117
`shouldBe` ( binary,
122-
[path, "-j", "--sarif", "--no-exit-code"],
118+
[path, "--hint=" <> hints, "-j", "--sarif", "--no-exit-code"],
123119
Just category,
124120
Just token
125121
)

0 commit comments

Comments
 (0)