Skip to content

Commit b7b1649

Browse files
committed
Warn on spaces in module names
1 parent 9f0b49b commit b7b1649

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Hpack/Module.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ instance IsString Module where
3333
fromString = Module
3434

3535
instance FromValue Module where
36-
fromValue = fmap Module . fromValue
36+
fromValue v = do
37+
r <- fromValue v
38+
case words r of
39+
[name] -> return (Module name)
40+
_ -> warn ("invalid module name " <> show r) >> return (Module r)
3741

3842
toModule :: Path -> Module
3943
toModule path = case reverse $ Path.components path of

test/EndToEndSpec.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ spec = around_ (inTempDirectoryNamed "foo") $ do
7070
"package.yaml: Duplicate field $.name"
7171
]
7272

73+
context "when a module name contains spaces" $ do
74+
it "warns" $ do
75+
[i|
76+
name: foo
77+
library:
78+
other-modules:
79+
Foo
80+
Bar
81+
Baz
82+
|] `shouldWarn` ["package.yaml: invalid module name \"Foo Bar Baz\" in $.library.other-modules"]
83+
7384
describe "handling of Paths_ module" $ do
7485
it "adds Paths_ to other-modules" $ do
7586
[i|

0 commit comments

Comments
 (0)