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

chore: Fix clippy errors and remove old feature directives #5497

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/turborepo-cache/src/cache_archive/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
fn create_entry(anchor: &AbsoluteSystemPath, file: &CreateFileDefinition) -> Result<()> {
match &file.file_type {
FileType::Dir => create_dir(anchor, file),
FileType::Symlink { linkname } => create_symlink(anchor, file, &linkname),
FileType::Symlink { linkname } => create_symlink(anchor, file, linkname),
FileType::Fifo => create_fifo(anchor, file),
FileType::File => create_file(anchor, file),
}
Expand All @@ -185,7 +185,7 @@ mod tests {
linkname: &str,
) -> Result<()> {
let path = anchor.resolve(&file.path);
path.symlink_to_file(&linkname)?;
path.symlink_to_file(linkname)?;

Ok(())
}
Expand Down Expand Up @@ -407,7 +407,7 @@ mod tests {
fn test_compression() -> Result<()> {
let mut buffer = Vec::new();
let mut encoder = zstd::Encoder::new(&mut buffer, 0)?.auto_finish();
encoder.write(b"hello world")?;
encoder.write_all(b"hello world")?;
// Should finish encoding on drop
drop(encoder);

Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-cache/src/cache_archive/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ mod tests {
for (tar_bytes, is_compressed) in
[(&uncompressed_tar[..], false), (&compressed_tar[..], true)]
{
let mut cache_reader = CacheReader::new(&tar_bytes[..], is_compressed)?;
let mut cache_reader = CacheReader::new(tar_bytes, is_compressed)?;
let output_dir = tempdir()?;
let output_dir_path = output_dir.path().to_string_lossy();
let anchor = AbsoluteSystemPath::new(&output_dir_path)?;
Expand All @@ -365,7 +365,7 @@ mod tests {
for (tar_bytes, is_compressed) in
[(&uncompressed_tar[..], false), (&compressed_tar[..], true)]
{
let mut cache_reader = CacheReader::new(&tar_bytes[..], is_compressed)?;
let mut cache_reader = CacheReader::new(tar_bytes, is_compressed)?;
let output_dir = tempdir()?;
let output_dir_path = output_dir.path().to_string_lossy();
let anchor = AbsoluteSystemPath::new(&output_dir_path)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-cache/src/signature_authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl ArtifactSignatureAuthenticator {
let mut mac = HmacSha256::new_from_slice(&self.secret_key()?)?;
let message = self.construct_metadata(hash)?;
mac.update(&message);
mac.update(&artifact_body);
mac.update(artifact_body);

let expected_bytes = BASE64_STANDARD.decode(expected_tag)?;
Ok(mac.verify_slice(&expected_bytes).is_ok())
Expand All @@ -124,7 +124,7 @@ mod tests {
let mut mac = HmacSha256::new_from_slice(&self.secret_key()?)?;
let message = self.construct_metadata(hash)?;
mac.update(&message);
mac.update(&artifact_body);
mac.update(artifact_body);

Ok(mac.verify_slice(expected_tag).is_ok())
}
Expand Down
26 changes: 11 additions & 15 deletions crates/turborepo-globwalk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(assert_matches)]
#![feature(once_cell)]

mod empty_glob;

Expand Down Expand Up @@ -324,7 +323,7 @@ fn collapse_path(path: &str) -> Option<(Cow<str>, usize)> {
Some((Cow::Borrowed(path), lowest_index))
} else {
let string = if is_root {
std::iter::once("").chain(stack.into_iter()).join("/")
std::iter::once("").chain(stack).join("/")
} else {
stack.join("/")
};
Expand Down Expand Up @@ -502,7 +501,7 @@ mod test {
let expected = format!(
"{}{}",
ROOT,
base_path_exp.replace("/", std::path::MAIN_SEPARATOR_STR)
base_path_exp.replace('/', std::path::MAIN_SEPARATOR_STR)
);
assert_eq!(result_path.to_string_lossy(), expected);

Expand Down Expand Up @@ -1316,7 +1315,7 @@ mod test {
.iter()
.map(|p| {
p.trim_start_matches('/')
.replace("/", std::path::MAIN_SEPARATOR_STR)
.replace('/', std::path::MAIN_SEPARATOR_STR)
})
.sorted()
.collect::<Vec<_>>();
Expand Down Expand Up @@ -1427,17 +1426,14 @@ mod test {
relative.to_string()
})
.collect::<HashSet<_>>();
let expected: HashSet<String> = HashSet::from_iter(
[
"docs/package.json"
.replace("/", std::path::MAIN_SEPARATOR_STR)
.to_string(),
"apps/some-app/package.json"
.replace("/", std::path::MAIN_SEPARATOR_STR)
.to_string(),
]
.into_iter(),
);
let expected: HashSet<String> = HashSet::from_iter([
"docs/package.json"
.replace('/', std::path::MAIN_SEPARATOR_STR)
.to_string(),
"apps/some-app/package.json"
.replace('/', std::path::MAIN_SEPARATOR_STR)
.to_string(),
]);
assert_eq!(paths, expected);
}
}
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ pub async fn run(

Ok(Payload::Rust(Ok(0)))
}
#[allow(unused_variables)]
Command::Daemon { command, idle_time } => {
let base = CommandBase::new(cli_args.clone(), repo_root, version, ui)?;

Expand Down
3 changes: 1 addition & 2 deletions crates/turborepo-lib/src/config/turbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ impl TryFrom<RawTurboJSON> for TurboJson {
pipeline: raw_turbo
.pipeline
.into_iter()
.map(|p| p.0)
.flatten()
.flat_map(|p| p.0)
.map(|(task_name, task_definition)| Ok((task_name, task_definition.try_into()?)))
.collect::<Result<HashMap<_, _>, Error>>()?,
// copy these over, we don't need any changes here.
Expand Down
22 changes: 5 additions & 17 deletions crates/turborepo-lib/src/globwatcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,7 @@ mod test {
println!("{:?} {:?}", include, exclude);

watcher
.watch_globs(
hash.clone(),
include.clone().into_iter(),
exclude.clone().into_iter(),
)
.watch_globs(hash.clone(), include.clone(), exclude.clone())
.await
.unwrap();

Expand Down Expand Up @@ -532,19 +528,15 @@ mod test {
let globs2_exclusion = ["my-pkg/.next/cache/**".to_string()];

watcher
.watch_globs(
hash1.clone(),
globs1_inclusion.clone().into_iter(),
vec![].into_iter(),
)
.watch_globs(hash1.clone(), globs1_inclusion.clone(), vec![])
.await
.unwrap();

watcher
.watch_globs(
hash2.clone(),
globs2_inclusion.clone().into_iter(),
globs2_exclusion.clone().into_iter(),
globs2_inclusion.clone(),
globs2_exclusion.clone(),
)
.await
.unwrap();
Expand Down Expand Up @@ -650,11 +642,7 @@ mod test {
let inclusions = ["my-pkg/.next/next-file".to_string()];

watcher
.watch_globs(
hash.clone(),
inclusions.clone().into_iter(),
vec![].into_iter(),
)
.watch_globs(hash.clone(), inclusions.clone(), vec![])
.await
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/package_graph/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl Dependencies {
.map_or(false, |workspace_version| {
DependencyVersion::new(version).matches_workspace_package(
workspace_version,
&workspace_dir,
workspace_dir,
repo_root,
)
});
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/package_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ mod test {
{
match key {
"key:a" => Ok(Some(
vec![("c", "1")]
[("c", "1")]
.iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect(),
)),
"key:b" => Ok(Some(
vec![("c", "1")]
[("c", "1")]
.iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect(),
Expand Down
40 changes: 17 additions & 23 deletions crates/turborepo-lib/src/package_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,40 +461,34 @@ mod tests {
let examples = root.join_component("examples");

let with_yarn = examples.join_component("with-yarn");
let with_yarn_expected: HashSet<AbsoluteSystemPathBuf> = HashSet::from_iter(
[
with_yarn.join_components(&["apps", "docs", "package.json"]),
with_yarn.join_components(&["apps", "web", "package.json"]),
with_yarn.join_components(&["packages", "eslint-config-custom", "package.json"]),
with_yarn.join_components(&["packages", "tsconfig", "package.json"]),
with_yarn.join_components(&["packages", "ui", "package.json"]),
]
.into_iter(),
);
let with_yarn_expected: HashSet<AbsoluteSystemPathBuf> = HashSet::from_iter([
with_yarn.join_components(&["apps", "docs", "package.json"]),
with_yarn.join_components(&["apps", "web", "package.json"]),
with_yarn.join_components(&["packages", "eslint-config-custom", "package.json"]),
with_yarn.join_components(&["packages", "tsconfig", "package.json"]),
with_yarn.join_components(&["packages", "ui", "package.json"]),
]);
for mgr in &[
PackageManager::Berry,
PackageManager::Yarn,
PackageManager::Npm,
] {
let found = mgr.get_package_jsons(&with_yarn).unwrap();
let found: HashSet<AbsoluteSystemPathBuf> = HashSet::from_iter(found.into_iter());
let found: HashSet<AbsoluteSystemPathBuf> = HashSet::from_iter(found);
assert_eq!(found, with_yarn_expected);
}

let basic = examples.join_component("basic");
let basic_expected: HashSet<AbsoluteSystemPathBuf> = HashSet::from_iter(
[
basic.join_components(&["apps", "docs", "package.json"]),
basic.join_components(&["apps", "web", "package.json"]),
basic.join_components(&["packages", "eslint-config-custom", "package.json"]),
basic.join_components(&["packages", "tsconfig", "package.json"]),
basic.join_components(&["packages", "ui", "package.json"]),
]
.into_iter(),
);
let basic_expected: HashSet<AbsoluteSystemPathBuf> = HashSet::from_iter([
basic.join_components(&["apps", "docs", "package.json"]),
basic.join_components(&["apps", "web", "package.json"]),
basic.join_components(&["packages", "eslint-config-custom", "package.json"]),
basic.join_components(&["packages", "tsconfig", "package.json"]),
basic.join_components(&["packages", "ui", "package.json"]),
]);
for mgr in &[PackageManager::Pnpm, PackageManager::Pnpm6] {
let found = mgr.get_package_jsons(&basic).unwrap();
let found: HashSet<AbsoluteSystemPathBuf> = HashSet::from_iter(found.into_iter());
let found: HashSet<AbsoluteSystemPathBuf> = HashSet::from_iter(found);
assert_eq!(found, basic_expected);
}
}
Expand All @@ -517,7 +511,7 @@ mod tests {
PackageManager::Pnpm6,
] {
let globs = mgr.get_workspace_globs(&fixtures).unwrap();
let ignores: HashSet<String> = HashSet::from_iter(globs.raw_exclusions.into_iter());
let ignores: HashSet<String> = HashSet::from_iter(globs.raw_exclusions);
let expected: &[&str] = match mgr {
PackageManager::Npm => &["**/node_modules/**"],
PackageManager::Berry => &["**/node_modules", "**/.git", "**/.yarn"],
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/scope/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl PackageInference {
);
let full_inference_path = turbo_root.resolve(pkg_inference_path);
for (workspace_name, workspace_entry) in pkg_graph.workspaces() {
let pkg_path = turbo_root.resolve(&workspace_entry.package_json_path());
let pkg_path = turbo_root.resolve(workspace_entry.package_json_path());
let inferred_path_is_below = pkg_path.contains(&full_inference_path);
// We skip over the root package as the inferred path will always be below it
if inferred_path_is_below && (&pkg_path as &AbsoluteSystemPath) != turbo_root {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/scope/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn resolve_packages(
_scm: &SCM,
) -> Result<HashSet<String>> {
let _pkg_inference = opts.pkg_inference_root.as_ref().map(|pkg_inference_path| {
PackageInference::calculate(&base.repo_root, &pkg_inference_path, pkg_graph)
PackageInference::calculate(&base.repo_root, pkg_inference_path, pkg_graph)
});
warn!("resolve packages not implemented yet");
Ok(HashSet::new())
Expand Down
2 changes: 0 additions & 2 deletions crates/turborepo-lockfiles/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(once_cell)]

mod berry;
mod error;
mod npm;
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lockfiles/src/yarn1/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn multikey_property_statement(
Ok((
i,
std::iter::once(property)
.chain(others.into_iter())
.chain(others)
.map(|key| (key, value.clone()))
.collect(),
))
Expand Down
10 changes: 5 additions & 5 deletions crates/turborepo-scm/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Git {

let output = self.execute_git_command(&["diff", "--name-only", to_commit], pathspec)?;

self.add_files_from_stdout(&mut files, &turbo_root, output);
self.add_files_from_stdout(&mut files, turbo_root, output);

if let Some(from_commit) = from_commit {
let output = self.execute_git_command(
Expand All @@ -91,13 +91,13 @@ impl Git {
pathspec,
)?;

self.add_files_from_stdout(&mut files, &turbo_root, output);
self.add_files_from_stdout(&mut files, turbo_root, output);
}

let output =
self.execute_git_command(&["ls-files", "--others", "--exclude-standard"], pathspec)?;

self.add_files_from_stdout(&mut files, &turbo_root, output);
self.add_files_from_stdout(&mut files, turbo_root, output);

Ok(files)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Git {
turbo_root: &AbsoluteSystemPath,
stdout: Vec<u8>,
) {
let turbo_root = turbo_root.as_ref();
let turbo_root = turbo_root;
let stdout = String::from_utf8(stdout).unwrap();
for line in stdout.lines() {
let path = RelativeUnixPath::new(line).unwrap();
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn previous_content(
// Note that we assume any relative file path is relative to the git root
// FIXME: this is probably wrong. We should know the path to the lockfile
// exactly
let absolute_file_path = AbsoluteSystemPathBuf::from_unknown(&git_root, &file_path);
let absolute_file_path = AbsoluteSystemPathBuf::from_unknown(&git_root, file_path);

scm.previous_content(from_commit, &absolute_file_path)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/turborepo-scm/src/hash_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mod test {
let git_to_pkg_path = git_root.anchor(pkg_path).unwrap();
let pkg_prefix = git_to_pkg_path.to_unix().unwrap();

let expected_hashes = GitHashes::from_iter(file_hashes.into_iter());
let expected_hashes = GitHashes::from_iter(file_hashes);
let mut hashes = GitHashes::new();
let to_hash = expected_hashes.keys().map(|k| pkg_prefix.join(k)).collect();
hash_objects(&git_root, pkg_path, to_hash, &mut hashes).unwrap();
Expand All @@ -110,8 +110,8 @@ mod test {
.collect();

let mut hashes = GitHashes::new();
let result = hash_objects(&git_root, &pkg_path, to_hash, &mut hashes);
assert_eq!(result.is_err(), true);
let result = hash_objects(&git_root, pkg_path, to_hash, &mut hashes);
assert!(result.is_err());
}
}
}
2 changes: 1 addition & 1 deletion crates/turborepo-scm/src/ls_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod tests {
fn to_hash_map(pairs: &[(&str, &str)]) -> GitHashes {
HashMap::from_iter(
pairs
.into_iter()
.iter()
.map(|(path, hash)| (RelativeUnixPathBuf::new(*path).unwrap(), hash.to_string())),
)
}
Expand Down
Loading