Skip to content

Commit fbc5688

Browse files
committed
Merge pull request #23 from matsu-chara/su-ju-oku
2.2.2 - 数十万・数十億といった表現を許可
2 parents dafc6a5 + 8503448 commit fbc5688

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/2.2.2.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,21 @@ export default function (context) {
145145
}));
146146
};
147147

148+
// ignorePatternにマッチしたらmatchFnを呼ばないようにする(エラーを無視する)
149+
let ignoreWhenMatched = (ignorePattern, matchFn) => {
150+
return (text, pattern, match) => {
151+
if (ignorePattern.test(text)) {
152+
return null;
153+
} else {
154+
return matchFn(text, pattern, match);
155+
}
156+
}
157+
}
158+
148159
// 数えられる数字は算用数字を使う
149-
matchToReplace(text,
150-
/([]+)[]/g, toNumber
160+
// 数十万、数百億にマッチしないように"数"という文字から始まるものは除外
161+
matchToReplace(text, /([]+)[]/g,
162+
ignoreWhenMatched(/([]+)[]/g ,toNumber)
151163
);
152164
matchToReplace(text, /([]+)/g, toNumber);
153165
matchToReplace(text, /([]+)/g, toNumber);
@@ -165,8 +177,9 @@ export default function (context) {
165177
matchToReplace(text, /(1)/g, toKanNumber);
166178
matchToReplace(text, /(1)/g, toKanNumber);
167179
matchToReplace(text, /([0-9]+)/g, toKanNumber);
180+
matchToReplace(text, /([0-9]+)[]/g, toKanNumber);
168181
matchToReplace(text, /([0-9]+)/g, toKanNumber);
169182
matchToReplace(text, /(5)/g, toKanNumber);
170183
}
171184
}
172-
}
185+
}

test/2.2.2-test.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ tester.run("2.2.2.算用数字と漢数字の使い分け", rule, {
7070
"二次関数",
7171
"四捨五入",
7272
"四角い",
73-
"五大陸"
73+
"五大陸",
74+
"数十億",
75+
"しばしば数十万行以上に"
7476
],
7577
invalid: [
7678
{
@@ -108,6 +110,28 @@ tester.run("2.2.2.算用数字と漢数字の使い分け", rule, {
108110
慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。`
109111
}
110112
]
113+
},
114+
{
115+
text: "数10億",
116+
errors: [
117+
{
118+
message: `数10億 => 数十億
119+
慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。`,
120+
line: 1,
121+
column: 1
122+
}
123+
]
124+
},
125+
{
126+
text: "しばしば数10万行以上に",
127+
errors: [
128+
{
129+
message: `数10万 => 数十万
130+
慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。`,
131+
line: 1,
132+
column: 1
133+
}
134+
]
111135
}
112136
]
113-
});
137+
});

0 commit comments

Comments
 (0)