Skip to content

Commit 6215e69

Browse files
committed
warn on non-ASCII characters in name:
1 parent 857e67e commit 6215e69

File tree

7 files changed

+46
-1
lines changed

7 files changed

+46
-1
lines changed

Cabal/src/Distribution/PackageDescription/Check.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,13 @@ checkPackageDescription
413413
checkPackageId package_
414414
-- TODO `name` is caught at parse level, remove this test.
415415
let pn = packageName package_
416+
pns = unPackageName pn
416417
checkP
417-
(null . unPackageName $ pn)
418+
(null pns)
418419
(PackageBuildImpossible NoNameField)
420+
checkP
421+
(any (not . isAscii) pns)
422+
(PackageDistInexcusable NonASCIIName)
419423
-- TODO `version` is caught at parse level, remove this test.
420424
checkP
421425
(nullVersion == packageVersion package_)

Cabal/src/Distribution/PackageDescription/Check/Warning.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ filterPackageChecksByIdString cs ss =
142142
data CheckExplanation
143143
= ParseWarning FilePath PWarning
144144
| NoNameField
145+
| NonASCIIName
145146
| NoVersionField
146147
| NoTarget
147148
| UnnamedInternal
@@ -309,6 +310,7 @@ extractCheckExplanation (PackageDistInexcusable e) = e
309310
data CheckExplanationID
310311
= CIParseWarning
311312
| CINoNameField
313+
| CINonASCIIName
312314
| CINoVersionField
313315
| CINoTarget
314316
| CIUnnamedInternal
@@ -455,6 +457,7 @@ data CheckExplanationID
455457
checkExplanationId :: CheckExplanation -> CheckExplanationID
456458
checkExplanationId (ParseWarning{}) = CIParseWarning
457459
checkExplanationId (NoNameField{}) = CINoNameField
460+
checkExplanationId (NonASCIIName{}) = CINonASCIIName
458461
checkExplanationId (NoVersionField{}) = CINoVersionField
459462
checkExplanationId (NoTarget{}) = CINoTarget
460463
checkExplanationId (UnnamedInternal{}) = CIUnnamedInternal
@@ -608,6 +611,7 @@ ppCheckExplanationId :: CheckExplanationID -> CheckExplanationIDString
608611
-- $ cabal run Cabal-tests:unit-tests -- --pattern=Parsimonious
609612
ppCheckExplanationId CIParseWarning = "parser-warning"
610613
ppCheckExplanationId CINoNameField = "no-name-field"
614+
ppCheckExplanationId CINonASCIIName = "non-ascii-name"
611615
ppCheckExplanationId CINoVersionField = "no-version-field"
612616
ppCheckExplanationId CINoTarget = "no-target"
613617
ppCheckExplanationId CIUnnamedInternal = "unnamed-internal-library"
@@ -795,6 +799,7 @@ ppWarnLang LangCPlusPlus = "C++"
795799
ppExplanation :: CheckExplanation -> String
796800
ppExplanation (ParseWarning fp pp) = showPWarning fp pp
797801
ppExplanation NoNameField = "No 'name' field."
802+
ppExplanation NonASCIIName = "Non-ASCII characters in 'name' field."
798803
ppExplanation NoVersionField = "No 'version' field."
799804
ppExplanation NoTarget =
800805
"No executables, libraries, tests, or benchmarks found. Nothing to do."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# cabal check
2+
The following errors will cause portability problems on other environments:
3+
Error: [name-no-match] The filename './pkg.cabal' does not match package name (expected: 'pkg-?.cabal')
4+
Error: [non-ascii-name] Non-ASCII characters in 'name' field.
5+
Error: Hackage would reject this package.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
3+
-- Non ASCII charaters in package name.
4+
main = cabalTest $
5+
fails $ cabal "check" []
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cabal-version: 3.0
2+
name: pkg-α
3+
-- Cabal testsuite sadly chokes when copying files with
4+
-- non-ASCII characters in them. So for this test, in
5+
-- the output file, you will get an error for filename/
6+
-- name mismatch, too.
7+
description: description
8+
synopsis: synopsis
9+
version: 0
10+
category: example
11+
maintainer: [email protected]
12+
license: GPL-3.0-or-later
13+
14+
library
15+
exposed-modules: Module
16+
default-language: Haskell2010

changelog.d/pr-11198

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
synopsis: Warn on non-ASCII characters in `name`
3+
packages: [Cabal, cabal-install]
4+
prs: 11198
5+
issues: 11197
6+
---
7+
8+
`cabal check` now warns about packages with non-ASCII characters
9+
in their name (they are not accepted by Hackage).

doc/cabal-commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ A list of all warnings with their constructor:
13851385

13861386
- ``parser-warning``: inherited from parser.
13871387
- ``no-name-field``: missing ``name`` field.
1388+
- ``non-ascii-name``: non-ASCII characters in ``name`` field.
13881389
- ``no-version-field``: missing ``version`` field.
13891390
- ``no-target``: missing target in ``.cabal``.
13901391
- ``unnamed-internal-library``: unnamed internal library.

0 commit comments

Comments
 (0)