Skip to content

Commit

Permalink
Simplify msg_of_errors to msg_of_error function
Browse files Browse the repository at this point in the history
  • Loading branch information
benmandrew authored and shonfeder committed Jun 20, 2024
1 parent f030cd4 commit 6bbdc3c
Showing 1 changed file with 56 additions and 58 deletions.
114 changes: 56 additions & 58 deletions lib/lint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -436,69 +436,67 @@ module Lint = struct

let id = "opam-ci-lint"

let msg_of_errors =
List.map (fun (package, err) ->
let pkg = OpamPackage.to_string package in
match err with
| UnnecessaryField field ->
Fmt.str "Warning in %s: Unnecessary field '%s'. It is suggested to remove it." pkg field
| UnmatchedName value ->
Fmt.str "Error in %s: The field 'name' that doesn't match its context. \
Field 'name' has value '%s' but was expected of value '%s'."
pkg
(OpamPackage.Name.to_string value)
(OpamPackage.Name.to_string (OpamPackage.name package))
| UnmatchedVersion value ->
Fmt.str "Error in %s: The field 'version' that doesn't match its context. \
Field 'version' has value '%s' but was expected of value '%s'."
pkg
(OpamPackage.Version.to_string value)
(OpamPackage.Version.to_string (OpamPackage.version package))
| DubiousDuneSubst ->
Fmt.str "Warning in %s: Dubious use of 'dune subst'. \
'dune subst' should always only be called with {dev} (i.e. [\"dune\" \"subst\"] {dev}) \
If your opam file has been autogenerated by dune, you need to upgrade your dune-project \
to at least (lang dune 2.7)."
pkg
| DuneProjectMissing ->
Fmt.str "Warning in %s: The package seems to use dune but the dune-project file is missing." pkg
| DuneConstraintMissing ->
Fmt.str "Warning in %s: The package has a dune-project file but no explicit dependency on dune was found." pkg
| DuneIsBuild ->
Fmt.str "Warning in %s: The package tagged dune as a build dependency. \
Due to a bug in dune (https://github.com/ocaml/dune/issues/2147) this should never be the case. \
Please remove the {build} tag from its filter."
pkg
| BadDuneConstraint (dep, ver) ->
Fmt.str "Error in %s: Your dune-project file indicates that this package requires at least dune %s \
but your opam file only requires dune >= %s. Please check which requirement is the right one, and fix the other."
pkg ver dep
| UnexpectedFile file ->
Fmt.str "Error in %s: Unexpected file in %s/files/%s" pkg (Check.path_from_pkg package) file
| ForbiddenPerm file ->
Fmt.str
"Error in %s: Forbidden permission for file %s/%s. All files should have permissions 644."
pkg (Check.path_from_pkg package) file
| OpamLint warn ->
let warn = OpamFileTools.warns_to_string [warn] in
Fmt.str "Error in %s: %s" pkg warn
| FailedToDownload msg ->
Fmt.str "Error in %s: Failed to download the archive. Details: %s" pkg msg
| NameCollision other_pkg ->
Fmt.str "Warning in %s: Possible name collision with package '%s'" pkg other_pkg
| WeakChecksum msg ->
Fmt.str "Error in %s: Weak checksum algorithm(s) provided. Please use SHA-256 or SHA-512. Details: %s" pkg msg
| PinDepends ->
Fmt.str "Error in %s: pin-depends present. This is not allowed in the opam-repository." pkg
| ExtraFiles ->
Fmt.str "Error in %s: extra-files present. This is not allowed in the opam-repository. Please use extra-source instead." pkg
)
let msg_of_error (package, err) =
let pkg = OpamPackage.to_string package in
match err with
| UnnecessaryField field ->
Fmt.str "Warning in %s: Unnecessary field '%s'. It is suggested to remove it." pkg field
| UnmatchedName value ->
Fmt.str "Error in %s: The field 'name' that doesn't match its context. \
Field 'name' has value '%s' but was expected of value '%s'."
pkg
(OpamPackage.Name.to_string value)
(OpamPackage.Name.to_string (OpamPackage.name package))
| UnmatchedVersion value ->
Fmt.str "Error in %s: The field 'version' that doesn't match its context. \
Field 'version' has value '%s' but was expected of value '%s'."
pkg
(OpamPackage.Version.to_string value)
(OpamPackage.Version.to_string (OpamPackage.version package))
| DubiousDuneSubst ->
Fmt.str "Warning in %s: Dubious use of 'dune subst'. \
'dune subst' should always only be called with {dev} (i.e. [\"dune\" \"subst\"] {dev}) \
If your opam file has been autogenerated by dune, you need to upgrade your dune-project \
to at least (lang dune 2.7)."
pkg
| DuneProjectMissing ->
Fmt.str "Warning in %s: The package seems to use dune but the dune-project file is missing." pkg
| DuneConstraintMissing ->
Fmt.str "Warning in %s: The package has a dune-project file but no explicit dependency on dune was found." pkg
| DuneIsBuild ->
Fmt.str "Warning in %s: The package tagged dune as a build dependency. \
Due to a bug in dune (https://github.com/ocaml/dune/issues/2147) this should never be the case. \
Please remove the {build} tag from its filter."
pkg
| BadDuneConstraint (dep, ver) ->
Fmt.str "Error in %s: Your dune-project file indicates that this package requires at least dune %s \
but your opam file only requires dune >= %s. Please check which requirement is the right one, and fix the other."
pkg ver dep
| UnexpectedFile file ->
Fmt.str "Error in %s: Unexpected file in %s/files/%s" pkg (Check.path_from_pkg package) file
| ForbiddenPerm file ->
Fmt.str
"Error in %s: Forbidden permission for file %s/%s. All files should have permissions 644."
pkg (Check.path_from_pkg package) file
| OpamLint warn ->
let warn = OpamFileTools.warns_to_string [warn] in
Fmt.str "Error in %s: %s" pkg warn
| FailedToDownload msg ->
Fmt.str "Error in %s: Failed to download the archive. Details: %s" pkg msg
| NameCollision other_pkg ->
Fmt.str "Warning in %s: Possible name collision with package '%s'" pkg other_pkg
| WeakChecksum msg ->
Fmt.str "Error in %s: Weak checksum algorithm(s) provided. Please use SHA-256 or SHA-512. Details: %s" pkg msg
| PinDepends ->
Fmt.str "Error in %s: pin-depends present. This is not allowed in the opam-repository." pkg
| ExtraFiles ->
Fmt.str "Error in %s: extra-files present. This is not allowed in the opam-repository. Please use extra-source instead." pkg

let run { master } job { Key.src; packages } { Value.host_os } =
Current.Job.start job ~pool ~level:Current.Level.Harmless >>= fun () ->
Current_git.with_checkout ~job src @@ fun dir ->
Check.of_dir ~host_os ~master ~job ~packages dir >|= fun errors ->
let errors = msg_of_errors errors in
let errors = List.map msg_of_error errors in
List.iter (Current.Job.log job "%s") errors;
match errors with
| [] -> Ok ()
Expand Down

0 comments on commit 6bbdc3c

Please sign in to comment.