Skip to content

Commit

Permalink
fix(telemetry): correct clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tknickman committed Dec 8, 2023
1 parent 4b338fc commit 65276e7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 1 addition & 3 deletions crates/turborepo-lib/src/commands/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn configure(command: &Option<Box<TelemetryCommand>>, base: &mut CommandBase
Ok(config) => config,
Err(e) => {
log_error("Failed to load telemetry config", &e.to_string(), base);
return ();
return;
}
};

Expand Down Expand Up @@ -68,6 +68,4 @@ pub fn configure(command: &Option<Box<TelemetryCommand>>, base: &mut CommandBase
log_status(config, base);
}
}

()
}
2 changes: 1 addition & 1 deletion crates/turborepo-telemetry/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl AnonAPIClient {

let request_builder = self
.client
.request(method, &url)
.request(method, url)
.header("User-Agent", self.user_agent.clone())
.header("Content-Type", "application/json")
.header("x-turbo-telemetry-id", telemetry_id)
Expand Down
20 changes: 10 additions & 10 deletions crates/turborepo-telemetry/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn write_new_config() -> Result<(), ConfigError> {

pub fn is_debug() -> bool {
let debug = env::var(DEBUG_ENV_VAR).unwrap_or("0".to_string());
return debug == "1" || debug == "true";
debug == "1" || debug == "true"
}

impl TelemetryConfig {
Expand All @@ -74,15 +74,16 @@ impl TelemetryConfig {

let settings = settings.build();

// Check if this is a FileParse error, remove the config file and write a new
// one, otherwise return the error
// If this is a FileParse error, we assume something corrupted the file or
// structure. In this case, try to remove the config file and write a
// new one, otherwise return the error
if let Err(ConfigError::FileParse { .. }) = settings {
fs::remove_file(file_path).map_err(|e| ConfigError::Message(e.to_string()))?;
write_new_config()?;
return Err(settings.unwrap_err());
} else if settings.is_err() {
} else if let Err(err) = settings {
// Propagate other errors
return Err(settings.unwrap_err());
return Err(err);
}

// this is safe because we just checked the error case above
Expand All @@ -107,7 +108,7 @@ impl TelemetryConfig {
Ok(())
}

pub fn show_alert(&mut self) -> () {
pub fn show_alert(&mut self) {
if !self.has_seen_alert() && self.is_enabled() {
println!(
"\n{}\n{}\n{}\n{}\n{}\n",
Expand Down Expand Up @@ -137,7 +138,6 @@ impl TelemetryConfig {
),
}
}
()
}

// getters
Expand Down Expand Up @@ -168,13 +168,13 @@ impl TelemetryConfig {
pub fn enable(&mut self) -> Result<&TelemetryConfigContents, ConfigError> {
self.config.telemetry_enabled = true;
self.write()?;
return Ok(&self.config);
Ok(&self.config)
}

pub fn disable(&mut self) -> Result<&TelemetryConfigContents, ConfigError> {
self.config.telemetry_enabled = false;
self.write()?;
return Ok(&self.config);
Ok(&self.config)
}

pub fn alert_shown(&mut self) -> Result<&TelemetryConfigContents, ConfigError> {
Expand All @@ -183,7 +183,7 @@ impl TelemetryConfig {
false => {
self.config.telemetry_alerted = Some(Utc::now());
self.write()?;
return Ok(&self.config);
Ok(&self.config)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/turborepo-telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct TelemetryHandle {
static SENDER_INSTANCE: OnceCell<TelemetrySender> = OnceCell::new();

// A global instance of the TelemetrySender.
pub fn telem(event: events::TelemetryEvent) -> () {
pub fn telem(event: events::TelemetryEvent) {
let sender = SENDER_INSTANCE.get();
match sender {
Some(s) => {
Expand Down Expand Up @@ -218,7 +218,6 @@ impl<C: telemetry::TelemetryClient + Clone + Send + Sync + 'static> Worker<C> {
for event in &events {
let pretty_event = serde_json::to_string_pretty(&event)
.unwrap_or("Error serializing event".to_string());
println!("");
println!(
"\n{}\n{}\n",
self.ui.apply(BOLD.apply_to("[telemetry event]")),
Expand Down

0 comments on commit 65276e7

Please sign in to comment.