|
1 | 1 | use super::{Lint, LintKind, Linter, Suggestion};
|
2 |
| -use crate::{Span, TokenKind, TokenStringExt}; |
| 2 | +use crate::{Span, Token, TokenKind, TokenStringExt}; |
3 | 3 |
|
4 | 4 | const MSG_SPACE_BEFORE: &str = "Don't use a space before a comma.";
|
5 | 5 | const MSG_AVOID_ASIAN: &str = "Avoid East Asian commas in English contexts.";
|
@@ -118,8 +118,13 @@ impl Linter for CommaFixes {
|
118 | 118 | add_space_after = true;
|
119 | 119 | }
|
120 | 120 |
|
| 121 | + // Handles Asian commas in all other contexts |
| 122 | + // TokenKind::Unlintable is used for non-English tokens |
| 123 | + // to prevent changing commas within CJK text |
121 | 124 | (None | Some(_), None | Some(_), _, None | Some(_), None | Some(_))
|
122 |
| - if comma_kind != ',' => |
| 125 | + if comma_kind != ',' |
| 126 | + && !matches!(toks.1, Some(Token { kind: TokenKind::Unlintable, .. })) |
| 127 | + && !matches!(toks.3, Some(Token { kind: TokenKind::Unlintable, .. })) => |
123 | 128 | {
|
124 | 129 | span = toks.2.span;
|
125 | 130 | suggestion = Suggestion::ReplaceWith(vec![',']);
|
@@ -242,4 +247,9 @@ mod tests {
|
242 | 247 | fn corrects_asian_comma_between_words_with_space_on_both_sides() {
|
243 | 248 | assert_suggestion_result("foo 、 bar", CommaFixes, "foo, bar")
|
244 | 249 | }
|
| 250 | + |
| 251 | + #[test] |
| 252 | + fn doesnt_correct_comma_between_non_english_tokens() { |
| 253 | + assert_lint_count("严禁采摘花、 果、叶,挖掘树根、草药!", CommaFixes, 0); |
| 254 | + } |
245 | 255 | }
|
0 commit comments