Skip to content

Commit

Permalink
fix(2.2.2): 11種類」が「1一種類」と誤検知される問題を修正 (#66)
Browse files Browse the repository at this point in the history
fix #65
  • Loading branch information
azu committed Jan 31, 2019
1 parent 174187a commit 09e6a62
Show file tree
Hide file tree
Showing 17 changed files with 4,075 additions and 38 deletions.
8 changes: 6 additions & 2 deletions src/1.1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ module.exports = function(context) {
matches.forEach(match => {
let message;
if (desumasu) {
message = `本文を常体(である調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${match.value}"が敬体(ですます調)です。`;
message = `本文を常体(である調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${
match.value
}"が敬体(ですます調)です。`;
} else if (dearu) {
message = `本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${match.value}"が常体(である調)です。`;
message = `本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"${
match.value
}"が常体(である調)です。`;
}
report(
node,
Expand Down
8 changes: 6 additions & 2 deletions src/1.1.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ module.exports = function(context) {
matches.forEach(match => {
let message;
if (desumasu) {
message = `箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${match.value}"が常体(である調)です。`;
message = `箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${
match.value
}"が常体(である調)です。`;
} else if (dearu) {
message = `箇条書きを常体(である調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${match.value}"が敬体(ですます調)です。`;
message = `箇条書きを常体(である調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"${
match.value
}"が敬体(ですます調)です。`;
}
report(
node,
Expand Down
8 changes: 6 additions & 2 deletions src/1.1.5.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ module.exports = function(context) {
matches.forEach(match => {
let message;
if (desumasu) {
message = `図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${match.value}"が常体(である調)です。`;
message = `図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${
match.value
}"が常体(である調)です。`;
} else if (dearu) {
message = `図表のキャプションを常体(である調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${match.value}"が敬体(ですます調)です。`;
message = `図表のキャプションを常体(である調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"${
match.value
}"が敬体(ですます調)です。`;
}
report(
node,
Expand Down
11 changes: 7 additions & 4 deletions src/1.2.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ const reporter = context => {
const indexOfSymbol = match.index;
report(
node,
new RuleError("句読点には全角の「、」と「。」を使います。和文の句読点としてピリオド(.)とカンマ(,)を使用しません。", {
index: indexOfSymbol,
fix: fixer.replaceTextRange([indexOfSymbol, indexOfSymbol + 1], symbol)
})
new RuleError(
"句読点には全角の「、」と「。」を使います。和文の句読点としてピリオド(.)とカンマ(,)を使用しません。",
{
index: indexOfSymbol,
fix: fixer.replaceTextRange([indexOfSymbol, indexOfSymbol + 1], symbol)
}
)
);
});
}
Expand Down
12 changes: 9 additions & 3 deletions src/2.2.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"use strict";
import { isUserWrittenNode } from "./util/node-util";
import ja2num from "japanese-numerals-to-number";

function matchToReplace(text, pattern, matchFn) {
var match = pattern.exec(text);
if (match) {
Expand Down Expand Up @@ -129,8 +130,12 @@ function reporter(context) {
report(node, ruleError);
};

// 算用数字 -> 漢数字

/**
* 算用数字 -> 漢数字
* @param {string} text
* @param {RegExp} pattern
* @param {*[]} match
*/
const toKanNumber = (text, pattern, match) => {
const matchedString = match[0];
const expected = matchedString.replace(pattern, function(all, match) {
Expand Down Expand Up @@ -183,7 +188,8 @@ function reporter(context) {
matchToReplace(text, /(1)時的/g, toKanNumber);
matchToReplace(text, /(1)部分/g, toKanNumber);
matchToReplace(text, /第(3)者/g, toKanNumber);
matchToReplace(text, /(1)種/g, toKanNumber);
// 1種 -> 一種: 11種類などにはマッチしない
matchToReplace(text, /[^\d](1)種(?!類)/g, toKanNumber);
matchToReplace(text, /(1)部の/g, toKanNumber);
matchToReplace(text, /(1)番に/g, toKanNumber);
matchToReplace(text, /数([0-9]+)倍/g, toKanNumber);
Expand Down
11 changes: 7 additions & 4 deletions src/4.2.4.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ function reporter(context) {
const { index } = match;
report(
node,
new RuleError("カタカナ複合語を区切る場合または同格の語句を並列する場合には全角の中黒(・)を使用します。", {
index: index,
fix: fixer.replaceTextRange([index, index + 1], "・")
})
new RuleError(
"カタカナ複合語を区切る場合または同格の語句を並列する場合には全角の中黒(・)を使用します。",
{
index: index,
fix: fixer.replaceTextRange([index, index + 1], "・")
}
)
);
});
}
Expand Down
9 changes: 6 additions & 3 deletions test/1.1.1-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ tester.run("1.1.1.本文", rule, {
それはペンです。`,
errors: [
{
message: '本文を常体(である調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"です。"が敬体(ですます調)です。',
message:
'本文を常体(である調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"です。"が敬体(ですます調)です。',
line: 5,
column: 6
}
Expand All @@ -38,7 +39,8 @@ tester.run("1.1.1.本文", rule, {
`,
errors: [
{
message: '本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"のだが"が常体(である調)です。',
message:
'本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"のだが"が常体(である調)です。',
line: 1,
column: 8
}
Expand All @@ -49,7 +51,8 @@ tester.run("1.1.1.本文", rule, {
text: `今日はいい天気ですね。今日はいい天気である。`,
errors: [
{
message: '本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"である。"が常体(である調)です。',
message:
'本文を敬体(ですます調)に統一して下さい。\n本文の文体は、敬体(ですます調)あるいは常体(である調)のどちらかで統一します。\n"である。"が常体(である調)です。',
line: 1,
column: 19
}
Expand Down
15 changes: 10 additions & 5 deletions test/1.1.3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ tester.run("1.1.3.箇条書き", rule, {
`.trim(),
errors: [
{
message: '箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"である。"が常体(である調)です。',
message:
'箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"である。"が常体(である調)です。',
line: 3,
column: 14
}
Expand All @@ -41,7 +42,8 @@ tester.run("1.1.3.箇条書き", rule, {
`.trim(),
errors: [
{
message: '箇条書きを常体(である調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"です。"が敬体(ですます調)です。',
message:
'箇条書きを常体(である調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"です。"が敬体(ですます調)です。',
line: 1,
column: 15
}
Expand All @@ -55,7 +57,8 @@ tester.run("1.1.3.箇条書き", rule, {
`.trim(),
errors: [
{
message: '箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"である。"が常体(である調)です。',
message:
'箇条書きを敬体(ですます調)に統一して下さい。\nひとまとまりの箇条書きでは、敬体と常体を混在させません。\n"である。"が常体(である調)です。',
line: 2,
column: 14
}
Expand All @@ -68,7 +71,8 @@ tester.run("1.1.3.箇条書き", rule, {
`.trim(),
errors: [
{
message: "箇条書きの文末に句点(。)を付けて下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。",
message:
"箇条書きの文末に句点(。)を付けて下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。",
line: 2,
column: 1 // 無指定なので - PR Welcome
}
Expand All @@ -82,7 +86,8 @@ tester.run("1.1.3.箇条書き", rule, {
`.trim(),
errors: [
{
message: "箇条書きの文末から句点(。)を外して下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。",
message:
"箇条書きの文末から句点(。)を外して下さい。\n箇条書きの文末に句点(。)を付けるかを統一します。",
line: 1,
column: 1 // 無指定なので - PR Welcome
}
Expand Down
9 changes: 6 additions & 3 deletions test/1.1.5-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ tester.run("1.1.5.図表のキャプション", rule, {
"![これは図です。](http://example.com/img) と ![これは図です。](http://example.com/img) と ![これは図である。](http://example.com/img).",
errors: [
{
message: '図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"である。"が常体(である調)です。',
message:
'図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"である。"が常体(である調)です。',
line: 1,
column: 82
}
Expand All @@ -26,7 +27,8 @@ tester.run("1.1.5.図表のキャプション", rule, {
"![これは図です。](http://example.com/img) と ![これは図である。](http://example.com/img) と ![これは図である。](http://example.com/img).",
errors: [
{
message: '図表のキャプションを常体(である調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"です。"が敬体(ですます調)です。',
message:
'図表のキャプションを常体(である調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"です。"が敬体(ですます調)です。',
line: 1,
column: 7 // imgのposition
}
Expand All @@ -37,7 +39,8 @@ tester.run("1.1.5.図表のキャプション", rule, {
text: "![これは図です。](http://example.com/img) と ![これは図である。](http://example.com/img).",
errors: [
{
message: '図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"である。"が常体(である調)です。',
message:
'図表のキャプションを敬体(ですます調)に統一して下さい。\n図表のキャプション内で敬体、常体を混在させないことが重要です。\n"である。"が常体(である調)です。',
line: 1,
column: 44
}
Expand Down
6 changes: 4 additions & 2 deletions test/1.2.1-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ tester.run("1.2.1.句点(。)と読点(、)", rule, {
output: "これは、見本となる例です。",
errors: [
{
message: "句読点には全角の「、」と「。」を使います。和文の句読点としてピリオド(.)とカンマ(,)を使用しません。",
message:
"句読点には全角の「、」と「。」を使います。和文の句読点としてピリオド(.)とカンマ(,)を使用しません。",
column: 4
},
{
message: "句読点には全角の「、」と「。」を使います。和文の句読点としてピリオド(.)とカンマ(,)を使用しません。",
message:
"句読点には全角の「、」と「。」を使います。和文の句読点としてピリオド(.)とカンマ(,)を使用しません。",
column: 13
}
]
Expand Down
3 changes: 2 additions & 1 deletion test/2.1.5-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ tester.run("2.1.5.カタカナ", rule, {
},
{
text: "ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚",
output: "ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゛゜",
output:
"ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゛゜",
errors: [
{
message: "カタカナは「全角」で表記します。",
Expand Down
12 changes: 11 additions & 1 deletion test/2.2.2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TextLintTester from "textlint-tester";
import rule from "../src/2.2.2";
var tester = new TextLintTester();
tester.run("2.2.2.算用数字と漢数字の使い分け", rule, {
valid: ["1億2805 万人", "3つのボタン", "第3回大会", "第3章", "20回", "第3節", "4種類"],
valid: ["1億2805 万人", "3つのボタン", "第3回大会", "第3章", "20回", "第3節", "4種類", "11種類"],
invalid: [
{
text: "第三章",
Expand Down Expand Up @@ -115,6 +115,16 @@ tester.run("2.2.2.算用数字と漢数字の使い分け", rule, {
errors: [
{
message: `1部の => 一部の
慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。`
}
]
},
{
text: "これは花の1種です",
output: "これは花の一種です",
errors: [
{
message: `の1種 => の一種
慣用的表現、熟語、概数、固有名詞、副詞など、漢数字を使用することが一般的な語句では漢数字を使います。`
}
]
Expand Down
3 changes: 2 additions & 1 deletion test/4.2.4-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ tester.run("4.2.4.中黒(・)", rule, {
text: "小・中学校",
errors: [
{
message: "カタカナ複合語を区切る場合または同格の語句を並列する場合には全角の中黒(・)を使用します。",
message:
"カタカナ複合語を区切る場合または同格の語句を並列する場合には全角の中黒(・)を使用します。",
column: 2
}
]
Expand Down
Loading

0 comments on commit 09e6a62

Please sign in to comment.