Skip to content

Commit

Permalink
reftest: lint add W69 that checks that there is no several '+' in pac…
Browse files Browse the repository at this point in the history
…kage name for variable in string, and advise the good syntax.
  • Loading branch information
rjbou authored and kit-ty-kate committed Mar 29, 2024
1 parent e6e4962 commit ad303d8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/state/opamFileTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,31 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t =
cond 68 `Warning
"Missing field 'license'"
(t.license = []);
(let vars =
List.flatten @@
List.map (fun s ->
List.filter_map
(fun f ->
try
let _ =
OpamTypesBase.filter_ident_of_string_interp
~accept:false f
in
None
with OpamTypesBase.Parse_error (p,v) ->
Some (p,v)
)
(OpamFilter.extract_variables_from_string s))
all_expanded_strings
in
cond 69 `Warning
"Package name in variable in string interpolation contains several \
'+', use"
~detail:(List.map (fun (p,v) ->
Printf.sprintf "'?%s:%s:' instead of '%s:%s'"
p v p v)
vars)
(vars <> []));
]
in
format_errors @
Expand Down
20 changes: 20 additions & 0 deletions tests/reftests/lint.test
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,23 @@ bug-reports: "https://nobug"
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Warnings.
warning 68: Missing field 'license'
### : W69: Package name in variable in string interpolation contains several '+'
### <lint.opam>
opam-version: "2.0"
name: "conf-g++"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "maint@tain.er"
license: "ISC"
dev-repo: "hg+https://to@li.nt"
bug-reports: "https://nobug"
messages: [
"foo" { "%{?conf-c++:installed:}%" }
"bar" { "%{conf-g++:installed}%" }
"baz" { "%{abc+xyz+jkl:installed}%" }
]
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Warnings.
warning 69: Package name in variable in string interpolation contains several '+', use: "'?conf-g++:installed:' instead of 'conf-g++:installed'"

0 comments on commit ad303d8

Please sign in to comment.