Skip to content

Commit dadcf03

Browse files
committed
refactor: improve colon detection implementation
- Remove redundant colon index calculation - Determine colon type once and reuse - Remove unused colonIndex variable - Keep clean and efficient implementation
1 parent 8b57e63 commit dadcf03

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/rules/no-ai-colon-continuation.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ const rule = (context: any, options: any = {}) => {
6262
return;
6363
}
6464

65+
// コロンの種類を特定
66+
const isFullWidthColon = plainText.endsWith(":");
67+
const colonChar = isFullWidthColon ? ":" : ":";
68+
6569
// コロンを除いたテキストを取得
6670
const beforeColonText = plainText.slice(0, -1);
6771

@@ -138,16 +142,12 @@ const rule = (context: any, options: any = {}) => {
138142
})();
139143

140144
if (shouldReport) {
141-
// 半角・全角コロンの位置を検索
142-
const halfWidthIndex = paragraphText.lastIndexOf(":");
143-
const fullWidthIndex = paragraphText.lastIndexOf(":");
144-
const colonIndex = Math.max(halfWidthIndex, fullWidthIndex);
145-
const matchRange = [colonIndex, colonIndex + 1] as const;
146-
147-
// メッセージに元のコロン文字を含める
148-
const originalColon = fullWidthIndex > halfWidthIndex ? ":" : ":";
145+
// paragraphTextでのコロン位置を計算(StringSourceとの位置差を考慮)
146+
const paragraphColonIndex = paragraphText.lastIndexOf(colonChar);
147+
const matchRange = [paragraphColonIndex, paragraphColonIndex + 1] as const;
148+
149149
const ruleError = new RuleError(
150-
`「${beforeColonText}${originalColon}」のようなパターンは英語構文の直訳の可能性があります。より自然な日本語表現を検討してください。`,
150+
`「${beforeColonText}${colonChar}」のようなパターンは英語構文の直訳の可能性があります。より自然な日本語表現を検討してください。`,
151151
{
152152
padding: locator.range(matchRange)
153153
}

0 commit comments

Comments
 (0)