Skip to content

Commit 776b83a

Browse files
committed
fix: 漢数字の連続は例外とする
fix #22
1 parent 1fb5a7f commit 776b83a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/textlint-rule-ja-no-successive-word.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const DefaultOptions = {
99
// 例) カクカク、ドキドキ、ビリビリ
1010
// https://ja.wikipedia.org/wiki/%E6%93%AC%E5%A3%B0%E8%AA%9E
1111
allowOnomatopee: true,
12-
12+
1313
// 許可する単語
1414
// RegExp-like Stringを使用可能
1515
allow: []
@@ -19,9 +19,19 @@ function isOnomatopee(str) {
1919
return /^[-]*$/.test(str);
2020
}
2121

22-
export default function(context, options = {}) {
22+
/**
23+
* 漢数字かどうかを判定する
24+
* https://azu.github.io/morpheme-match/?text=%E5%80%A4%E3%81%AF%E4%B9%9D%E4%B9%9D%E3%81%A7%E3%81%99%E3%80%82
25+
* @param {import("kuromojin").KuromojiToken} token
26+
* @returns {boolean}
27+
*/
28+
function isNumberToken(token) {
29+
return token.pos === "名詞" && token.pos_detail_1 === "数";
30+
}
31+
32+
export default function (context, options = {}) {
2333
const allowOnomatopee = options.allowOnomatopee !== undefined ? options.allowOnomatopee
24-
: DefaultOptions.allowOnomatopee;
34+
: DefaultOptions.allowOnomatopee;
2535
const allow = options.allow || DefaultOptions.allow;
2636
const { Syntax, RuleError, report, getSource } = context;
2737
return {
@@ -38,6 +48,12 @@ export default function(context, options = {}) {
3848
if (prevWord !== currentWord) {
3949
return;
4050
}
51+
// 漢数字は例外とする
52+
// 例) 値は"九九"です。
53+
// https://azu.github.io/morpheme-match/?text=%E5%80%A4%E3%81%AF%E4%B9%9D%E4%B9%9D%E3%81%A7%E3%81%99%E3%80%82
54+
if (isNumberToken(prevToken) && isNumberToken(nextToken)) {
55+
return;
56+
}
4157
if (allowOnomatopee && isOnomatopee(prevWord) && isOnomatopee(currentWord)) {
4258
return;
4359
}

test/textlint-rule-ja-no-successive-word-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ tester.run("ja-no-successive-word", rule, {
99
"これは問題ない文章です。",
1010
"すもももももももものうち",
1111
"111回目の問題",
12+
"ニニ回目の問題",
13+
"九九回目の問題",
1214
"11,11回目の問題",
1315
"フレームレートが落ちて動作がカクカクしてきた",
1416
{

0 commit comments

Comments
 (0)