refactor(oxc): ban index methods on std::str::Chars (#6075)

closes #6071
This commit is contained in:
dalaoshu 2024-10-10 21:35:24 +08:00 committed by GitHub
parent c5deb3235e
commit f70e93b2f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View file

@ -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

View file

@ -133,9 +133,9 @@ fn min_distance(a: &str, b: &str) -> usize {
let mut previous_row: Vec<usize> = (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);