git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Improve license errors in psc-publish (#2082)

* Improve license errors in psc-publish Currently, you get the 'no license specified' error even if you do specify a license but it's not a valid SPDX license expression. There is quite a lot of code in the wild which specifies a license but does not use the SPDX format, and in these cases the error is not very good. This commit adds a new error type to differentiate between these two cases. It also removes the (now redundant) LicenseNotFound constructor. * Add Apache-2.0 example

commit66107e5ca8d2a013e7ea28f3f7da6e6090d27e5a authorHarry Garrood <harry@garrood.me> dateMon 2 May 2016, 21:14 (10 years ago) parenta5eed31
2 files changed+28−17
src/Language/PureScript/Publish.hs+6−2 src/Language/PureScript/Publish/ErrorsWarnings.hs+22−15
src/Language/PureScript/Publish.hs+6−2
@@ -216,8 +216,12 @@ getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExt
216216
217217checkLicense :: PackageMeta -> PrepareM ()
218218checkLicense pkgMeta =
219− unless (any isValidSPDX (bowerLicense pkgMeta))
220− (userError NoLicenseSpecified)
219+ case bowerLicense pkgMeta of
220+ [] ->
221+ userError NoLicenseSpecified
222+ ls ->
223+ unless (any isValidSPDX ls)
224+ (userError InvalidLicense)
221225
222226-- |
223227-- Check if a string is a valid SPDX license expression.
src/Language/PureScript/Publish/ErrorsWarnings.hs+22−15
@@ -55,13 +55,13 @@ data PackageWarning
5555-- | An error that should be fixed by the user.
5656data UserError
5757 = BowerJSONNotFound
58− | LicenseNotFound
5958 | BowerExecutableNotFound [String] -- list of executable names tried
6059 | CouldntDecodeBowerJSON (ParseError BowerError)
6160 | TagMustBeCheckedOut
6261 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
6362 | BadRepositoryField RepositoryFieldError
6463 | NoLicenseSpecified
64+ | InvalidLicense
6565 | MissingDependencies (NonEmpty PackageName)
6666 | CompileError P.MultipleErrors
6767 | DirtyWorkingTree
@@ -129,12 +129,6 @@ displayUserError e = case e of
129129 "The bower.json file was not found. Please create one, or run " ++
130130 "`pulp init`."
131131 )
132− LicenseNotFound ->
133− para (concat
134− ["No LICENSE file was found. Please create one. ",
135− "Distributing code without a license means that nobody ",
136− "will be able to (legally) use it."
137− ])
138132 BowerExecutableNotFound names ->
139133 para (concat
140134 [ "The Bower executable was not found (tried: ", format names, "). Please"
@@ -189,14 +183,7 @@ displayUserError e = case e of
189183 , "following would be acceptable:"
190184 ])
191185 , spacer
192− ] ++
193− map (indented . para)
194− [ "* \"MIT\""
195− , "* \"BSD-2-Clause\""
196− , "* \"GPL-2.0+\""
197− , "* \"(GPL-3.0 OR MIT)\""
198− ]
199− ++
186+ ] ++ spdxExamples ++
200187 [ spacer
201188 , para (concat
202189 [ "Note that distributing code without a license means that nobody "
@@ -209,6 +196,16 @@ displayUserError e = case e of
209196 , "necessary."
210197 ])
211198 ]
199+ InvalidLicense ->
200+ vcat $
201+ [ para (concat
202+ [ "The license specified in bower.json is not a valid SPDX license "
203+ , "expression. Please use the SPDX license expression format. For "
204+ , "example, any of the following would be acceptable:"
205+ ])
206+ , spacer
207+ ] ++
208+ spdxExamples
212209 MissingDependencies pkgs ->
213210 let singular = NonEmpty.length pkgs == 1
214211 pl a b = if singular then b else a
@@ -239,6 +236,16 @@ displayUserError e = case e of
239236 "your changes first."
240237 )
241238
239+spdxExamples :: [Box]
240+spdxExamples =
241+ map (indented . para)
242+ [ "* \"MIT\""
243+ , "* \"Apache-2.0\""
244+ , "* \"BSD-2-Clause\""
245+ , "* \"GPL-2.0+\""
246+ , "* \"(GPL-3.0 OR MIT)\""
247+ ]
248+
242249displayRepositoryError :: RepositoryFieldError -> Box
243250displayRepositoryError err = case err of
244251 RepositoryFieldMissing ->