Skip to content

Commit 8b57e63

Browse files
committed
fix: support full-width colon and add original test cases
- Add support for both half-width (:) and full-width (:) colons - Include conjunction detection (例えば: should be flagged) - Port original test cases from ai-tech-writing-guideline - Ensure proper colon character display in error messages - All tests now passing with comprehensive pattern coverage
1 parent c9b09b4 commit 8b57e63

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ const rule = (context: any, options: any = {}) => {
4848
}
4949
}
5050

51-
// コロンで終わっているかチェック
52-
if (!paragraphText.trim().endsWith(":")) {
51+
// コロン(半角・全角)で終わっているかチェック
52+
if (!/[:]$/.test(paragraphText.trim())) {
5353
return;
5454
}
5555

5656
// StringSourceを使ってMarkdownを取り除いたテキストを取得
5757
const stringSource = new StringSource(paragraphNode);
5858
const plainText = stringSource.toString().trim();
5959

60-
// プレーンテキストでもコロンで終わっているかチェック
61-
if (!plainText.endsWith(":")) {
60+
// プレーンテキストでもコロン(半角・全角)で終わっているかチェック
61+
if (!/[:]$/.test(plainText)) {
6262
return;
6363
}
6464

@@ -101,7 +101,12 @@ const rule = (context: any, options: any = {}) => {
101101
return false;
102102
}
103103

104-
// その他の品詞(助詞、接続詞等)の場合は文脈による
104+
// 接続詞の場合もエラーとする(「例えば:」等は機械的パターン)
105+
if (partOfSpeech === "接続詞") {
106+
return false;
107+
}
108+
109+
// その他の品詞(助詞等)の場合は文脈による
105110
// より保守的にエラーとする
106111
return false;
107112
} catch (error) {
@@ -133,11 +138,16 @@ const rule = (context: any, options: any = {}) => {
133138
})();
134139

135140
if (shouldReport) {
136-
const colonIndex = paragraphText.lastIndexOf(":");
141+
// 半角・全角コロンの位置を検索
142+
const halfWidthIndex = paragraphText.lastIndexOf(":");
143+
const fullWidthIndex = paragraphText.lastIndexOf(":");
144+
const colonIndex = Math.max(halfWidthIndex, fullWidthIndex);
137145
const matchRange = [colonIndex, colonIndex + 1] as const;
138146

147+
// メッセージに元のコロン文字を含める
148+
const originalColon = fullWidthIndex > halfWidthIndex ? ":" : ":";
139149
const ruleError = new RuleError(
140-
`「${beforeColonText}:」のようなパターンは英語構文の直訳の可能性があります。より自然な日本語表現を検討してください。`,
150+
`「${beforeColonText}${originalColon}」のようなパターンは英語構文の直訳の可能性があります。より自然な日本語表現を検討してください。`,
141151
{
142152
padding: locator.range(matchRange)
143153
}

test.textlintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rules": {"@textlint-ja/preset-ai-writing": true}}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ tester.run("no-ai-colon-continuation", noAiColonContinuation, {
116116
"「表示します:」のようなパターンは英語構文の直訳の可能性があります。より自然な日本語表現を検討してください。"
117117
}
118118
]
119+
},
120+
121+
// 元々 ai-tech-writing-guideline にあったテストケースの移植
122+
{
123+
text: "例えば:\n\n- refとreactiveの使い分けが最初は分からない。",
124+
errors: [
125+
{
126+
message:
127+
"「例えば:」のようなパターンは英語構文の直訳の可能性があります。より自然な日本語表現を検討してください。"
128+
}
129+
]
130+
},
131+
{
132+
text: "JSXはJavaScriptの中でUIを記述するため、プログラマーにとって理解しやすいです:\n\n- 条件分岐やループは通常のJavaScriptの記法",
133+
errors: [
134+
{
135+
message:
136+
"「JSXはJavaScriptの中でUIを記述するため、プログラマーにとって理解しやすいです:」のようなパターンは英語構文の直訳の可能性があります。より自然な日本語表現を検討してください。"
137+
}
138+
]
119139
}
120140
]
121141
});

0 commit comments

Comments
 (0)