chore(core): format rust code (#30954)
## Current Behavior Rust formatting isn't checked in CI ## Expected Behavior Rust formatting is checked in CI ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
d9cb931116
commit
981dd94671
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -94,7 +94,7 @@ jobs:
|
||||
pnpm nx run-many -t check-imports check-commit check-lock-files check-codeowners --parallel=1 --no-dte &
|
||||
pids+=($!)
|
||||
|
||||
pnpm nx affected --targets=lint,test,build,e2e,e2e-ci &
|
||||
pnpm nx affected --targets=lint,test,build,e2e,e2e-ci,format-native &
|
||||
pids+=($!)
|
||||
|
||||
for pid in "${pids[@]}"; do
|
||||
|
||||
@ -2,3 +2,4 @@ pnpm check-lock-files
|
||||
pnpm check-commit
|
||||
pnpm documentation
|
||||
pnpm pretty-quick --check
|
||||
pnpm nx format-native nx
|
||||
@ -139,6 +139,19 @@
|
||||
"parallel": false
|
||||
}
|
||||
},
|
||||
"test-native": {}
|
||||
"test-native": {},
|
||||
"format-native": {
|
||||
"command": "cargo fmt",
|
||||
"cache": true,
|
||||
"options": {
|
||||
"cwd": "{projectRoot}/src/native",
|
||||
"args": ["--all", "--check"]
|
||||
},
|
||||
"configurations": {
|
||||
"fix": {
|
||||
"args": ["--all"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
use super::contains_glob_pattern;
|
||||
use crate::native::glob::glob_group::GlobGroup;
|
||||
use crate::native::glob::glob_parser::parse_glob;
|
||||
use itertools::Either::{Left, Right};
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashSet;
|
||||
use itertools::Either::{Left, Right};
|
||||
use super::contains_glob_pattern;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum GlobType {
|
||||
@ -120,15 +120,13 @@ pub fn partition_glob(glob: &str) -> anyhow::Result<(String, Vec<String>)> {
|
||||
let (leading_dir_segments, pattern_segments): (Vec<String>, _) = groups
|
||||
.into_iter()
|
||||
.filter(|group| !group.is_empty())
|
||||
.partition_map(|group| {
|
||||
match &group[0] {
|
||||
GlobGroup::NonSpecial(value) if !contains_glob_pattern(&value) && !has_patterns => {
|
||||
Left(value.to_string())
|
||||
}
|
||||
_ => {
|
||||
has_patterns = true;
|
||||
Right(group)
|
||||
}
|
||||
.partition_map(|group| match &group[0] {
|
||||
GlobGroup::NonSpecial(value) if !contains_glob_pattern(&value) && !has_patterns => {
|
||||
Left(value.to_string())
|
||||
}
|
||||
_ => {
|
||||
has_patterns = true;
|
||||
Right(group)
|
||||
}
|
||||
});
|
||||
|
||||
@ -267,7 +265,8 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn should_partition_glob_with_leading_dirs() {
|
||||
let (leading_dirs, globs) = super::partition_glob("dist/app/**/!(README|LICENSE).(js|ts)").unwrap();
|
||||
let (leading_dirs, globs) =
|
||||
super::partition_glob("dist/app/**/!(README|LICENSE).(js|ts)").unwrap();
|
||||
assert_eq!(leading_dirs, "dist/app");
|
||||
assert_eq!(globs, ["!**/{README,LICENSE}.{js,ts}", "**/*.{js,ts}",]);
|
||||
}
|
||||
|
||||
@ -9,12 +9,16 @@ pub fn hash(content: &[u8]) -> String {
|
||||
|
||||
#[napi]
|
||||
pub fn hash_array(input: Vec<Option<String>>) -> String {
|
||||
let joined = input.iter().filter_map(|s| {
|
||||
if s.is_none() {
|
||||
trace!("Encountered None value in hash_array input: {:?}", input);
|
||||
}
|
||||
s.as_deref()
|
||||
}).collect::<Vec<_>>().join(",");
|
||||
let joined = input
|
||||
.iter()
|
||||
.filter_map(|s| {
|
||||
if s.is_none() {
|
||||
trace!("Encountered None value in hash_array input: {:?}", input);
|
||||
}
|
||||
s.as_deref()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
let content = joined.as_bytes();
|
||||
hash(content)
|
||||
}
|
||||
@ -41,7 +45,7 @@ pub fn hash_file_path<P: AsRef<Path>>(path: P) -> Option<String> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::native::hasher::{hash_file, hash_array};
|
||||
use crate::native::hasher::{hash_array, hash_file};
|
||||
use assert_fs::prelude::*;
|
||||
use assert_fs::TempDir;
|
||||
|
||||
|
||||
@ -8,4 +8,3 @@ use crate::native::project_graph::types::ProjectGraph;
|
||||
pub fn transfer_project_graph(project_graph: ProjectGraph) -> External<ProjectGraph> {
|
||||
External::new(project_graph)
|
||||
}
|
||||
|
||||
|
||||
@ -32,14 +32,8 @@ impl RustPseudoTerminal {
|
||||
quiet: Option<bool>,
|
||||
tty: Option<bool>,
|
||||
) -> napi::Result<ChildProcess> {
|
||||
self.pseudo_terminal.run_command(
|
||||
command,
|
||||
command_dir,
|
||||
js_env,
|
||||
exec_argv,
|
||||
quiet,
|
||||
tty,
|
||||
)
|
||||
self.pseudo_terminal
|
||||
.run_command(command, command_dir, js_env, exec_argv, quiet, tty)
|
||||
}
|
||||
|
||||
/// This allows us to run a pseudoterminal with a fake node ipc channel
|
||||
|
||||
@ -33,14 +33,8 @@ impl RustPseudoTerminal {
|
||||
quiet: Option<bool>,
|
||||
tty: Option<bool>,
|
||||
) -> napi::Result<ChildProcess> {
|
||||
self.pseudo_terminal.run_command(
|
||||
command,
|
||||
command_dir,
|
||||
js_env,
|
||||
exec_argv,
|
||||
quiet,
|
||||
tty,
|
||||
)
|
||||
self.pseudo_terminal
|
||||
.run_command(command, command_dir, js_env, exec_argv, quiet, tty)
|
||||
}
|
||||
|
||||
/// This allows us to run a pseudoterminal with a fake node ipc channel
|
||||
|
||||
@ -117,7 +117,9 @@ impl PseudoTerminal {
|
||||
|
||||
let mut content = String::from_utf8_lossy(&buf[0..len]).to_string();
|
||||
if content.contains("\x1B[6n") {
|
||||
trace!("Prevented terminal escape sequence ESC[6n from being printed.");
|
||||
trace!(
|
||||
"Prevented terminal escape sequence ESC[6n from being printed."
|
||||
);
|
||||
content = content.replace("\x1B[6n", "");
|
||||
}
|
||||
|
||||
|
||||
@ -4,8 +4,8 @@ mod hash_project_config;
|
||||
mod hash_project_files;
|
||||
mod hash_runtime;
|
||||
mod hash_task_output;
|
||||
mod hash_workspace_files;
|
||||
mod hash_tsconfig;
|
||||
mod hash_workspace_files;
|
||||
|
||||
pub use hash_env::*;
|
||||
pub use hash_external::*;
|
||||
@ -13,5 +13,5 @@ pub use hash_project_config::*;
|
||||
pub use hash_project_files::*;
|
||||
pub use hash_runtime::*;
|
||||
pub use hash_task_output::*;
|
||||
pub use hash_workspace_files::*;
|
||||
pub use hash_tsconfig::*;
|
||||
pub use hash_workspace_files::*;
|
||||
|
||||
@ -158,12 +158,15 @@ mod tests {
|
||||
let hash_result = hash_project_files(proj_name, proj_root, file_sets, &file_map).unwrap();
|
||||
assert_eq!(
|
||||
hash_result,
|
||||
hash(&[
|
||||
file_data1.hash.as_bytes(),
|
||||
file_data1.file.as_bytes(),
|
||||
file_data3.hash.as_bytes(),
|
||||
file_data3.file.as_bytes()
|
||||
].concat())
|
||||
hash(
|
||||
&[
|
||||
file_data1.hash.as_bytes(),
|
||||
file_data1.file.as_bytes(),
|
||||
file_data3.hash.as_bytes(),
|
||||
file_data3.file.as_bytes()
|
||||
]
|
||||
.concat()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -205,12 +208,15 @@ mod tests {
|
||||
let hash_result = hash_project_files(proj_name, proj_root, file_sets, &file_map).unwrap();
|
||||
assert_eq!(
|
||||
hash_result,
|
||||
hash(&[
|
||||
file_data1.hash.as_bytes(),
|
||||
file_data1.file.as_bytes(),
|
||||
file_data3.hash.as_bytes(),
|
||||
file_data3.file.as_bytes(),
|
||||
].concat())
|
||||
hash(
|
||||
&[
|
||||
file_data1.hash.as_bytes(),
|
||||
file_data1.file.as_bytes(),
|
||||
file_data3.hash.as_bytes(),
|
||||
file_data3.file.as_bytes(),
|
||||
]
|
||||
.concat()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
use std::path::Path;
|
||||
use crate::native::cache::expand_outputs::get_files_for_outputs;
|
||||
use crate::native::glob::build_glob_set;
|
||||
use crate::native::hasher::{hash_array, hash_file};
|
||||
use anyhow::*;
|
||||
use rayon::prelude::*;
|
||||
use std::path::Path;
|
||||
use tracing::trace;
|
||||
|
||||
pub fn hash_task_output(workspace_root: &str, glob: &str, outputs: &[String]) -> Result<String> {
|
||||
@ -14,7 +14,15 @@ pub fn hash_task_output(workspace_root: &str, glob: &str, outputs: &[String]) ->
|
||||
let hashes = output_files
|
||||
.into_par_iter()
|
||||
.filter(|file| glob.is_match(file))
|
||||
.filter_map(|file| hash_file(Path::new(workspace_root).join(file).to_str().expect("path contains invalid utf-8").to_owned()))
|
||||
.filter_map(|file| {
|
||||
hash_file(
|
||||
Path::new(workspace_root)
|
||||
.join(file)
|
||||
.to_str()
|
||||
.expect("path contains invalid utf-8")
|
||||
.to_owned(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
Ok(hash_array(hashes.into_iter().map(Some).collect()))
|
||||
}
|
||||
|
||||
@ -9,6 +9,6 @@ mod utils;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod details;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod task_history;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod running_tasks_service;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod task_history;
|
||||
|
||||
@ -99,10 +99,12 @@ impl CountdownPopup {
|
||||
|
||||
pub fn render(&mut self, f: &mut Frame<'_>, area: Rect) {
|
||||
// Add a safety check to prevent rendering outside buffer bounds (this can happen if the user resizes the window a lot before it stabilizes it seems)
|
||||
if area.height == 0 || area.width == 0 ||
|
||||
area.x >= f.area().width ||
|
||||
area.y >= f.area().height {
|
||||
return; // Area is out of bounds, don't try to render
|
||||
if area.height == 0
|
||||
|| area.width == 0
|
||||
|| area.x >= f.area().width
|
||||
|| area.y >= f.area().height
|
||||
{
|
||||
return; // Area is out of bounds, don't try to render
|
||||
}
|
||||
|
||||
// Ensure area is entirely within frame bounds
|
||||
|
||||
@ -27,10 +27,12 @@ impl HelpText {
|
||||
|
||||
pub fn render(&self, f: &mut Frame<'_>, area: Rect) {
|
||||
// Add a safety check to prevent rendering outside buffer bounds (this can happen if the user resizes the window a lot before it stabilizes it seems)
|
||||
if area.height == 0 || area.width == 0 ||
|
||||
area.x >= f.area().width ||
|
||||
area.y >= f.area().height {
|
||||
return; // Area is out of bounds, don't try to render
|
||||
if area.height == 0
|
||||
|| area.width == 0
|
||||
|| area.x >= f.area().width
|
||||
|| area.y >= f.area().height
|
||||
{
|
||||
return; // Area is out of bounds, don't try to render
|
||||
}
|
||||
|
||||
// Ensure area is entirely within frame bounds
|
||||
|
||||
@ -252,11 +252,7 @@ impl LayoutManager {
|
||||
}
|
||||
|
||||
// Prevent divide-by-zero
|
||||
let task_list_height = if area.height < 3 {
|
||||
1
|
||||
} else {
|
||||
area.height / 3
|
||||
};
|
||||
let task_list_height = if area.height < 3 { 1 } else { area.height / 3 };
|
||||
|
||||
// Apply padding only if there's enough space
|
||||
let padding_height = if area.height > task_list_height + self.vertical_padding {
|
||||
@ -311,11 +307,7 @@ impl LayoutManager {
|
||||
}
|
||||
|
||||
// Prevent divide-by-zero
|
||||
let task_list_width = if area.width < 3 {
|
||||
1
|
||||
} else {
|
||||
area.width / 3
|
||||
};
|
||||
let task_list_width = if area.width < 3 { 1 } else { area.width / 3 };
|
||||
|
||||
// Apply padding only if there's enough space
|
||||
let padding_width = if area.width > task_list_width + self.horizontal_padding {
|
||||
@ -440,7 +432,10 @@ mod tests {
|
||||
fn test_default_properties() {
|
||||
let layout_manager = LayoutManager::new(5);
|
||||
assert_eq!(layout_manager.get_pane_arrangement(), PaneArrangement::None);
|
||||
assert_eq!(layout_manager.get_task_list_visibility(), TaskListVisibility::Visible);
|
||||
assert_eq!(
|
||||
layout_manager.get_task_list_visibility(),
|
||||
TaskListVisibility::Visible
|
||||
);
|
||||
assert_eq!(layout_manager.get_task_count(), 5);
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ use parking_lot::{Condvar, Mutex, MutexGuard};
|
||||
|
||||
pub struct NxMutex<T>(Mutex<T>);
|
||||
|
||||
impl <T> NxMutex<T> {
|
||||
impl<T> NxMutex<T> {
|
||||
pub fn new(value: T) -> Self {
|
||||
Self(Mutex::new(value))
|
||||
}
|
||||
@ -18,9 +18,13 @@ impl NxCondvar {
|
||||
Self(Condvar::new())
|
||||
}
|
||||
|
||||
pub fn wait<'a, T, F>(&'a self, mut guard: MutexGuard<'a, T>, condition: F) -> anyhow::Result<MutexGuard<'a, T>>
|
||||
where
|
||||
F: Fn(&MutexGuard<'a, T>) -> bool
|
||||
pub fn wait<'a, T, F>(
|
||||
&'a self,
|
||||
mut guard: MutexGuard<'a, T>,
|
||||
condition: F,
|
||||
) -> anyhow::Result<MutexGuard<'a, T>>
|
||||
where
|
||||
F: Fn(&MutexGuard<'a, T>) -> bool,
|
||||
{
|
||||
if condition(&guard) {
|
||||
self.0.wait(&mut guard);
|
||||
|
||||
@ -2,7 +2,7 @@ use std::sync::{Condvar, LockResult, Mutex, MutexGuard};
|
||||
|
||||
pub struct NxMutex<T>(Mutex<T>);
|
||||
|
||||
impl <T> NxMutex<T> {
|
||||
impl<T> NxMutex<T> {
|
||||
pub fn new(value: T) -> Self {
|
||||
Self(Mutex::new(value))
|
||||
}
|
||||
@ -18,9 +18,13 @@ impl NxCondvar {
|
||||
Self(Condvar::new())
|
||||
}
|
||||
|
||||
pub fn wait<'a, T, F>(&self, mutex_guard: MutexGuard<'a, T>, condition: F) -> LockResult<MutexGuard<'a, T>>
|
||||
pub fn wait<'a, T, F>(
|
||||
&self,
|
||||
mutex_guard: MutexGuard<'a, T>,
|
||||
condition: F,
|
||||
) -> LockResult<MutexGuard<'a, T>>
|
||||
where
|
||||
F: Fn(&mut T) -> bool
|
||||
F: Fn(&mut T) -> bool,
|
||||
{
|
||||
self.0.wait_while(mutex_guard, condition)
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::native::{utils::normalize_trait::Normalize, types::FileData};
|
||||
use crate::native::{types::FileData, utils::normalize_trait::Normalize};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
impl Normalize for Path {
|
||||
@ -65,13 +65,9 @@ mod test {
|
||||
FileData {
|
||||
file: "foo-other/not-child".into(),
|
||||
hash: "123".into(),
|
||||
}
|
||||
},
|
||||
];
|
||||
let child_files = get_child_files(&directory, files);
|
||||
assert_eq!(child_files, [
|
||||
"foo/bar",
|
||||
"foo/baz",
|
||||
"foo/child/bar",
|
||||
]);
|
||||
assert_eq!(child_files, ["foo/bar", "foo/baz", "foo/child/bar",]);
|
||||
}
|
||||
}
|
||||
@ -50,14 +50,13 @@ where
|
||||
!ignore_glob_set.is_match(path.as_ref())
|
||||
})
|
||||
.filter_map(move |entry| {
|
||||
entry
|
||||
.ok()
|
||||
.and_then(|e|
|
||||
e.path()
|
||||
.strip_prefix(&base_dir).ok()
|
||||
entry.ok().and_then(|e| {
|
||||
e.path()
|
||||
.strip_prefix(&base_dir)
|
||||
.ok()
|
||||
.filter(|p| !p.to_string_lossy().is_empty())
|
||||
.map(|p| p.to_owned())
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,11 @@ fn hash_files(files: Vec<NxFile>) -> Vec<(String, NxFileHashed)> {
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
trace!("hashing workspace files in {} chunks of {}", num_parallelism, chunks);
|
||||
trace!(
|
||||
"hashing workspace files in {} chunks of {}",
|
||||
num_parallelism,
|
||||
chunks
|
||||
);
|
||||
files
|
||||
.par_chunks(chunks)
|
||||
.flat_map_iter(|chunks| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user