Skip to content
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

New lint: Pub module level static missing #496

Merged
merged 11 commits into from
Jul 15, 2023
47 changes: 47 additions & 0 deletions src/lints/pub_static_missing.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
SemverQuery(
id: "pub_static_missing",
human_readable_name: "pub static is missing",
description: "A pub static is missing, renamed, or made private",
required_update: Major,
reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#item-remove"),
query: r#"
{
CrateDiff {
baseline {
item {
... on Static {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output

importable_path {
path @output @tag
}

span_: span @optional {
filename @output
begin_line @output
}
}
}
}
current {
item @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
# A GlobalValue is a supertype of Static and Constant
... on GlobalValue {
visibility_limit @filter(op: "=", value: ["$public"])

importable_path {
path @filter(op: "=", value: ["%path"])
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"zero": 0,
},
error_message: "A public static is missing, renamed, or made private.",
per_result_error_template: Some("{{name}} in file {{span_filename}}:{{span_begin_line}}"),
)
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,5 @@ add_lints!(
enum_tuple_variant_field_added,
trait_removed_supertrait,
pub_module_level_const_missing,
pub_static_missing,
);
7 changes: 7 additions & 0 deletions test_crates/pub_static_missing/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "pub_static_missing"
version = "0.1.0"
edition = "2021"

[dependencies]
30 changes: 30 additions & 0 deletions test_crates/pub_static_missing/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pub static PUB_STATIC_IN_GLOBAL: i32 = 0;
pub static PUB_STATIC_IN_GLOBAL_IS_RENAMED: i32 = 0;
pub const PUB_STATIC_IN_GLOBAL_WILL_BE_CONST: i32 = 0;
const PUB_STATIC_IN_GLOBAL_WILL_BE_PRIVATE_CONST: i32 = 0;
static PUB_STATIC_IN_GLOBAL_WILL_BE_PRIVATE_STATIC: i32 = 0;

mod re_exporter {
pub const SPECIAL_CONST: i32 = 0;
pub static SPECIAL_STATIC: i32 = 0;
}

pub mod my_module {
pub static PUB_STATIC_IN_MODULE: i32 = 0;
pub static PUB_STATIC_IN_MODULE_IS_RENAMED: i32 = 0;
pub const PUB_STATIC_IN_MODULE_WILL_BE_CONST: i32 = 0;
const PUB_STATIC_IN_MODULE_WILL_BE_PRIVATE_CONST: i32 = 0;
static PUB_STATIC_IN_MODULE_WILL_BE_PRIVATE_STATIC: i32 = 0;
pub use crate::re_exporter::SPECIAL_CONST as PUB_STATIC_IN_MODULE_WILL_RE_EXPORT_CONST;
pub use crate::re_exporter::SPECIAL_STATIC as PUB_STATIC_IN_MODULE_WILL_RE_EXPORT;

pub mod my_module_nested {
pub static PUB_STATIC_IN_NESTED_MODULE: i32 = 0;
pub static PUB_STATIC_IN_NESTED_MODULE_IS_RENAMED: i32 = 0;
pub const PUB_STATIC_IN_NESTED_MODULE_WILL_BE_CONST: i32 = 0;
const PUB_STATIC_IN_NESTED_MODULE_WILL_BE_PRIVATE_CONST: i32 = 0;
static PUB_STATIC_IN_NESTED_MODULE_WILL_BE_PRIVATE_STATIC: i32 = 0;
pub use crate::re_exporter::SPECIAL_CONST as PUB_STATIC_IN_NESTED_MODULE_WILL_RE_EXPORT_CONST;
pub use crate::re_exporter::SPECIAL_STATIC as PUB_STATIC_IN_NESTED_MODULE_WILL_RE_EXPORT;
}
}
7 changes: 7 additions & 0 deletions test_crates/pub_static_missing/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "pub_static_missing"
version = "0.1.0"
edition = "2021"

[dependencies]
28 changes: 28 additions & 0 deletions test_crates/pub_static_missing/old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pub static PUB_STATIC_IN_GLOBAL: i32 = 0;
pub static PUB_STATIC_IN_GLOBAL_WILL_REMOVE: i32 = 0;
pub static PUB_STATIC_IN_GLOBAL_WILL_RENAME: i32 = 0;
pub static PUB_STATIC_IN_GLOBAL_WILL_BE_CONST: i32 = 0;
pub static PUB_STATIC_IN_GLOBAL_WILL_BE_PRIVATE_CONST: i32 = 0;
pub static PUB_STATIC_IN_GLOBAL_WILL_BE_PRIVATE_STATIC: i32 = 0;

pub mod my_module {
pub static PUB_STATIC_IN_MODULE: i32 = 0;
pub static PUB_STATIC_IN_MODULE_WILL_REMOVE: i32 = 0;
pub static PUB_STATIC_IN_MODULE_WILL_RENAME: i32 = 0;
pub static PUB_STATIC_IN_MODULE_WILL_BE_CONST: i32 = 0;
pub static PUB_STATIC_IN_MODULE_WILL_BE_PRIVATE_CONST: i32 = 0;
pub static PUB_STATIC_IN_MODULE_WILL_BE_PRIVATE_STATIC: i32 = 0;
pub static PUB_STATIC_IN_MODULE_WILL_RE_EXPORT: i32 = 0;
pub static PUB_STATIC_IN_MODULE_WILL_RE_EXPORT_CONST: i32 = 0;

pub mod my_module_nested {
pub static PUB_STATIC_IN_NESTED_MODULE: i32 = 0;
pub static PUB_STATIC_IN_NESTED_MODULE_WILL_REMOVE: i32 = 0;
pub static PUB_STATIC_IN_NESTED_MODULE_WILL_RENAME: i32 = 0;
pub static PUB_STATIC_IN_NESTED_MODULE_WILL_BE_CONST: i32 = 0;
pub static PUB_STATIC_IN_NESTED_MODULE_WILL_BE_PRIVATE_CONST: i32 = 0;
pub static PUB_STATIC_IN_NESTED_MODULE_WILL_BE_PRIVATE_STATIC: i32 = 0;
pub static PUB_STATIC_IN_NESTED_MODULE_WILL_RE_EXPORT: i32 = 0;
pub static PUB_STATIC_IN_NESTED_MODULE_WILL_RE_EXPORT_CONST: i32 = 0;
}
}
136 changes: 136 additions & 0 deletions test_outputs/pub_static_missing.output.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"./test_crates/pub_static_missing/": [
{
"name": String("PUB_STATIC_IN_GLOBAL_WILL_REMOVE"),
"path": List([
String("pub_static_missing"),
String("PUB_STATIC_IN_GLOBAL_WILL_REMOVE"),
]),
"span_begin_line": Uint64(2),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_GLOBAL_WILL_RENAME"),
"path": List([
String("pub_static_missing"),
String("PUB_STATIC_IN_GLOBAL_WILL_RENAME"),
]),
"span_begin_line": Uint64(3),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_GLOBAL_WILL_BE_PRIVATE_CONST"),
"path": List([
String("pub_static_missing"),
String("PUB_STATIC_IN_GLOBAL_WILL_BE_PRIVATE_CONST"),
]),
"span_begin_line": Uint64(5),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_GLOBAL_WILL_BE_PRIVATE_STATIC"),
"path": List([
String("pub_static_missing"),
String("PUB_STATIC_IN_GLOBAL_WILL_BE_PRIVATE_STATIC"),
]),
"span_begin_line": Uint64(6),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_MODULE_WILL_REMOVE"),
"path": List([
String("pub_static_missing"),
String("my_module"),
String("PUB_STATIC_IN_MODULE_WILL_REMOVE"),
]),
"span_begin_line": Uint64(10),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_MODULE_WILL_RENAME"),
"path": List([
String("pub_static_missing"),
String("my_module"),
String("PUB_STATIC_IN_MODULE_WILL_RENAME"),
]),
"span_begin_line": Uint64(11),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_MODULE_WILL_BE_PRIVATE_CONST"),
"path": List([
String("pub_static_missing"),
String("my_module"),
String("PUB_STATIC_IN_MODULE_WILL_BE_PRIVATE_CONST"),
]),
"span_begin_line": Uint64(13),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_MODULE_WILL_BE_PRIVATE_STATIC"),
"path": List([
String("pub_static_missing"),
String("my_module"),
String("PUB_STATIC_IN_MODULE_WILL_BE_PRIVATE_STATIC"),
]),
"span_begin_line": Uint64(14),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_NESTED_MODULE_WILL_REMOVE"),
"path": List([
String("pub_static_missing"),
String("my_module"),
String("my_module_nested"),
String("PUB_STATIC_IN_NESTED_MODULE_WILL_REMOVE"),
]),
"span_begin_line": Uint64(20),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_NESTED_MODULE_WILL_RENAME"),
"path": List([
String("pub_static_missing"),
String("my_module"),
String("my_module_nested"),
String("PUB_STATIC_IN_NESTED_MODULE_WILL_RENAME"),
]),
"span_begin_line": Uint64(21),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_NESTED_MODULE_WILL_BE_PRIVATE_CONST"),
"path": List([
String("pub_static_missing"),
String("my_module"),
String("my_module_nested"),
String("PUB_STATIC_IN_NESTED_MODULE_WILL_BE_PRIVATE_CONST"),
]),
"span_begin_line": Uint64(23),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("PUB_STATIC_IN_NESTED_MODULE_WILL_BE_PRIVATE_STATIC"),
"path": List([
String("pub_static_missing"),
String("my_module"),
String("my_module_nested"),
String("PUB_STATIC_IN_NESTED_MODULE_WILL_BE_PRIVATE_STATIC"),
]),
"span_begin_line": Uint64(24),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
}