Skip to content

Commit 74ccb01

Browse files
committed
feat(rule): 末尾がスペースであるパターンを追加
1 parent 276b430 commit 74ccb01

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"use strict";
33
const RuleHelper = require("textlint-rule-helper").RuleHelper;
44
const japaneseRegExp = /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])/;
5-
const exceptionMarkRegExp = /[!?\) ]/;
5+
const exceptionMarkRegExp = /[!?\)]/;
66
const defaultPeriodMark = /[\.]/;
77
const defaultOptions = {
88
// 優先する句点文字
@@ -32,6 +32,14 @@ const reporter = (context, options = {}) => {
3232
if (lastChar === undefined) {
3333
return;
3434
}
35+
// 文末がスペースである場合
36+
if (/\s/.test(lastChar)) {
37+
report(lastNode, new RuleError(`文末が"${periodMark}"で終わっていません。末尾に不要なスペースがあります。`, {
38+
index: lastIndex,
39+
fix: fix
40+
}));
41+
return
42+
}
3543
// 末尾の"文字"が句点以外で末尾に使われる文字であるときは無視する
3644
// 例外: 感嘆符
3745
// 例外: 「」 () ()『』

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ tester.run("textlint-rule-ja-no-mixed-period", rule, {
4848
}
4949
]
5050
},
51+
{
52+
text: "末尾にスペースがある。 ",
53+
errors: [
54+
{
55+
message: `文末が"。"で終わっていません。末尾に不要なスペースがあります。`,
56+
line: 1,
57+
column: 12
58+
}
59+
]
60+
},
5161
// multiple hit items in a line
5262
{
5363
text: "これは句点がありません、これは句点がありません",

0 commit comments

Comments
 (0)