Skip to content

Commit e9e8e06

Browse files
committed
feat(rule): 日本語ではないパラグラフは無視する
1 parent c0fe3bc commit e9e8e06

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,26 @@ textlint --rule ja-no-mixed-period README.md
5151

5252
## 例外
5353

54+
**会話文**
55+
5456
末尾に``がない場合でも、代わりに感嘆符や疑問符、括弧などがある場合は例外として扱います。
5557

5658
> これは問題ない文章ですか!?
5759
> 「会話文は括弧で括れば末尾に。がなくても問題ありません」
5860
61+
**箇条書き**
62+
5963
箇条書きの中はチェックせず無視します。
6064

6165
```
6266
- これは問題ないです
6367
- これも問題ないです
6468
```
6569

70+
**日本語ではない**
71+
72+
日本語が含まれていないパラグラフは無視します。
73+
6674
## 参考情報
6775

6876
- [句点 - Wikipedia](https://ja.wikipedia.org/wiki/%E5%8F%A5%E7%82%B9 "句点 - Wikipedia")

src/textlint-rule-ja-no-mixed-period.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// LICENSE : MIT
22
"use strict";
33
const RuleHelper = require("textlint-rule-helper").RuleHelper;
4+
const japaneseRegExp = /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])/;
45
const exceptionMarkRegExp = /[!?\) ]/;
56
const defaultPeriodMark = /[\.]/;
67
const defaultOptions = {
@@ -22,6 +23,9 @@ const reporter = (context, options = {}) => {
2223
return;
2324
}
2425
const lastStrText = getSource(lastNode);
26+
if (!japaneseRegExp.test(lastStrText)) {
27+
return;
28+
}
2529
const lastIndex = lastStrText.length - 1;
2630
const lastChar = lastStrText[lastIndex];
2731
if (lastChar === undefined) {

test/textlint-rule-ja-no-mixed-period-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tester.run("textlint-rule-ja-no-mixed-period", rule, {
99
"1行目 空白はあるけど末尾に句点はある。",
1010
// 例外: 感嘆符などが末尾にある場合は問題なし
1111
"末尾に句点はある!",
12+
"english only",
1213
// 例外のNode type
1314
`- 箇条書きは無視される`,
1415
`![画像の説明も無視される](img/img.png)`,
@@ -61,16 +62,16 @@ tester.run("textlint-rule-ja-no-mixed-period", rule, {
6162
},
6263
// options
6364
{
64-
text: "This is error",
65-
output: "This is error.",
65+
text: "これはダメ",
66+
output: "これはダメ.",
6667
options: {
6768
periodMark: "."
6869
},
6970
errors: [
7071
{
7172
message: `文末が"."で終わっていません。`,
7273
line: 1,
73-
column: 13
74+
column: 5
7475
}
7576
]
7677
}

0 commit comments

Comments
 (0)