From f70e93b2f5b9d0da48aa888fd26d8dde9633a5bb Mon Sep 17 00:00:00 2001 From: dalaoshu Date: Thu, 10 Oct 2024 21:35:24 +0800 Subject: [PATCH] refactor(oxc): ban index methods on std::str::Chars (#6075) closes #6071 --- .github/workflows/ci.yml | 9 +++++++++ crates/oxc_linter/src/rules/nextjs/no_typos.rs | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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 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);