Skip to content

Commit d02595e

Browse files
authored
chore(config): Enable pedantic lints for graph and builders (#26593)
1 parent b854614 commit d02595e

10 files changed

Lines changed: 148 additions & 41 deletions

File tree

‎src/config/api.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use std::net::{Ipv4Addr, SocketAddr};
24

35
use url::Url;
@@ -44,18 +46,24 @@ const fn default_enabled() -> bool {
4446
/// By default, the API binds to 127.0.0.1:8686. This function should remain public;
4547
/// `vector top` will use it to determine which to connect to by default, if no URL
4648
/// override is provided.
49+
#[must_use]
4750
pub fn default_address() -> Option<SocketAddr> {
4851
Some(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 8686))
4952
}
5053

5154
/// Default gRPC API address for `vector top` and other API clients
55+
#[must_use]
56+
// https://github.com/vectordotdev/vector/issues/23659
57+
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
5258
pub fn default_grpc_url() -> Url {
5359
let addr = default_address().unwrap();
5460
Url::parse(&format!("http://{addr}"))
5561
.expect("Couldn't parse default API URL. Please report this.")
5662
}
5763

5864
impl Options {
65+
// https://github.com/vectordotdev/vector/issues/23659
66+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
5967
pub fn merge(&mut self, other: Self) -> Result<(), String> {
6068
// Merge options
6169

‎src/config/builder.rs‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use std::{path::Path, time::Duration};
24

35
use indexmap::IndexMap;
@@ -132,6 +134,8 @@ impl From<Config> for ConfigBuilder {
132134
}
133135

134136
impl ConfigBuilder {
137+
// https://github.com/vectordotdev/vector/issues/23659
138+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
135139
pub fn build(self) -> Result<Config, Vec<String>> {
136140
let (config, warnings) = self.build_with_warnings()?;
137141

@@ -142,6 +146,8 @@ impl ConfigBuilder {
142146
Ok(config)
143147
}
144148

149+
// https://github.com/vectordotdev/vector/issues/23659
150+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
145151
pub fn build_with_warnings(self) -> Result<(Config, Vec<String>), Vec<String>> {
146152
compiler::compile(self)
147153
}
@@ -154,7 +160,7 @@ impl ConfigBuilder {
154160
) {
155161
let inputs = inputs
156162
.iter()
157-
.map(|value| value.to_string())
163+
.map(std::string::ToString::to_string)
158164
.collect::<Vec<_>>();
159165
self.enrichment_tables.insert(
160166
ComponentKey::from(key.into()),
@@ -175,7 +181,7 @@ impl ConfigBuilder {
175181
) {
176182
let inputs = inputs
177183
.iter()
178-
.map(|value| value.to_string())
184+
.map(std::string::ToString::to_string)
179185
.collect::<Vec<_>>();
180186
let sink = SinkOuter::new(inputs, sink);
181187
self.add_sink_outer(key, sink);
@@ -195,7 +201,7 @@ impl ConfigBuilder {
195201
) {
196202
let inputs = inputs
197203
.iter()
198-
.map(|value| value.to_string())
204+
.map(std::string::ToString::to_string)
199205
.collect::<Vec<_>>();
200206
let transform = TransformOuter::new(inputs, transform);
201207

@@ -207,6 +213,8 @@ impl ConfigBuilder {
207213
self.global.data_dir = Some(path.to_owned());
208214
}
209215

216+
// https://github.com/vectordotdev/vector/issues/23659
217+
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
210218
pub fn append(&mut self, with: Self) -> Result<(), Vec<String>> {
211219
let mut errors = Vec::new();
212220

@@ -273,11 +281,17 @@ impl ConfigBuilder {
273281
}
274282

275283
#[cfg(test)]
284+
#[must_use]
285+
// https://github.com/vectordotdev/vector/issues/23659
286+
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
276287
pub fn from_toml(input: &str) -> Self {
277288
crate::config::format::deserialize(input, crate::config::format::Format::Toml).unwrap()
278289
}
279290

280291
#[cfg(test)]
292+
#[must_use]
293+
// https://github.com/vectordotdev/vector/issues/23659
294+
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
281295
pub fn from_json(input: &str) -> Self {
282296
crate::config::format::deserialize(input, crate::config::format::Format::Json).unwrap()
283297
}

‎src/config/compiler.rs‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use indexmap::{IndexMap, IndexSet};
24
use std::sync::Arc;
35
use vector_lib::config::ComponentKey;
@@ -8,6 +10,8 @@ use super::{
810
sink::SinkOuter, transform::get_transform_output_ids, validation,
911
};
1012

13+
// https://github.com/vectordotdev/vector/issues/23659
14+
#[allow(clippy::too_many_lines, reason = "Preserve existing control flow")]
1115
pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<String>> {
1216
let mut errors = Vec::new();
1317

@@ -112,15 +116,15 @@ pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<
112116

113117
if errors.is_empty() {
114118
let mut config = Config {
115-
global,
116119
#[cfg(feature = "api")]
117120
api,
118121
schema,
122+
global,
119123
healthchecks,
120-
enrichment_tables,
121124
sources,
122125
sinks,
123126
transforms,
127+
enrichment_tables,
124128
tests,
125129
secret,
126130
graceful_shutdown_duration,
@@ -166,11 +170,11 @@ pub(crate) fn expand_globs(config: &mut ConfigBuilder) {
166170
.map(|output_id| output_id.to_string())
167171
.collect::<IndexSet<String>>();
168172

169-
for (id, transform) in config.transforms.iter_mut() {
173+
for (id, transform) in &mut config.transforms {
170174
expand_globs_inner(&mut transform.inputs, &id.to_string(), &candidates);
171175
}
172176

173-
for (id, sink) in config.sinks.iter_mut() {
177+
for (id, sink) in &mut config.sinks {
174178
expand_globs_inner(&mut sink.inputs, &id.to_string(), &candidates);
175179
}
176180
}
@@ -184,7 +188,7 @@ fn validate_sinks(config: &mut Config) -> Vec<String> {
184188
let mut errors = Vec::new();
185189

186190
// Validate direct sinks
187-
for (key, sink) in config.sinks.iter_mut() {
191+
for (key, sink) in &mut config.sinks {
188192
let dyn_sink: &dyn DynValidatedSink = sink.inner.as_ref();
189193
match dyn_sink.validate_dyn() {
190194
Ok(state) => sink.validated = Some(Arc::from(state)),
@@ -193,7 +197,7 @@ fn validate_sinks(config: &mut Config) -> Vec<String> {
193197
}
194198

195199
// Validate enrichment table sinks with resolved inputs.
196-
for (key, table) in config.enrichment_tables.iter_mut() {
200+
for (key, table) in &mut config.enrichment_tables {
197201
if let Some((_, sink)) = table.as_sink(key) {
198202
let dyn_sink: &dyn DynValidatedSink = sink.inner.as_ref();
199203
match dyn_sink.validate_dyn() {
@@ -215,7 +219,7 @@ enum InputMatcher {
215219

216220
impl InputMatcher {
217221
fn matches(&self, candidate: &str) -> bool {
218-
use InputMatcher::*;
222+
use InputMatcher::{Pattern, String};
219223

220224
match self {
221225
Pattern(pattern) => pattern.matches(candidate),
@@ -224,26 +228,29 @@ impl InputMatcher {
224228
}
225229
}
226230

231+
// https://github.com/vectordotdev/vector/issues/23659
232+
#[allow(clippy::similar_names, reason = "Naming cleanup deferred")]
227233
fn expand_globs_inner(inputs: &mut Inputs<String>, id: &str, candidates: &IndexSet<String>) {
228234
let raw_inputs = std::mem::take(inputs);
229235
for raw_input in raw_inputs {
230-
let matcher = glob::Pattern::new(&raw_input)
231-
.map(InputMatcher::Pattern)
232-
.unwrap_or_else(|error| {
236+
let matcher = glob::Pattern::new(&raw_input).map_or_else(
237+
|error| {
233238
warn!(message = "Invalid glob pattern for input.", component_id = %id, %error);
234-
InputMatcher::String(raw_input.to_string())
235-
});
239+
InputMatcher::String(raw_input.clone())
240+
},
241+
InputMatcher::Pattern,
242+
);
236243
let mut matched = false;
237244
for input in candidates {
238245
if matcher.matches(input) && input != id {
239246
matched = true;
240-
inputs.extend(Some(input.to_string()))
247+
inputs.extend(Some(input.clone()));
241248
}
242249
}
243250
// If it didn't work as a glob pattern, leave it in the inputs as-is. This lets us give
244251
// more accurate error messages about nonexistent inputs.
245252
if !matched {
246-
inputs.extend(Some(raw_input))
253+
inputs.extend(Some(raw_input));
247254
}
248255
}
249256
}

‎src/config/component.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use serde::Serialize;
24
use strum::EnumDiscriminants;
35
use vector_lib::configurable::{Configurable, ToValue};
@@ -64,6 +66,7 @@ impl<'a, T> Component<'a, T>
6466
where
6567
T: Configurable + Serialize + ToValue + Clone + 'static,
6668
{
69+
#[must_use]
6770
pub fn kind(&self) -> ComponentKind {
6871
self.into()
6972
}
@@ -72,6 +75,7 @@ where
7275
///
7376
/// Enrichment table inputs belong to the table's derived sink. A derived
7477
/// source is a separate component, whose key may differ from the table key.
78+
#[must_use]
7579
pub fn inputs(&self) -> Option<&'a [T]> {
7680
match self {
7781
Self::Source(_) => None,

‎src/config/diff.rs‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use std::collections::HashSet;
24

35
use indexmap::IndexMap;
@@ -15,10 +17,12 @@ pub struct ConfigDiff {
1517
}
1618

1719
impl ConfigDiff {
20+
#[must_use]
1821
pub fn initial(initial: &Config) -> Self {
1922
Self::new(&Config::default(), initial, HashSet::new())
2023
}
2124

25+
#[must_use]
2226
pub fn new(old: &Config, new: &Config, components_to_reload: HashSet<ComponentKey>) -> Self {
2327
ConfigDiff {
2428
sources: Difference::new(&old.sources, &new.sources, &components_to_reload),
@@ -34,6 +38,7 @@ impl ConfigDiff {
3438
}
3539

3640
/// Swaps removed with added in Differences.
41+
#[must_use]
3742
pub const fn flip(mut self) -> Self {
3843
self.sources.flip();
3944
self.transforms.flip();
@@ -43,6 +48,7 @@ impl ConfigDiff {
4348
}
4449

4550
/// Checks whether the given component is present at all.
51+
#[must_use]
4652
pub fn contains(&self, key: &ComponentKey) -> bool {
4753
self.sources.contains(key)
4854
|| self.transforms.contains(key)
@@ -51,6 +57,7 @@ impl ConfigDiff {
5157
}
5258

5359
/// Checks whether the given component is changed.
60+
#[must_use]
5461
pub fn is_changed(&self, key: &ComponentKey) -> bool {
5562
self.sources.is_changed(key)
5663
|| self.transforms.is_changed(key)
@@ -59,6 +66,7 @@ impl ConfigDiff {
5966
}
6067

6168
/// Checks whether the given component is removed.
69+
#[must_use]
6270
pub fn is_removed(&self, key: &ComponentKey) -> bool {
6371
self.sources.is_removed(key)
6472
|| self.transforms.is_removed(key)
@@ -147,6 +155,11 @@ impl EnrichmentTableDiff {
147155
}
148156

149157
#[derive(Debug)]
158+
// https://github.com/vectordotdev/vector/issues/23659
159+
#[allow(
160+
clippy::struct_field_names,
161+
reason = "Preserve field names and API contracts"
162+
)]
150163
pub struct Difference {
151164
pub to_remove: HashSet<ComponentKey>,
152165
pub to_change: HashSet<ComponentKey>,
@@ -402,7 +415,7 @@ mod tests {
402415
let diff = EnrichmentTableDiff::new(
403416
&old_config.enrichment_tables,
404417
&new_config.enrichment_tables,
405-
&Default::default(),
418+
&HashSet::default(),
406419
);
407420

408421
assert_eq!(
@@ -482,7 +495,7 @@ mod tests {
482495
let diff = EnrichmentTableDiff::new(
483496
&old_config.enrichment_tables,
484497
&new_config.enrichment_tables,
485-
&Default::default(),
498+
&HashSet::default(),
486499
);
487500
let table_key = ComponentKey::from("file_table");
488501

@@ -547,7 +560,7 @@ mod tests {
547560
let diff = EnrichmentTableDiff::new(
548561
&old_config.enrichment_tables,
549562
&new_config.enrichment_tables,
550-
&Default::default(),
563+
&HashSet::default(),
551564
);
552565

553566
assert_eq!(

‎src/config/enrichment_table.rs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::pedantic)]
2+
13
use std::{any::Any, sync::Arc};
24

35
use enum_dispatch::enum_dispatch;
@@ -50,7 +52,7 @@ where
5052
{
5153
Self {
5254
inner: inner.into(),
53-
graph: Default::default(),
55+
graph: GraphConfig::default(),
5456
inputs: Inputs::from_iter(inputs),
5557
validated: None,
5658
}
@@ -68,6 +70,12 @@ where
6870
// components to deserialization and build up the components and the topology in a more granular
6971
// way, with each having "modules" for inputs (making them valid as sinks), for healthchecks,
7072
// for providing outputs, etc.
73+
#[must_use]
74+
// https://github.com/vectordotdev/vector/issues/23659
75+
#[allow(
76+
clippy::default_trait_access,
77+
reason = "Preserve inferred default types"
78+
)]
7179
pub fn as_sink(&self, default_key: &ComponentKey) -> Option<(ComponentKey, SinkOuter<T>)> {
7280
self.inner.sink_config(default_key).map(|(key, sink)| {
7381
(
@@ -86,6 +94,12 @@ where
8694
})
8795
}
8896

97+
#[must_use]
98+
// https://github.com/vectordotdev/vector/issues/23659
99+
#[allow(
100+
clippy::default_trait_access,
101+
reason = "Preserve inferred default types"
102+
)]
89103
pub fn as_source(&self, default_key: &ComponentKey) -> Option<(ComponentKey, SourceOuter)> {
90104
self.inner.source_config(default_key).map(|(key, source)| {
91105
(

0 commit comments

Comments
 (0)