Skip to content

Commit 08e6503

Browse files
authored
refactor(ja-no-space-around-parentheses): replace match-index with String.prototype.matchAll (#74)
* refactor(ja-no-space-around-parentheses): replace match-index with String.prototype.matchAll * deps(ja-no-space-around-parentheses) remove match-index
1 parent 88afa16 commit 08e6503

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

packages/textlint-rule-ja-no-space-around-parentheses/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"textlint-scripts": "^13.3.3"
3333
},
3434
"dependencies": {
35-
"match-index": "^1.0.3",
3635
"textlint-rule-helper": "^2.2.4"
3736
}
3837
}

packages/textlint-rule-ja-no-space-around-parentheses/src/index.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
かっこの外側、内側ともにスペースを入れません。
66
*/
77
import { RuleHelper } from "textlint-rule-helper";
8-
import { matchCaptureGroupAll } from "match-index";
98

109
const brackets = ["\\[", "\\]", "(", ")", "[", "]", "「", "」", "『", "』"];
1110

@@ -26,29 +25,29 @@ function reporter(context) {
2625
const text = getSource(node);
2726
// 左にスペース
2827
leftBrackets.forEach((pattern) => {
29-
matchCaptureGroupAll(text, pattern).forEach((match) => {
30-
const { index } = match;
28+
for (const match of text.matchAll(pattern)) {
29+
const indexZeroBased = match.index;
3130
report(
3231
node,
3332
new RuleError("かっこの外側、内側ともにスペースを入れません。", {
34-
index: index,
35-
fix: fixer.replaceTextRange([index, index + 1], "")
33+
index: indexZeroBased,
34+
fix: fixer.replaceTextRange([indexZeroBased, indexZeroBased + 1], "")
3635
})
3736
);
38-
});
37+
}
3938
});
4039
// 右にスペース
4140
rightBrackets.forEach((pattern) => {
42-
matchCaptureGroupAll(text, pattern).forEach((match) => {
43-
const { index, text } = match;
41+
for (const match of text.matchAll(pattern)) {
42+
const indexOnebased = match.index + 1;
4443
report(
4544
node,
4645
new RuleError("かっこの外側、内側ともにスペースを入れません。", {
47-
index: index,
48-
fix: fixer.replaceTextRange([index, index + 1], "")
46+
index: indexOnebased,
47+
fix: fixer.replaceTextRange([indexOnebased, indexOnebased + 1], "")
4948
})
5049
);
51-
});
50+
}
5251
});
5352
}
5453
};

0 commit comments

Comments
 (0)