From b8cdd16ec0c5ae353b8c84e80a6ed084100a24a3 Mon Sep 17 00:00:00 2001 From: SUZUKI Masaya Date: Sat, 12 Sep 2020 19:23:54 +0900 Subject: [PATCH] =?UTF-8?q?fix(4.3.1):=20=E9=96=8B=E3=81=8D=E3=81=8B?= =?UTF-8?q?=E3=81=A3=E3=81=93=E3=81=A8=E9=96=89=E3=81=98=E3=81=8B=E3=81=A3?= =?UTF-8?q?=E3=81=93=E3=82=92=E4=B8=A1=E6=96=B9report=E3=81=99=E3=82=8B=20?= =?UTF-8?q?(#76)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/4.3.1.js | 28 +++++++++++++++++----------- test/4.3.1-test.js | 32 +++++++++++++++++++++++++++++++- test/fixtures/input.md | 4 ++++ test/fixtures/output.md | 4 ++++ 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/4.3.1.js b/src/4.3.1.js index 4d5f227..22b4c45 100644 --- a/src/4.3.1.js +++ b/src/4.3.1.js @@ -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)) + }) + ); + }); + } } }; } diff --git a/test/4.3.1-test.js b/test/4.3.1-test.js index 26c452b..0419712 100644 --- a/test/4.3.1-test.js +++ b/test/4.3.1-test.js @@ -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: [ { // 半角かっこ @@ -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", diff --git a/test/fixtures/input.md b/test/fixtures/input.md index 5beda86..7e1a184 100644 --- a/test/fixtures/input.md +++ b/test/fixtures/input.md @@ -85,6 +85,10 @@ A氏は「5月に新製品を発売します。」と述べました。 クォーク(物質の素粒子) +(物質の素粒子) + +(npm 2.x以上をインストールしている必要があります) + 例)test 半角[かっこ diff --git a/test/fixtures/output.md b/test/fixtures/output.md index b16a9e8..2fd11fb 100644 --- a/test/fixtures/output.md +++ b/test/fixtures/output.md @@ -85,6 +85,10 @@ A氏は「5月に新製品を発売します」と述べました。 クォーク(物質の素粒子) +(物質の素粒子) + +(npm 2.x以上をインストールしている必要があります) + 例)test 半角[かっこ