-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
feature_missing
manifest lint to prove manifest lints work!
- Loading branch information
1 parent
3d2766d
commit 1c76d69
Showing
8 changed files
with
159 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
SemverQuery( | ||
id: "feature_missing", | ||
human_readable_name: "package feature removed or renamed", | ||
description: "A feature has been removed from this package's Cargo.toml.", | ||
required_update: Major, | ||
lint_level: Deny, | ||
reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#cargo-feature-remove"), | ||
query: r#" | ||
{ | ||
CrateDiff { | ||
baseline { | ||
feature { | ||
# Until cargo ships with support for private and/or unstable feature names, | ||
# we'll rely on feature names to detect whether to flag feature removals. | ||
# | ||
# This lint will ignore features that match any of the following: | ||
# - start with an underscore (`_`) character | ||
# - are named `unstable`, `nightly`, or `bench` | ||
# - have a prefix of `unstable`, `nightly`, or `bench` followed by | ||
# a dash (`-`) or underscore (`_`) character. | ||
# | ||
# Cargo tracking issues: | ||
# - unstable/nightly features: https://github.com/rust-lang/cargo/issues/10881 | ||
# - private/hidden features: https://github.com/rust-lang/cargo/issues/10882 | ||
name @tag | ||
@filter(op: "not_regex", value: ["$unstable_feature_pattern"]) | ||
@filter(op: "not_has_prefix", value: ["$underscore"]) | ||
@output | ||
# An explicit ordering key is needed since we don't have span information, | ||
# which what we usually use to order results in tests. | ||
name @output(name: "ordering_key") | ||
} | ||
} | ||
current { | ||
feature @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | ||
name @filter(op: "=", value: ["%name"]) | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"zero": 0, | ||
"unstable_feature_pattern": "^(?:unstable|nightly|bench)(?:[-_].*)?$", | ||
"underscore": "_", | ||
}, | ||
error_message: "A feature has been removed from this package's Cargo.toml. This will break downstream crates that enable this feature.", | ||
per_result_error_template: Some("feature {{name}} in the package's Cargo.toml"), | ||
// TODO: It's currently not possible to write witnesses for manifest lints, | ||
// since we'd need to generate a *Cargo.toml* witness instead of a Rust code witness. | ||
// Issue: https://github.com/obi1kenobi/cargo-semver-checks/issues/1008 | ||
witness: None, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
publish = false | ||
name = "feature_missing" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
||
[features] | ||
still_present = [] | ||
# Explicitly-added feature, to replace the implicit feature defined by | ||
# the `optional = true` dependency in the previous crate version. | ||
rand_core = [] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
publish = false | ||
name = "feature_missing" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
# Since `rand` isn't used in a feature with `dep:rand` syntax, | ||
# it defines an implicit feature by that name. | ||
# Removing that implicit feature is a breaking change. | ||
rand = { version = "*", optional = true } | ||
# However, re-adding an explicit feature after removing the implicit one | ||
# will avoid the breakage. | ||
rand_core = { version = "*", optional = true} | ||
|
||
[features] | ||
still_present = [] | ||
going_missing = [] | ||
|
||
# We ignore unstable-looking feature names. | ||
# All of the following will be removed, and none of them should be flagged. | ||
unstable = [] | ||
nightly = [] | ||
bench = [] | ||
unstable-dash = [] | ||
unstable_underscore = [] | ||
nightly-dash = [] | ||
nightly_underscore = [] | ||
bench-dash = [] | ||
bench_underscore = [] | ||
_underscore_prefix = [] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
source: src/query.rs | ||
expression: "&query_execution_results" | ||
--- | ||
{ | ||
"./test_crates/feature_missing/": [ | ||
{ | ||
"name": String("going_missing"), | ||
"ordering_key": String("going_missing"), | ||
}, | ||
{ | ||
"name": String("rand"), | ||
"ordering_key": String("rand"), | ||
}, | ||
], | ||
"./test_crates/function_feature_changed/": [ | ||
{ | ||
"name": String("feature_to_be_removed"), | ||
"ordering_key": String("feature_to_be_removed"), | ||
}, | ||
], | ||
} |