-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement new_struct_added lint #495
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
SemverQuery( | ||
id: "new_struct_added", | ||
human_readable_name: "new struct added", | ||
description: "A new public struct has been exposed.", | ||
required_update: Minor, | ||
|
||
// TODO: Change the reference link to point to the cargo semver reference | ||
// once it has a section on attribute #[must_use]. | ||
reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"), | ||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like copy-pasta, change it to |
||
query: r#" | ||
{ | ||
CrateDiff { | ||
current { | ||
item { | ||
... on Struct { | ||
name @tag(name: "new_crate_name") @output(name: "new_struct_added_name") | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
|
||
span_: span { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
|
||
baseline { | ||
item @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | ||
... on Struct { | ||
name @filter(op: "=", value: ["%new_crate_name"]) | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
} | ||
} | ||
} | ||
Comment on lines
+14
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will actually also fire on structs that are just moved, renamed, and re-exported in their original place under their new name, which is a false-positive unless there's a new name in the public API. You'll need to use |
||
} | ||
}"#, | ||
arguments: { | ||
"public": "public", | ||
"zero": 0, | ||
}, | ||
error_message: "A new struct has been added to externally exposed API, this requires a minor version bump.", | ||
per_result_error_template: Some("struct {{new_struct_added_name}} in {{span_filename}}:{{span_begin_line}}"), | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
publish = false | ||
name = "new_struct_added" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
struct A; | ||
pub struct B; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
publish = false | ||
name = "new_struct_added" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
struct A; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"./test_crates/inherent_method_must_use_added/": [ | ||
{ | ||
"new_struct_added_name": String("EnumToStructWithMustUseMethods"), | ||
"span_begin_line": Uint64(8), | ||
"span_filename": String("src/item_type_changed_inherent_method_must_use_added.rs"), | ||
}, | ||
{ | ||
"new_struct_added_name": String("UnionToStructWithMustUseMethods"), | ||
"span_begin_line": Uint64(141), | ||
"span_filename": String("src/item_type_changed_inherent_method_must_use_added.rs"), | ||
}, | ||
{ | ||
"new_struct_added_name": String("NewStructWithMustUseMethods"), | ||
"span_begin_line": Uint64(68), | ||
"span_filename": String("src/struct_inherent_method_must_use_added.rs"), | ||
}, | ||
], | ||
"./test_crates/method_moved_to_trait_must_use_added/": [ | ||
{ | ||
"new_struct_added_name": String("NewStructWithTraitMustUseMethods"), | ||
"span_begin_line": Uint64(147), | ||
"span_filename": String("src/struct_method_moved_to_trait_must_use_added.rs"), | ||
}, | ||
], | ||
"./test_crates/move_item_and_reexport/": [ | ||
{ | ||
"new_struct_added_name": String("HasBeenRenamedTypedefReexport"), | ||
"span_begin_line": Uint64(25), | ||
"span_filename": String("src/lib.rs"), | ||
}, | ||
{ | ||
"new_struct_added_name": String("HasBeenRenamedTypedefWithGenericsReexport"), | ||
"span_begin_line": Uint64(27), | ||
"span_filename": String("src/lib.rs"), | ||
}, | ||
], | ||
"./test_crates/new_struct_added/": [ | ||
{ | ||
"new_struct_added_name": String("B"), | ||
"span_begin_line": Uint64(2), | ||
"span_filename": String("src/lib.rs"), | ||
}, | ||
], | ||
"./test_crates/nonbreaking_item_rename/": [ | ||
{ | ||
"new_struct_added_name": String("NewName"), | ||
"span_begin_line": Uint64(2), | ||
"span_filename": String("src/lib.rs"), | ||
}, | ||
], | ||
"./test_crates/struct_must_use_added/": [ | ||
{ | ||
"new_struct_added_name": String("MustUseNewStruct"), | ||
"span_begin_line": Uint64(60), | ||
"span_filename": String("src/lib.rs"), | ||
}, | ||
], | ||
"./test_crates/type_marked_deprecated/": [ | ||
{ | ||
"new_struct_added_name": String("DeprecatedNewStruct"), | ||
"span_begin_line": Uint64(57), | ||
"span_filename": String("src/structs.rs"), | ||
}, | ||
], | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is lacking a trailing newline, please configure your editor to add them automatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
With the new version of
cargo-semver-checks
, it is now possible to have allow-by-default and warn-by-default checks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably make this
Allow
by default. I'm sure many users will want to opt-in, but it might be a bit noisy to enable for everyone.