Skip to content

Commit

Permalink
Fixed a bunch of clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Feb 6, 2025
1 parent 59cf259 commit 35e8887
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 161 deletions.
50 changes: 13 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/turbo-trace/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Tracer {
errors.push(TraceError::Resolve {
import: import.to_string(),
file_path: file_path.to_string(),
span: SourceSpan::new(start.into(), (end - start).into()),
span: SourceSpan::new(start.into(), end - start),
text: file_content.clone(),
reason: err.to_string(),
});
Expand Down
20 changes: 8 additions & 12 deletions crates/turborepo-cache/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl FromStr for CacheConfig {
.ok_or(Error::InvalidCacheTypeAndAction {
text: s.to_string(),
pair: action.to_string(),
span: Some(SourceSpan::new(idx.into(), action.len().into())),
span: Some(SourceSpan::new(idx.into(), action.len())),
})?;

match key {
Expand All @@ -114,40 +114,36 @@ impl FromStr for CacheConfig {
return Err(Error::DuplicateKeys {
text: s.to_string(),
key: "local",
span: Some(SourceSpan::new(idx.into(), key.len().into())),
span: Some(SourceSpan::new(idx.into(), key.len())),
});
}

seen_local = true;
cache.local = CacheActions::from_str(value).map_err(|err| {
err.add_text(s).add_span(SourceSpan::new(
(idx + key.len() + 1).into(),
key.len().into(),
))
err.add_text(s)
.add_span(SourceSpan::new((idx + key.len() + 1).into(), key.len()))
})?;
}
"remote" => {
if seen_remote {
return Err(Error::DuplicateKeys {
text: s.to_string(),
key: "remote",
span: Some(SourceSpan::new(idx.into(), key.len().into())),
span: Some(SourceSpan::new(idx.into(), key.len())),
});
}

seen_remote = true;
cache.remote = CacheActions::from_str(value).map_err(|err| {
err.add_text(s).add_span(SourceSpan::new(
(idx + key.len() + 1).into(),
value.len().into(),
))
err.add_text(s)
.add_span(SourceSpan::new((idx + key.len() + 1).into(), value.len()))
})?
}
ty => {
return Err(Error::InvalidCacheType {
text: s.to_string(),
s: ty.to_string(),
span: Some(SourceSpan::new(idx.into(), ty.len().into())),
span: Some(SourceSpan::new(idx.into(), ty.len())),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/boundaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Run {
let (start, end) = source_map.span_to_char_offset(&source_file, *span);
let start = start as usize;
let end = end as usize;
let span = SourceSpan::new(start.into(), (end - start).into());
let span = SourceSpan::new(start.into(), end - start);

// We have a file import
let check_result = if import.starts_with(".") {
Expand Down
31 changes: 18 additions & 13 deletions crates/turborepo-lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ pub struct InvalidEnvPrefixError {
pub env_pipeline_delimiter: &'static str,
}

#[derive(Debug, Error, Diagnostic)]
#[diagnostic(
code(unnecessary_package_task_syntax),
url("{}/messages/{}", TURBO_SITE, self.code().unwrap().to_string().to_case(Case::Kebab))
)]
#[error("\"{actual}\". Use \"{wanted}\" instead.")]
pub struct UnnecessaryPackageTaskSyntaxError {
pub actual: String,
pub wanted: String,
#[label("unnecessary package syntax found here")]
pub span: Option<SourceSpan>,
#[source_code]
pub text: NamedSource<String>,
}

#[allow(clippy::enum_variant_names)]
#[derive(Debug, Error, Diagnostic)]
pub enum Error {
Expand Down Expand Up @@ -107,19 +122,9 @@ pub enum Error {
InvalidEnvPrefix(Box<InvalidEnvPrefixError>),
#[error(transparent)]
PathError(#[from] turbopath::PathError),
#[diagnostic(
code(unnecessary_package_task_syntax),
url("{}/messages/{}", TURBO_SITE, self.code().unwrap().to_string().to_case(Case::Kebab))
)]
#[error("\"{actual}\". Use \"{wanted}\" instead.")]
UnnecessaryPackageTaskSyntax {
actual: String,
wanted: String,
#[label("unnecessary package syntax found here")]
span: Option<SourceSpan>,
#[source_code]
text: NamedSource<String>,
},
#[error(transparent)]
#[diagnostic(transparent)]
UnnecessaryPackageTaskSyntax(Box<UnnecessaryPackageTaskSyntaxError>),
#[error("You can only extend from the root of the workspace.")]
ExtendFromNonRoot {
#[label("non-root workspace found here")]
Expand Down
Loading

0 comments on commit 35e8887

Please sign in to comment.