Skip to content

Commit

Permalink
lint: add W74 to detect 'pin-depends' packages that are not present i…
Browse files Browse the repository at this point in the history
…n 'depends' nor in 'depopts'
  • Loading branch information
rjbou committed Dec 3, 2024
1 parent 432c00c commit 186ab9a
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ users)
## Source

## Lint
* [NEW] Add W74 to detect `pin-depends` packages that are neither present in the `depends` nor `depopts` field [#6317 @rjbou - fix #5795]

## Repository
* Accurately tag `curl` download command when loaded from global config file [#6270 @rjbou]
Expand Down
15 changes: 15 additions & 0 deletions src/state/opamFileTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,21 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t =
"Field 'extra-files' contains path with '..'"
~detail:relative
(relative <> []));
(let missing =
let pkgs =
List.map fst t.pin_depends
|> OpamPackage.Set.of_list
|> OpamPackage.names_of_packages
in
OpamPackage.Name.Set.diff pkgs all_depends
|> OpamPackage.Name.Set.elements
|> List.map OpamPackage.Name.to_string
in
cond 74 `Warning
"Field 'pin-depends' contains packages that are neither in 'depends' nor in \
'depopts'"
~detail:missing
(missing <> []));
]
in
format_errors @
Expand Down
121 changes: 121 additions & 0 deletions tests/reftests/lint.test
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ pin-depends: [
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Errors.
error 65: URLs must be absolute: "./my/url/path", "/wrong/../mirror", "./../[email protected]", "/my/./../extrasource/path", "/my/../pinned/package"
warning 74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts': "pinned"
# Return code 1 #
### : W66: String that can't be resolved to bool in filtered package formula
### <lint.opam>
Expand Down Expand Up @@ -1265,6 +1266,126 @@ ${BASEDIR}/lint.opam: Errors.
error 53: Mismatching 'extra-files:' field: "./relative/path", "/absolute/../relative/path", "/absolute/path", "extra-files..patch.patch"
error 73: Field 'extra-files' contains path with '..': "/absolute/../relative/path"
# Return code 1 #
### : E74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts'
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
pin-depends: [
[ "foo.1" "file:///some/path" ]
[ "bar.1" "file:///some/path" ]
]
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Warnings.
warning 74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts': "bar", "foo"
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
depends: [ "foo" ]
pin-depends: [
[ "foo.1" "file:///some/path" ]
[ "bar.1" "file:///some/path" ]
]
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Warnings.
warning 74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts': "bar"
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
depopts: [ "bar" ]
pin-depends: [
[ "foo.1" "file:///some/path" ]
[ "bar.1" "file:///some/path" ]
]
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Warnings.
warning 74: Field 'pin-depends' contains packages that are not in 'depends' nor in 'depopts': "foo"
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
depends: [ "foo" "oof" ]
depopts: [ "bar" "rab" ]
pin-depends: [
[ "foo.1" "file:///some/path" ]
[ "bar.1" "file:///some/path" ]
]
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Passed.
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
depends: [ "foo" ]
pin-depends: [
[ "foo.1" "file:///some/path" ]
]
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Passed.
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
depopts: [ "bar" ]
pin-depends: [
[ "bar.1" "file:///some/path" ]
]
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Passed.
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
depends: [ "foo" { = "1" } ]
pin-depends: [
[ "foo.2" "file:///some/path" ]
]
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Passed.
### :::::::::::::::::::::
### : Test parse errors :
### :::::::::::::::::::::
Expand Down

0 comments on commit 186ab9a

Please sign in to comment.