Skip to content

Commit ea6a54f

Browse files
committed
feat(3.3): 半角かっこのときに外側のスペースを許容するオプションを追加
1 parent e301ef8 commit ea6a54f

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/3.3.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ const leftBrackets = brackets.map((bracket) => {
1414
const rightBrackets = brackets.map((bracket) => {
1515
return new RegExp(bracket + "([  ])", "g");
1616
});
17-
function reporter(context) {
17+
const defaultOptions = {
18+
allowOutsideHalfParentheses: true
19+
};
20+
function reporter(context, options) {
1821
let { Syntax, RuleError, report, fixer, getSource } = context;
22+
const allowOutsideHalfParentheses =
23+
options.allowOutsideHalfParentheses ?? defaultOptions.allowOutsideHalfParentheses;
1924
return {
2025
[Syntax.Str](node) {
2126
if (!isUserWrittenNode(node, context)) {
@@ -26,6 +31,9 @@ function reporter(context) {
2631
leftBrackets.forEach((pattern) => {
2732
matchCaptureGroupAll(text, pattern).forEach((match) => {
2833
const { index } = match;
34+
if (allowOutsideHalfParentheses && text.substring(index, index + 2) === " (") {
35+
return;
36+
}
2937
report(
3038
node,
3139
new RuleError("かっこの外側、内側ともにスペースを入れません。", {
@@ -38,7 +46,10 @@ function reporter(context) {
3846
// 右にスペース
3947
rightBrackets.forEach((pattern) => {
4048
matchCaptureGroupAll(text, pattern).forEach((match) => {
41-
const { index, text } = match;
49+
const { index } = match;
50+
if (allowOutsideHalfParentheses && text.substring(index - 1, index + 1) === ") ") {
51+
return;
52+
}
4253
report(
4354
node,
4455
new RuleError("かっこの外側、内側ともにスペースを入れません。", {

test/3.3-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ tester.run("3.3.かっこ類と隣接する文字の間のスペースの有無"
77
valid: [
88
"「良い」",
99
"テスト[文章]です",
10+
"これは (test) です",
1011
`
1112
実装をみてもらうと分かりますが、JavaScriptの\`prototype\`の仕組みをそのまま利用しています。
1213
そのため、特別な実装は必要なく
@@ -50,6 +51,9 @@ tester.run("3.3.かっこ類と隣接する文字の間のスペースの有無"
5051
{
5152
text: "これはダメ (test) です",
5253
output: "これはダメ(test)です",
54+
options: {
55+
allowOutsideHalfParentheses: false
56+
},
5357
errors: [
5458
{
5559
message: "かっこの外側、内側ともにスペースを入れません。",

test/fixtures/input.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ JTF 標準
7575

7676
これは (ダメ) です
7777

78-
これはダメ (test) です
79-
8078
A氏は「5月に新製品を発売します。」と述べました。
8179

8280
従業員は約30,000人です(関連企業を含みます。)

test/fixtures/output.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ JTF標準
7575

7676
これは(ダメ)です
7777

78-
これはダメ(test)です
79-
8078
A氏は「5月に新製品を発売します」と述べました。
8179

8280
従業員は約30,000人です(関連企業を含みます)

0 commit comments

Comments
 (0)