Skip to content

Commit 995a380

Browse files
committed
fix: fix lint and format
1 parent 8646ccd commit 995a380

File tree

8 files changed

+80
-61
lines changed

8 files changed

+80
-61
lines changed

crates/cli/src/commands/init.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ const JS_APPLY_SCRIPT_FOR_RUST: &str =
100100
const JS_APPLY_SCRIPT_FOR_GO: &str = include_str!("../templates/js-astgrep/scripts/codemod.go.ts");
101101
const JS_APPLY_SCRIPT_FOR_JAVA: &str =
102102
include_str!("../templates/js-astgrep/scripts/codemod.java.ts");
103-
const JS_APPLY_SCRIPT_FOR_TSX: &str = include_str!("../templates/js-astgrep/scripts/codemod.tsx.ts");
104-
const JS_APPLY_SCRIPT_FOR_CSS: &str = include_str!("../templates/js-astgrep/scripts/codemod.css.ts");
105-
const JS_APPLY_SCRIPT_FOR_HTML: &str = include_str!("../templates/js-astgrep/scripts/codemod.html.ts");
106-
const JS_APPLY_SCRIPT_FOR_KOTLIN: &str = include_str!("../templates/js-astgrep/scripts/codemod.kt.ts");
103+
const JS_APPLY_SCRIPT_FOR_TSX: &str =
104+
include_str!("../templates/js-astgrep/scripts/codemod.tsx.ts");
105+
const JS_APPLY_SCRIPT_FOR_CSS: &str =
106+
include_str!("../templates/js-astgrep/scripts/codemod.css.ts");
107+
const JS_APPLY_SCRIPT_FOR_HTML: &str =
108+
include_str!("../templates/js-astgrep/scripts/codemod.html.ts");
109+
const JS_APPLY_SCRIPT_FOR_KOTLIN: &str =
110+
include_str!("../templates/js-astgrep/scripts/codemod.kt.ts");
107111

108112
const JS_TSCONFIG_TEMPLATE: &str = include_str!("../templates/js-astgrep/tsconfig.json");
109113
const JS_TEST_INPUT: &str = include_str!("../templates/js-astgrep/tests/fixtures/input.js");
@@ -118,10 +122,14 @@ const ASTGREP_PATTERNS_FOR_RUST: &str =
118122
const ASTGREP_PATTERNS_FOR_GO: &str = include_str!("../templates/astgrep-yaml/rules/config.go.yml");
119123
const ASTGREP_PATTERNS_FOR_JAVA: &str =
120124
include_str!("../templates/astgrep-yaml/rules/config.java.yml");
121-
const ASTGREP_PATTERNS_FOR_CSS: &str = include_str!("../templates/astgrep-yaml/rules/config.css.yml");
122-
const ASTGREP_PATTERNS_FOR_HTML: &str = include_str!("../templates/astgrep-yaml/rules/config.html.yml");
123-
const ASTGREP_PATTERNS_FOR_KOTLIN: &str = include_str!("../templates/astgrep-yaml/rules/config.kt.yml");
124-
const ASTGREP_PATTERNS_FOR_TSX: &str = include_str!("../templates/astgrep-yaml/rules/config.tsx.yml");
125+
const ASTGREP_PATTERNS_FOR_CSS: &str =
126+
include_str!("../templates/astgrep-yaml/rules/config.css.yml");
127+
const ASTGREP_PATTERNS_FOR_HTML: &str =
128+
include_str!("../templates/astgrep-yaml/rules/config.html.yml");
129+
const ASTGREP_PATTERNS_FOR_KOTLIN: &str =
130+
include_str!("../templates/astgrep-yaml/rules/config.kt.yml");
131+
const ASTGREP_PATTERNS_FOR_TSX: &str =
132+
include_str!("../templates/astgrep-yaml/rules/config.tsx.yml");
125133

126134
static ROCKET: Emoji<'_, '_> = Emoji("🚀 ", "");
127135
static CHECKMARK: Emoji<'_, '_> = Emoji("✓ ", "");

crates/codemod-sandbox/src/ast_grep/native.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,16 @@ async fn execute_ast_grep_on_globs_with_options(
138138
} else {
139139
let mut languages = Vec::new();
140140
for content in config_content.split("---") {
141-
let parsed = serde_yaml::Deserializer::from_str(&content).into_iter();
141+
let parsed = serde_yaml::Deserializer::from_str(content);
142142
let rule = Rule::deserialize(parsed)
143143
.map_err(|e| AstGrepError::Config(format!("Failed to parse rule: {e:?}")))?;
144144

145145
languages.push(SupportedLanguage::from_str(&rule.language).unwrap());
146146
}
147147

148-
load_tree_sitter(&languages)
149-
.await
150-
.map_err(|e| {
151-
AstGrepError::Config(format!("Failed to load tree-sitter language: {e:?}"))
152-
})?;
148+
load_tree_sitter(&languages).await.map_err(|e| {
149+
AstGrepError::Config(format!("Failed to load tree-sitter language: {e:?}"))
150+
})?;
153151

154152
from_yaml_string::<DynamicLang>(&config_content, &Default::default())
155153
.map_err(|e| AstGrepError::Config(format!("Failed to parse YAML rules: {e:?}")))?
@@ -322,7 +320,7 @@ async fn scan_file(
322320
let content = fs::read_to_string(file_path)?;
323321
let language = detect_language(file_path).map_err(|e| AstGrepError::Language(e.to_string()))?;
324322

325-
println!("language at SCAN FILE FYNC: {:?}", language);
323+
println!("language at SCAN FILE FYNC: {language:?}");
326324

327325
scan_content(
328326
&content,
@@ -343,10 +341,16 @@ async fn scan_content(
343341
_rule_configs: &[RuleConfig<DynamicLang>],
344342
apply_fixes: bool,
345343
) -> Result<Vec<AstGrepMatch>, AstGrepError> {
346-
println!("language at SCAN CONTENT: {:?}", language);
344+
println!("language at SCAN CONTENT: {language:?}");
347345
println!("extensions");
348346

349-
println!("DynamicLang::all_langs() language.to_string(): {:?}", DynamicLang::all_langs().iter().map(|lang| lang.name()).collect::<Vec<_>>());
347+
println!(
348+
"DynamicLang::all_langs() language.to_string(): {:?}",
349+
DynamicLang::all_langs()
350+
.iter()
351+
.map(|lang| lang.name())
352+
.collect::<Vec<_>>()
353+
);
350354
let dynamic_lang = DynamicLang::from_str(&language.to_string()).unwrap();
351355
println!("extensions loaded");
352356

@@ -548,9 +552,9 @@ pub async fn execute_ast_grep_on_paths_with_fixes(
548552
#[cfg(test)]
549553
mod tests {
550554
use super::*;
555+
use serial_test::serial;
551556
use std::fs;
552557
use tempfile::TempDir;
553-
use serial_test::serial;
554558

555559
fn create_test_file(dir: &Path, name: &str, content: &str) -> PathBuf {
556560
let file_path = dir.join(name);
@@ -719,7 +723,7 @@ message: "Found console.log statement"
719723
}
720724

721725
#[tokio::test]
722-
#[serial]
726+
#[serial]
723727
async fn test_execute_ast_grep_on_multiple_files() {
724728
let temp_dir = TempDir::new().unwrap();
725729
let temp_path = temp_dir.path();
@@ -764,7 +768,7 @@ message: "Found console.log statement"
764768
}
765769

766770
#[tokio::test]
767-
#[serial]
771+
#[serial]
768772
async fn test_execute_ast_grep_with_json_config() {
769773
let temp_dir = TempDir::new().unwrap();
770774
let temp_path = temp_dir.path();
@@ -805,7 +809,7 @@ message: "Found console.log statement"
805809
}
806810

807811
#[tokio::test]
808-
#[serial]
812+
#[serial]
809813
async fn test_execute_ast_grep_no_matches() {
810814
let temp_dir = TempDir::new().unwrap();
811815
let temp_path = temp_dir.path();
@@ -843,7 +847,7 @@ message: "Found console.log statement"
843847
}
844848

845849
#[tokio::test]
846-
#[serial]
850+
#[serial]
847851
async fn test_execute_ast_grep_nonexistent_file() {
848852
let temp_dir = TempDir::new().unwrap();
849853
let temp_path = temp_dir.path();
@@ -873,7 +877,7 @@ rule:
873877
}
874878

875879
#[tokio::test]
876-
#[serial]
880+
#[serial]
877881
async fn test_execute_ast_grep_with_recursive_glob() {
878882
let temp_dir = TempDir::new().unwrap();
879883
let temp_path = temp_dir.path();
@@ -954,7 +958,7 @@ message: "Found console.log statement"
954958
}
955959

956960
#[tokio::test]
957-
#[serial]
961+
#[serial]
958962
async fn test_execute_ast_grep_with_fixes() {
959963
let temp_dir = TempDir::new().unwrap();
960964
let temp_path = temp_dir.path();
@@ -1114,7 +1118,7 @@ message: "Found console.log statement in TSX"
11141118
}
11151119

11161120
#[tokio::test]
1117-
#[serial]
1121+
#[serial]
11181122
async fn test_generic_glob_enhancement() {
11191123
let temp_dir = TempDir::new().unwrap();
11201124
let temp_path = temp_dir.path();

crates/codemod-sandbox/src/ast_grep/sg_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'js> SgRootRjs<'js> {
7676
}
7777
}
7878

79-
impl<'js> SgRootRjs<'js> {
79+
impl SgRootRjs<'_> {
8080
pub fn try_new(
8181
lang_str: String,
8282
src: String,

crates/codemod-sandbox/src/sandbox/engine/execution_engine.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ where
185185
.map(|n| n.get())
186186
.unwrap_or(4)
187187
});
188-
let language = load_tree_sitter(
189-
&[self.config.language.unwrap_or(SupportedLanguage::Typescript)],
190-
)
188+
let language = load_tree_sitter(&[self
189+
.config
190+
.language
191+
.unwrap_or(SupportedLanguage::Typescript)])
191192
.await
192193
.unwrap()[0];
193194

crates/codemod-sandbox/src/tree_sitter/mod.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct ReadyLang {
1515

1616
pub async fn load_tree_sitter(languages: &[SupportedLanguage]) -> Result<Vec<DynamicLang>, String> {
1717
let mut ready_langs = HashSet::new();
18-
println!("languages at load_tree_sitter: {:?}", languages);
18+
println!("languages at load_tree_sitter: {languages:?}");
1919
for language in languages {
2020
let extensions = get_extensions_for_language(language.to_string().as_str());
2121
let os: &'static str = if env::consts::OS == "macos" {
@@ -44,50 +44,56 @@ pub async fn load_tree_sitter(languages: &[SupportedLanguage]) -> Result<Vec<Dyn
4444
"so"
4545
};
4646
let lib_path = data_local_dir().unwrap().join(format!(
47-
"codemod/tree_sitter/{}/{}-{}.{}",
48-
language.to_string(),
49-
os,
50-
arch,
51-
extension
47+
"codemod/tree_sitter/{language}/{os}-{arch}.{extension}"
5248
));
5349
if !lib_path.exists() {
5450
if let Some(parent) = lib_path.parent() {
5551
std::fs::create_dir_all(parent)
56-
.map_err(|e| format!("Failed to create directory: {}", e))?;
52+
.map_err(|e| format!("Failed to create directory: {e}"))?;
5753
}
58-
let url = format!("https://tree-sitter-parsers.s3.us-east-1.amazonaws.com/tree-sitter/parsers/tree-sitter-{}/latest/{}-{}.{}", language.to_string(), os, arch, extension);
54+
let url = format!("https://tree-sitter-parsers.s3.us-east-1.amazonaws.com/tree-sitter/parsers/tree-sitter-{language}/latest/{os}-{arch}.{extension}");
5955
let response = reqwest::get(url)
6056
.await
61-
.map_err(|e| format!("Failed to download: {}", e))?;
57+
.map_err(|e| format!("Failed to download: {e}"))?;
6258
let body = response
6359
.bytes()
6460
.await
65-
.map_err(|e| format!("Failed to read response: {}", e))?;
66-
std::fs::write(&lib_path, body).map_err(|e| format!("Failed to write file: {}", e))?;
67-
}
61+
.map_err(|e| format!("Failed to read response: {e}"))?;
62+
std::fs::write(&lib_path, body).map_err(|e| format!("Failed to write file: {e}"))?;
63+
}
6864
ready_langs.insert(ReadyLang {
6965
language: *language,
7066
extensions: extensions.iter().map(|s| s.to_string()).collect(),
7167
lib_path: lib_path.clone(),
7268
});
7369
}
74-
println!("ready_langs: {:?}", ready_langs.iter().map(|lang| lang.language).collect::<Vec<_>>());
75-
let registrations: Vec<Registration> = ready_langs.iter().map(|lang| Registration {
76-
lang_name: lang.language.to_string(),
77-
lib_path: lang.lib_path.clone(),
78-
symbol: format!("tree_sitter_{}", lang.language.to_string()),
79-
meta_var_char: Some('$'),
80-
expando_char: Some('$'),
81-
extensions: lang.extensions.iter().map(|s| s.to_string()).collect(),
82-
}).collect();
83-
70+
println!(
71+
"ready_langs: {:?}",
72+
ready_langs
73+
.iter()
74+
.map(|lang| lang.language)
75+
.collect::<Vec<_>>()
76+
);
77+
let registrations: Vec<Registration> = ready_langs
78+
.iter()
79+
.map(|lang| Registration {
80+
lang_name: lang.language.to_string(),
81+
lib_path: lang.lib_path.clone(),
82+
symbol: format!("tree_sitter_{}", lang.language),
83+
meta_var_char: Some('$'),
84+
expando_char: Some('$'),
85+
extensions: lang.extensions.iter().map(|s| s.to_string()).collect(),
86+
})
87+
.collect();
88+
8489
unsafe {
8590
DynamicLang::register(registrations)
86-
.map_err(|e| format!("Failed to register Rust language: {}", e))?;
91+
.map_err(|e| format!("Failed to register Rust language: {e}"))?;
8792
}
88-
Ok(ready_langs.into_iter().map(|lang| {
89-
DynamicLang::from_str(&lang.language.to_string()).unwrap()
90-
}).collect())
93+
Ok(ready_langs
94+
.into_iter()
95+
.map(|lang| DynamicLang::from_str(&lang.language.to_string()).unwrap())
96+
.collect())
9197
}
9298

9399
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
@@ -119,7 +125,7 @@ impl fmt::Display for SupportedLanguage {
119125
SupportedLanguage::Html => "html",
120126
SupportedLanguage::Kotlin => "kotlin",
121127
};
122-
write!(f, "{}", name)
128+
write!(f, "{name}")
123129
}
124130
}
125131

@@ -138,7 +144,7 @@ impl FromStr for SupportedLanguage {
138144
"css" => Ok(SupportedLanguage::Css),
139145
"html" => Ok(SupportedLanguage::Html),
140146
"kotlin" => Ok(SupportedLanguage::Kotlin),
141-
_ => Err(format!("Unsupported language: {}", s)),
147+
_ => Err(format!("Unsupported language: {s}")),
142148
}
143149
}
144150
}

crates/codemod-sandbox/src/utils/quickjs_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pub async fn maybe_promise<'js>(
77
let promise = result_obj.as_promise().unwrap().clone();
88
let ctx = result_obj.ctx();
99
while ctx.execute_pending_job() {}
10-
let result = promise.into_future::<rquickjs_compat::Value<'js>>().await?;
11-
result
10+
11+
promise.into_future::<rquickjs_compat::Value<'js>>().await?
1212
} else {
1313
result_obj.clone()
1414
};

crates/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod engine;
2+
pub mod error;
23
pub mod registry;
34
pub mod utils;
4-
pub mod error;
55

66
pub use butterflow_models::{
77
Error, Node, Result, StateSchema, StateSchemaItems, StateSchemaProperty, StateSchemaType, Task,

xtask/src/ts_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Visit<'a> {
1111
type_names: &'a mut HashSet<String>,
1212
}
1313

14-
impl<'a> TypeVisitor for Visit<'a> {
14+
impl TypeVisitor for Visit<'_> {
1515
fn visit<T: TS + 'static + ?Sized>(&mut self) {
1616
if T::output_path().is_none() {
1717
return;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy