From 100b0cdf4627c29d8c24f07452251e55553493b9 Mon Sep 17 00:00:00 2001 From: shulaoda Date: Thu, 26 Sep 2024 20:07:50 +0800 Subject: [PATCH 1/2] refactor(oxc): ban index methods on std::str::Chars --- crates/oxc_linter/src/rules/nextjs/no_typos.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/rules/nextjs/no_typos.rs b/crates/oxc_linter/src/rules/nextjs/no_typos.rs index b380d668bd582..097f3d2b3e2b9 100644 --- a/crates/oxc_linter/src/rules/nextjs/no_typos.rs +++ b/crates/oxc_linter/src/rules/nextjs/no_typos.rs @@ -133,9 +133,9 @@ fn min_distance(a: &str, b: &str) -> usize { let mut previous_row: Vec = (0..=n).collect(); - for (i, s1) in a.chars().enumerate() { + for (i, s1) in a.char_indices() { let mut current_row = vec![i + 1]; - for (j, s2) in b.chars().enumerate() { + for (j, s2) in b.char_indices() { let insertions = previous_row[j + 1] + 1; let deletions = current_row[j] + 1; let substitutions = previous_row[j] + usize::from(s1 != s2); From b5dee29cb351033eab36bff4a21231db8ce28aa3 Mon Sep 17 00:00:00 2001 From: shulaoda Date: Fri, 27 Sep 2024 10:27:52 +0800 Subject: [PATCH 2/2] chore(ci): add check --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2548f8a5616a5..0c7dbdee783cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -178,7 +178,16 @@ jobs: with: cache-key: warm components: clippy + tools: ast-grep - run: cargo lint -- -D warnings + - name: Check Char and Byte Offset + run: | + output=$(sg -p '$A.chars().enumerate()' -r '$A.char_indices()' -l rs) + echo "Output: $output" + if [ -n "$output" ]; then + echo "Error: Unexpected output detected" + exit 1 + fi doc: name: Doc