Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored and shulaoda committed Sep 11, 2024
1 parent a79428b commit 53e04c5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/fixer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ impl<'a> Fixer<'a> {

#[cfg(test)]
mod test {
use cow_utils::CowUtils;
use std::borrow::Cow;

use oxc_diagnostics::OxcDiagnostic;
Expand Down Expand Up @@ -417,7 +418,7 @@ mod test {
get_fix_result(vec![create_message(insert_at_middle(), Some(INSERT_AT_MIDDLE))]);
assert_eq!(
result.fixed_code,
TEST_CODE.replace("6 *", &format!("{}{}", INSERT_AT_MIDDLE.content, "6 *"))
TEST_CODE.cow_replace("6 *", &format!("{}{}", INSERT_AT_MIDDLE.content, "6 *"))
);
assert_eq!(result.messages.len(), 0);
}
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/unicorn/prefer_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ fn is_not_array(expr: &Expression, ctx: &LintContext) -> bool {
_ => return false,
};

if ident.cow_to_ascii_uppercase() != ident {
if ident.starts_with(|c: char| c.is_ascii_uppercase())
&& ident.cow_to_ascii_uppercase() != ident
{
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_linter/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use cow_utils::CowUtils;
use oxc_allocator::Allocator;
use oxc_diagnostics::{DiagnosticService, GraphicalReportHandler, GraphicalTheme, NamedSource};
use serde::Deserialize;
Expand Down Expand Up @@ -185,7 +186,7 @@ impl Tester {
expect_pass: Vec<T>,
expect_fail: Vec<T>,
) -> Self {
let rule_path = PathBuf::from(rule_name.replace('-', "_")).with_extension("tsx");
let rule_path = PathBuf::from(rule_name.cow_replace('-', "_")).with_extension("tsx");
let expect_pass = expect_pass.into_iter().map(Into::into).collect::<Vec<_>>();
let expect_fail = expect_fail.into_iter().map(Into::into).collect::<Vec<_>>();
let current_working_directory =
Expand Down Expand Up @@ -294,7 +295,7 @@ impl Tester {
}

fn snapshot(&self) {
let name = self.rule_name.replace('-', "_");
let name = self.rule_name.cow_replace('-', "_");
let mut settings = insta::Settings::clone_current();

settings.set_prepend_module_to_snapshot(false);
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_sourcemap/src/sourcemap_visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl<'a> SourcemapVisualizer<'a> {
}
}

let replaced: Cow<str> = s.as_str().cow_replace("\r", "");
let replaced: Cow<str> = s.cow_replace("\r", "");

// Windows: Replace "\r\n" and replace with "\n"
Cow::Owned(replaced.into_owned())
Expand Down

0 comments on commit 53e04c5

Please sign in to comment.