Skip to content

Commit

Permalink
fix(4.3.1): 開きかっこと閉じかっこを両方reportする (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
massongit committed Sep 12, 2020
1 parent e9c58f7 commit b8cdd16
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
28 changes: 17 additions & 11 deletions src/4.3.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@ function reporter(context) {
}
// 半角のかっこ()は使用しないで全角のかっこを使用する
const text = getSource(node);
const matchRegExp = rx`(?:${japaneseRegExp})([\(\)])`;
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
const { index } = match;
report(
node,
new RuleError("半角のかっこ()が使用されています。全角のかっこ()を使用してください。", {
index: index,
fix: fixer.replaceTextRange([index, index + 1], replaceSymbol(match.text))
})
);
});
const matchRegExps = [
rx`([\(\)])(?:.*${japaneseRegExp}+.*)([\(\)])`,
rx`([\(\)])(?:.*${japaneseRegExp})`,
rx`(?:${japaneseRegExp}.*)([\(\)])`
];
for (const matchRegExp of matchRegExps) {
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
const { index } = match;
report(
node,
new RuleError("半角のかっこ()が使用されています。全角のかっこ()を使用してください。", {
index: index,
fix: fixer.replaceTextRange([index, index + 1], replaceSymbol(match.text))
})
);
});
}
}
};
}
Expand Down
32 changes: 31 additions & 1 deletion test/4.3.1-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/4.3.1.js";
var tester = new TextLintTester();
tester.run("4.3.1.丸かっこ()", rule, {
valid: ["クォーク(物質の素粒子)"],
valid: ["クォーク(物質の素粒子)", "(物質の素粒子)", "(npm 2.x以上をインストールしている必要があります)"],
invalid: [
{
// 半角かっこ
Expand All @@ -21,6 +21,36 @@ tester.run("4.3.1.丸かっこ()", rule, {
}
]
},
{
// 半角かっこ
text: "(物質の素粒子)",
output: "(物質の素粒子)",
errors: [
{
message: "半角のかっこ()が使用されています。全角のかっこ()を使用してください。",
column: 1
},
{
message: "半角のかっこ()が使用されています。全角のかっこ()を使用してください。",
column: 8
}
]
},
{
// 半角かっこ
text: "(npm 2.x以上をインストールしている必要があります)",
output: "(npm 2.x以上をインストールしている必要があります)",
errors: [
{
message: "半角のかっこ()が使用されています。全角のかっこ()を使用してください。",
column: 1
},
{
message: "半角のかっこ()が使用されています。全角のかっこ()を使用してください。",
column: 29
}
]
},
{
// 半角かっこ
text: "例)test",
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ A氏は「5月に新製品を発売します。」と述べました。

クォーク(物質の素粒子)

(物質の素粒子)

(npm 2.x以上をインストールしている必要があります)

例)test

半角[かっこ
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ A氏は「5月に新製品を発売します」と述べました。

クォーク(物質の素粒子)

(物質の素粒子)

(npm 2.x以上をインストールしている必要があります)

例)test

半角[かっこ
Expand Down

0 comments on commit b8cdd16

Please sign in to comment.