Skip to content

2.2.2 - 数十万・数十億といった表現を許可 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/2.2.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,21 @@ export default function (context) {
}));
};

// ignorePatternにマッチしたらmatchFnを呼ばないようにする(エラーを無視する)
let ignoreWhenMatched = (ignorePattern, matchFn) => {
return (text, pattern, match) => {
if (ignorePattern.test(text)) {
return null;
} else {
return matchFn(text, pattern, match);
}
}
}

// 数えられる数字は算用数字を使う
matchToReplace(text,
/([一二三四五六七八九十壱弐参拾百〇]+)[兆億万]/g, toNumber
// 数十万、数百億にマッチしないように"数"という文字から始まるものは除外
matchToReplace(text, /([一二三四五六七八九十壱弐参拾百〇]+)[兆億万]/g,
ignoreWhenMatched(/数([一二三四五六七八九十壱弐参拾百〇]+)[兆億万]/g ,toNumber)
);
matchToReplace(text, /([一二三四五六七八九十壱弐参拾百〇]+)つ/g, toNumber);
matchToReplace(text, /([一二三四五六七八九十壱弐参拾百〇]+)回/g, toNumber);
Expand All @@ -165,8 +177,9 @@ export default function (context) {
matchToReplace(text, /(1)部の/g, toKanNumber);
matchToReplace(text, /(1)番に/g, toKanNumber);
matchToReplace(text, /数([0-9]+)倍/g, toKanNumber);
matchToReplace(text, /数([0-9]+)[兆億万]/g, toKanNumber);
matchToReplace(text, /([0-9]+)次関数/g, toKanNumber);
matchToReplace(text, /(5)大陸/g, toKanNumber);
}
}
}
}
28 changes: 26 additions & 2 deletions test/2.2.2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ tester.run("2.2.2.算用数字と漢数字の使い分け", rule, {
"二次関数",
"四捨五入",
"四角い",
"五大陸"
"五大陸",
"数十億",
"しばしば数十万行以上に"
],
invalid: [
{
Expand Down Expand Up @@ -108,6 +110,28 @@ tester.run("2.2.2.算用数字と漢数字の使い分け", rule, {
慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。`
}
]
},
{
text: "数10億",
errors: [
{
message: `数10億 => 数十億
慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。`,
line: 1,
column: 1
}
]
},
{
text: "しばしば数10万行以上に",
errors: [
{
message: `数10万 => 数十万
慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。`,
line: 1,
column: 1
}
]
}
]
});
});