Skip to content

Commit 44f74fd

Browse files
committed
chore: configure centralized clippy lints
- Add [workspace.lints] with clippy::all, pedantic, nursery, cargo - Forbid unsafe_code at workspace level - Add [lints] workspace = true to all crates - Apply clippy --fix for auto-fixable issues - Allow noisy lints for incremental improvement - Fix ref_option in npm parser - Fix unnecessary_literal_bound in tests
1 parent d05462b commit 44f74fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+515
-436
lines changed

Cargo.toml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,104 @@ tracing-subscriber = "0.3"
4545
urlencoding = "2.1"
4646
zed_extension_api = "0.7"
4747

48+
[workspace.lints.rust]
49+
unsafe_code = "forbid"
50+
missing_docs = "allow"
51+
missing_debug_implementations = "allow"
52+
unreachable_pub = "warn"
53+
54+
[workspace.lints.clippy]
55+
all = { level = "warn", priority = -1 }
56+
pedantic = { level = "warn", priority = -1 }
57+
nursery = { level = "warn", priority = -1 }
58+
cargo = { level = "warn", priority = -1 }
59+
60+
# Allowed lints - too noisy for this codebase
61+
module_name_repetitions = "allow"
62+
similar_names = "allow"
63+
too_many_lines = "allow"
64+
missing_errors_doc = "allow"
65+
missing_panics_doc = "allow"
66+
must_use_candidate = "allow"
67+
single_match_else = "allow"
68+
69+
# Documentation lints - allow for now, can enable incrementally
70+
doc_markdown = "allow"
71+
missing_docs_in_private_items = "allow"
72+
73+
# Cargo lints - metadata can be added later
74+
cargo_common_metadata = "allow"
75+
76+
# Nursery lints that are too pedantic
77+
option_if_let_else = "allow"
78+
future_not_send = "allow"
79+
redundant_pub_crate = "allow"
80+
81+
# Pattern-matching lints - allow for now
82+
wildcard_enum_match_arm = "allow"
83+
redundant_else = "allow"
84+
85+
# Style lints - allow for readability
86+
manual_let_else = "allow"
87+
items_after_statements = "allow"
88+
89+
# Type conversion lints - allow where intentional
90+
cast_possible_truncation = "allow"
91+
cast_precision_loss = "allow"
92+
cast_sign_loss = "allow"
93+
94+
# Nursery performance lints that need review
95+
significant_drop_tightening = "allow"
96+
97+
# Cargo lints that conflict with workspace setup
98+
multiple_crate_versions = "allow"
99+
100+
# Style lints - allow for now, can be fixed incrementally
101+
uninlined_format_args = "allow"
102+
explicit_iter_loop = "allow"
103+
redundant_closure_for_method_calls = "allow"
104+
match_wildcard_for_single_variants = "allow"
105+
106+
# Function lints - allow for now
107+
missing_const_for_fn = "allow"
108+
unnecessary_wraps = "allow"
109+
110+
# LazyLock migration - allow until we can target newer MSRV
111+
non_std_lazy_statics = "allow"
112+
113+
# HashMap generics - too noisy for internal APIs
114+
implicit_hasher = "allow"
115+
116+
# Performance lints that are pedantic
117+
map_unwrap_or = "allow"
118+
needless_collect = "allow"
119+
or_fun_call = "allow"
120+
format_push_string = "allow"
121+
122+
# Documentation lints
123+
doc_link_with_quotes = "allow"
124+
125+
# Derive lints - can be fixed incrementally
126+
derive_partial_eq_without_eq = "allow"
127+
128+
# Test-specific lints
129+
used_underscore_binding = "allow"
130+
ignore_without_reason = "allow"
131+
132+
# API design lints that need review
133+
unused_self = "allow"
134+
unused_async = "allow"
135+
136+
# Pattern matching lints
137+
match_same_arms = "allow"
138+
139+
# File extension checks - too strict
140+
case_sensitive_file_extension_comparisons = "allow"
141+
142+
# Style preferences
143+
default_trait_access = "allow"
144+
needless_pass_by_value = "allow"
145+
48146
[profile.release]
49147
lto = true
50148
codegen-units = 1

crates/deps-cargo/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ repository.workspace = true
99
description = "Cargo.toml support for deps-lsp"
1010
publish = true
1111

12+
[lints]
13+
workspace = true
14+
1215
[dependencies]
1316
deps-core = { workspace = true }
1417
async-trait = { workspace = true }

crates/deps-cargo/benches/cargo_benchmarks.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ resolver = "2"
108108
i % 20
109109
));
110110
} else if i % 3 == 1 {
111-
content.push_str(&format!("dep{} = {{ workspace = true }}\n", i));
111+
content.push_str(&format!("dep{i} = {{ workspace = true }}\n"));
112112
} else {
113113
content.push_str(&format!("dep{} = \"1.{}.0\"\n", i, i % 20));
114114
}
@@ -145,24 +145,24 @@ fn bench_cargo_parsing(c: &mut Criterion) {
145145

146146
group.bench_function("small_5_deps", |b| {
147147
let url = test_url();
148-
b.iter(|| parse_cargo_toml(black_box(SMALL_CARGO_TOML), black_box(&url)))
148+
b.iter(|| parse_cargo_toml(black_box(SMALL_CARGO_TOML), black_box(&url)));
149149
});
150150

151151
group.bench_function("medium_25_deps", |b| {
152152
let url = test_url();
153-
b.iter(|| parse_cargo_toml(black_box(MEDIUM_CARGO_TOML), black_box(&url)))
153+
b.iter(|| parse_cargo_toml(black_box(MEDIUM_CARGO_TOML), black_box(&url)));
154154
});
155155

156156
let large_toml = generate_large_cargo_toml();
157157
group.bench_function("large_100_deps", |b| {
158158
let url = test_url();
159-
b.iter(|| parse_cargo_toml(black_box(&large_toml), black_box(&url)))
159+
b.iter(|| parse_cargo_toml(black_box(&large_toml), black_box(&url)));
160160
});
161161

162162
let workspace_toml = generate_workspace_cargo_toml();
163163
group.bench_function("workspace_100_deps", |b| {
164164
let url = test_url();
165-
b.iter(|| parse_cargo_toml(black_box(&workspace_toml), black_box(&url)))
165+
b.iter(|| parse_cargo_toml(black_box(&workspace_toml), black_box(&url)));
166166
});
167167

168168
group.finish();
@@ -188,12 +188,12 @@ serde = { version = "1.0", features = ["derive", "std"], default-features = fals
188188

189189
group.bench_function("inline_dependency", |b| {
190190
let url = test_url();
191-
b.iter(|| parse_cargo_toml(black_box(inline), black_box(&url)))
191+
b.iter(|| parse_cargo_toml(black_box(inline), black_box(&url)));
192192
});
193193

194194
group.bench_function("table_dependency", |b| {
195195
let url = test_url();
196-
b.iter(|| parse_cargo_toml(black_box(table), black_box(&url)))
196+
b.iter(|| parse_cargo_toml(black_box(table), black_box(&url)));
197197
});
198198

199199
group.finish();
@@ -226,15 +226,14 @@ fn bench_registry_parsing(c: &mut Criterion) {
226226
.lines()
227227
.filter_map(|line| serde_json::from_str(line).ok())
228228
.collect();
229-
})
229+
});
230230
});
231231

232232
// Generate large sparse index response (100 versions)
233233
let mut large_index = String::new();
234234
for i in 0..100 {
235235
large_index.push_str(&format!(
236-
r#"{{"name":"crate","vers":"1.0.{}","deps":[],"cksum":"abc{}","features":{{}},"yanked":false}}"#,
237-
i, i
236+
r#"{{"name":"crate","vers":"1.0.{i}","deps":[],"cksum":"abc{i}","features":{{}},"yanked":false}}"#
238237
));
239238
large_index.push('\n');
240239
}
@@ -245,7 +244,7 @@ fn bench_registry_parsing(c: &mut Criterion) {
245244
.lines()
246245
.filter_map(|line| serde_json::from_str(line).ok())
247246
.collect();
248-
})
247+
});
249248
});
250249

251250
group.finish();
@@ -271,13 +270,13 @@ fn bench_version_matching(c: &mut Criterion) {
271270
// Simple version requirement
272271
let simple_req = VersionReq::parse("1.0").unwrap();
273272
group.bench_function("simple_version_req", |b| {
274-
b.iter(|| simple_req.matches(black_box(&latest)))
273+
b.iter(|| simple_req.matches(black_box(&latest)));
275274
});
276275

277276
// Complex version requirement (multiple constraints)
278277
let complex_req = VersionReq::parse(">=1.0.100, <2.0").unwrap();
279278
group.bench_function("complex_version_req", |b| {
280-
b.iter(|| complex_req.matches(black_box(&latest)))
279+
b.iter(|| complex_req.matches(black_box(&latest)));
281280
});
282281

283282
// Find latest matching version
@@ -288,7 +287,7 @@ fn bench_version_matching(c: &mut Criterion) {
288287
.filter(|v| simple_req.matches(v))
289288
.max()
290289
.cloned()
291-
})
290+
});
292291
});
293292

294293
group.finish();
@@ -318,8 +317,8 @@ serde = { version = "1.0", features = ["derive"] }"#,
318317
),
319318
(
320319
"workspace_inheritance",
321-
r#"[dependencies]
322-
serde = { workspace = true }"#,
320+
r"[dependencies]
321+
serde = { workspace = true }",
323322
),
324323
(
325324
"git_dependency",
@@ -344,7 +343,7 @@ default-features = false"#,
344343
for (name, content) in formats {
345344
group.bench_with_input(BenchmarkId::from_parameter(name), &content, |b, content| {
346345
let url = test_url();
347-
b.iter(|| parse_cargo_toml(black_box(content), black_box(&url)))
346+
b.iter(|| parse_cargo_toml(black_box(content), black_box(&url)));
348347
});
349348
}
350349

@@ -367,7 +366,7 @@ tokio = "1.0" # Зависимость с кириллицей
367366

368367
c.bench_function("unicode_parsing", |b| {
369368
let url = test_url();
370-
b.iter(|| parse_cargo_toml(black_box(unicode_toml), black_box(&url)))
369+
b.iter(|| parse_cargo_toml(black_box(unicode_toml), black_box(&url)));
371370
});
372371
}
373372

crates/deps-cargo/src/ecosystem.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ mod tests {
340340
}
341341

342342
fn uri(&self) -> &Uri {
343-
static URI: once_cell::sync::Lazy<Uri> =
344-
once_cell::sync::Lazy::new(|| Uri::from_file_path("/test/Cargo.toml").unwrap());
343+
static URI: std::sync::LazyLock<Uri> =
344+
std::sync::LazyLock::new(|| Uri::from_file_path("/test/Cargo.toml").unwrap());
345345
&URI
346346
}
347347

@@ -734,6 +734,6 @@ mod tests {
734734
// Real packages with special characters
735735
let results = ecosystem.complete_package_names("tokio-ut").await;
736736
assert!(!results.is_empty());
737-
assert!(results.iter().any(|r| r.label.contains("-")));
737+
assert!(results.iter().any(|r| r.label.contains('-')));
738738
}
739739
}

crates/deps-cargo/src/error.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,18 @@ impl CargoError {
137137
impl From<deps_core::DepsError> for CargoError {
138138
fn from(err: deps_core::DepsError) -> Self {
139139
match err {
140-
deps_core::DepsError::ParseError { source, .. } => {
141-
CargoError::CacheError(source.to_string())
142-
}
143-
deps_core::DepsError::CacheError(msg) => CargoError::CacheError(msg),
144-
deps_core::DepsError::InvalidVersionReq(msg) => CargoError::InvalidVersionSpecifier {
140+
deps_core::DepsError::ParseError { source, .. } => Self::CacheError(source.to_string()),
141+
deps_core::DepsError::CacheError(msg) => Self::CacheError(msg),
142+
deps_core::DepsError::InvalidVersionReq(msg) => Self::InvalidVersionSpecifier {
145143
specifier: String::new(),
146144
message: msg,
147145
},
148-
deps_core::DepsError::Io(e) => CargoError::Io(e),
149-
deps_core::DepsError::Json(e) => CargoError::ApiResponseError {
146+
deps_core::DepsError::Io(e) => Self::Io(e),
147+
deps_core::DepsError::Json(e) => Self::ApiResponseError {
150148
package: String::new(),
151149
source: e,
152150
},
153-
other => CargoError::CacheError(other.to_string()),
151+
other => Self::CacheError(other.to_string()),
154152
}
155153
}
156154
}
@@ -159,32 +157,28 @@ impl From<deps_core::DepsError> for CargoError {
159157
impl From<CargoError> for deps_core::DepsError {
160158
fn from(err: CargoError) -> Self {
161159
match err {
162-
CargoError::TomlParseError { source } => deps_core::DepsError::ParseError {
160+
CargoError::TomlParseError { source } => Self::ParseError {
163161
file_type: "Cargo.toml".into(),
164162
source: Box::new(source),
165163
},
166-
CargoError::InvalidVersionSpecifier { message, .. } => {
167-
deps_core::DepsError::InvalidVersionReq(message)
168-
}
164+
CargoError::InvalidVersionSpecifier { message, .. } => Self::InvalidVersionReq(message),
169165
CargoError::PackageNotFound { package } => {
170-
deps_core::DepsError::CacheError(format!("Crate '{}' not found", package))
166+
Self::CacheError(format!("Crate '{package}' not found"))
171167
}
172-
CargoError::RegistryError { package, source } => deps_core::DepsError::ParseError {
173-
file_type: format!("crates.io registry for {}", package),
168+
CargoError::RegistryError { package, source } => Self::ParseError {
169+
file_type: format!("crates.io registry for {package}"),
174170
source,
175171
},
176-
CargoError::ApiResponseError { source, .. } => deps_core::DepsError::Json(source),
177-
CargoError::InvalidStructure { message } => deps_core::DepsError::CacheError(message),
172+
CargoError::ApiResponseError { source, .. } => Self::Json(source),
173+
CargoError::InvalidStructure { message } => Self::CacheError(message),
178174
CargoError::MissingField { section, field } => {
179-
deps_core::DepsError::CacheError(format!("Missing '{}' in {}", field, section))
180-
}
181-
CargoError::WorkspaceError { message } => deps_core::DepsError::CacheError(message),
182-
CargoError::InvalidUri { uri } => {
183-
deps_core::DepsError::CacheError(format!("Invalid URI: {}", uri))
175+
Self::CacheError(format!("Missing '{field}' in {section}"))
184176
}
185-
CargoError::CacheError(msg) => deps_core::DepsError::CacheError(msg),
186-
CargoError::Io(e) => deps_core::DepsError::Io(e),
187-
CargoError::Other(e) => deps_core::DepsError::CacheError(e.to_string()),
177+
CargoError::WorkspaceError { message } => Self::CacheError(message),
178+
CargoError::InvalidUri { uri } => Self::CacheError(format!("Invalid URI: {uri}")),
179+
CargoError::CacheError(msg) => Self::CacheError(msg),
180+
CargoError::Io(e) => Self::Io(e),
181+
CargoError::Other(e) => Self::CacheError(e.to_string()),
188182
}
189183
}
190184
}

crates/deps-cargo/src/formatter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ pub struct CargoFormatter;
44

55
impl EcosystemFormatter for CargoFormatter {
66
fn format_version_for_code_action(&self, version: &str) -> String {
7-
format!("\"{}\"", version)
7+
format!("\"{version}\"")
88
}
99

1010
fn package_url(&self, name: &str) -> String {
11-
format!("https://crates.io/crates/{}", name)
11+
format!("https://crates.io/crates/{name}")
1212
}
1313
}
1414

crates/deps-cargo/src/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl EcosystemHandler for CargoHandler {
5151
}
5252

5353
fn format_version_for_edit(_dep: &Self::Dependency, version: &str) -> String {
54-
format!("\"{}\"", version)
54+
format!("\"{version}\"")
5555
}
5656

5757
fn is_deprecated(version: &crate::CargoVersion) -> bool {

crates/deps-cargo/src/lockfile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl LockFileProvider for CargoLockParser {
9999
return Ok(packages);
100100
};
101101

102-
for table in package_array.iter() {
102+
for table in package_array {
103103
// Extract required fields
104104
let Some(name) = table.get("name").and_then(|v: &toml_edit::Item| v.as_str()) else {
105105
tracing::warn!("Package missing name field");
@@ -338,9 +338,9 @@ source = "git+https://github.com/user/repo#abc123"
338338

339339
#[tokio::test]
340340
async fn test_parse_empty_cargo_lock() {
341-
let lockfile_content = r#"
341+
let lockfile_content = r"
342342
version = 4
343-
"#;
343+
";
344344

345345
let temp_dir = tempfile::tempdir().unwrap();
346346
let lockfile_path = temp_dir.path().join("Cargo.lock");

0 commit comments

Comments
 (0)