Skip to content

Commit 334bc68

Browse files
authored
Refactor traversal logic, add ModuleQualifiers rule (#4)
1 parent 6f36eb2 commit 334bc68

27 files changed

+611
-1451
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
- uses: actions/setup-node@v2
2525
with:
26-
node-version: 20
26+
node-version: 24
2727

2828
- run: npm install
2929
- run: npx spago build

bootstrap/src/Cache.purs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Node.ChildProcess.Types as StdIO
2222
import Node.Path as NodePath
2323
import Partial.Unsafe (unsafePartial)
2424
import Spago.Generated.BuildInfo as BuildInfo
25-
import Whine.Bootstrap.Execa (execResultSuccessOrDie, execSuccessOrDie_, execa)
25+
import Whine.Bootstrap.Execa (execSuccessOrDie, execSuccessOrDie_, execa)
2626
import Whine.Bootstrap.Hash (hashString)
2727
import Whine.Bootstrap.JsonCodecs as J
2828
import Whine.Runner.Config (PackageSpec(..))
@@ -106,6 +106,7 @@ rebuildCache { rulePackages, bundleFile } = do
106106
let mainModule = "Main" <> unique
107107
packageName = "whine-cached-bootstrap"
108108
dependencies = Map.union rulePackages (uncurry Map.singleton whineCorePackage)
109+
entryPointFile = cacheDir <> "/src/Main.purs"
109110

110111
FS.mkDirP (cacheDir <> "/src")
111112
FS.writeFile (cacheDir <> "/package.json") "{}"
@@ -150,15 +151,14 @@ rebuildCache { rulePackages, bundleFile } = do
150151
, "vscode-languageserver"
151152
, "vscode-languageserver-textdocument"
152153
]
153-
_
154-
{ cwd = Just cacheDir
155-
, stdout = Just StdIO.pipe
156-
, stderr = Just StdIO.pipe
157-
}
154+
inCacheDirAndPipeOutputs
158155

159156
logSameLine "Making a pitiful face..."
160157
logDebug "Installed NPM dependencies"
161158

159+
whenM (FS.exists entryPointFile) $
160+
FS.unlink entryPointFile # tryOrDie
161+
162162
moduleGraphJson <- spagoGraphModules
163163
moduleGraph <- moduleGraphJson # JSON.parse # lmap DecodeError.basic >>= J.decode moduleGraphCodec # rightOrDie
164164
logDebug "Obtained dependency module graph"
@@ -176,18 +176,14 @@ rebuildCache { rulePackages, bundleFile } = do
176176
inferredModule = Map.lookup package candidateModules
177177
pure $ specifiedModule <|> inferredModule
178178

179-
FS.writeFile (cacheDir <> "/src/Main.purs") $
179+
FS.writeFile entryPointFile $
180180
cachedBundleMainModule { moduleName: mainModule, ruleModules }
181181

182182
logSameLine "Revisiting complaints..."
183183
logDebug "Wrote executable entry point"
184184

185185
execSuccessOrDie_ "spago bundle" =<<
186-
execa "npx" ["spago", "bundle", "--source-maps"] _
187-
{ cwd = Just cacheDir
188-
, stdout = Just StdIO.pipe
189-
, stderr = Just StdIO.pipe
190-
}
186+
execa "npx" ["spago", "bundle", "--source-maps"] inCacheDirAndPipeOutputs
191187

192188
logSameLine "Done, ready to whine."
193189
logDebug "Bundled the executable"
@@ -203,30 +199,23 @@ rebuildCache { rulePackages, bundleFile } = do
203199
logInfo $ prefix <> msg
204200

205201
spagoGraphModules = do
206-
proc <-
207-
execa "npx" ["spago", "graph", "modules", "--json"] _
208-
{ cwd = Just cacheDir
209-
, stdout = Just StdIO.pipe
210-
, stderr = Just StdIO.pipe
211-
}
212-
213-
res <- liftAff proc.getResult
214-
215-
unless (res.exitCode == Just 0) do
216-
logDebug "'spago graph modules' failed. Trying to build to see what the error was..."
217-
FS.writeFile (cacheDir <> "/src/Main.purs") "module M where\nx = 42 :: Int"
218-
execSuccessOrDie_ "spago build" =<<
219-
execa "npx" ["spago", "build"] _
220-
{ cwd = Just cacheDir
221-
, stdout = Just StdIO.pipe
222-
, stderr = Just StdIO.pipe
223-
}
224-
225-
logDebug "Building succeeded, but 'spago graph modules' still failed."
226-
execResultSuccessOrDie "spago graph modules" res
202+
-- First build to make sure all modules are fresh, in case we just
203+
-- overwrote a previous config that was somehow incompatible.
204+
execSuccessOrDie_ "spago build" =<<
205+
execa "npx" ["spago", "build"] inCacheDirAndPipeOutputs
206+
207+
-- Then get the module graph.
208+
res <- execSuccessOrDie "spago graph modules" =<<
209+
execa "npx" ["spago", "graph", "modules", "--json"] inCacheDirAndPipeOutputs
227210

228211
pure res.stdout
229212

213+
inCacheDirAndPipeOutputs = _
214+
{ cwd = Just cacheDir
215+
, stdout = Just StdIO.pipe
216+
, stderr = Just StdIO.pipe
217+
}
218+
230219
whineCorePackage :: { package :: String } /\ PackageSpec
231220
whineCorePackage = { package: "whine-core" } /\ PackageVersion version
232221
where

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.32",
3+
"version": "0.0.33",
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.32",
6+
"version": "0.0.33",
77
"repository": "https://github.com/collegevine/purescript-whine",
88
"engines": {
99
"vscode": "^1.95.0"

integration-tests/cases/1-local-rules/src/WhineRules.purs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ import JSON (JSON)
77
import JSON as JSON
88
import PureScript.CST.Types (Module(..), ModuleHeader(..), ModuleName(..), Name(..))
99
import Whine.Log (logInfo)
10-
import Whine.Types (Handle(..), Rule, RuleFactories, currentModule, emptyRule, ruleFactory)
10+
import Whine.Types (Rule(..), RuleFactories, ruleFactory)
1111

1212
rules :: RuleFactories
1313
rules = [ruleFactory "LocalRule" CJ.json localRule]
1414

1515
localRule :: JSON -> Rule
16-
localRule config = emptyRule { onModule = onModule }
17-
where
18-
onModule :: Handle Module
19-
onModule = Handle \_ ->
20-
currentModule \(Module { header: ModuleHeader { name: Name { name: ModuleName n } } }) -> do
21-
logInfo $ "Local rule configured with '" <> JSON.print config <> "' is running on " <> n
22-
pure unit
16+
localRule config = Rule \(Module { header: ModuleHeader { name: Name { name: ModuleName n } } }) -> do
17+
logInfo $ "Local rule configured with '" <> JSON.print config <> "' is running on " <> n
18+
pure unit

integration-tests/cases/1-local-rules/with-local-rule-changed.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ Local rule changed configured with '{"foo":"bar","baz":42}' is running on Local.
1818
<TIMESTAMP>: Parsing src/Main.purs
1919
<TIMESTAMP>: Parsed src/Main.purs, running rules
2020
Local rule changed configured with '{"foo":"bar","baz":42}' is running on Main
21-
No violations found.
21+
No violations found.

integration-tests/cases/1-local-rules/with-local-rule-config-debug.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Local rule configured with '{"foo":"bar","baz":42}' is running on Local.WhineRul
55
<TIMESTAMP>: Parsing src/Main.purs
66
<TIMESTAMP>: Parsed src/Main.purs, running rules
77
Local rule configured with '{"foo":"bar","baz":42}' is running on Main
8-
No violations found.
8+
No violations found.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
src/B.purs:4:5: UndesirableFunctions/foo: Function g should not be used
1+
src/B.purs:5:7: CommaFirstArrays: Format array literals comma-first, align items vertically
22

3-
4: y = g 1
3+
5: z = h [2,
4+
6: 3]
45

56
src/B.purs:5:5: UndesirableFunctions/bar: Function h should not be used
67

78
5: z = h [2,
89

9-
src/B.purs:5:7: CommaFirstArrays: Format array literals comma-first, align items vertically
10+
src/B.purs:4:5: UndesirableFunctions/foo: Function g should not be used
11+

12+
4: y = g 1
13+

14+
src/A.purs:5:7: CommaFirstArrays: Format array literals comma-first, align items vertically
1015

1116
5: z = h [2,
1217
6: 3]
@@ -18,9 +23,4 @@
1823
src/A.purs:5:5: UndesirableFunctions/bar: Function h should not be used
1924

2025
5: z = h [2,
21-

22-
src/A.purs:5:7: CommaFirstArrays: Format array literals comma-first, align items vertically
23-

24-
5: z = h [2,
25-
6: 3]
2626


0 commit comments

Comments
 (0)