Skip to content

Commit

Permalink
refactor(ja-no-space-around-parentheses): replace match-index with St…
Browse files Browse the repository at this point in the history
…ring.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
  • Loading branch information
chick-p committed Apr 27, 2024
1 parent 88afa16 commit 08e6503
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Expand Up @@ -32,7 +32,6 @@
"textlint-scripts": "^13.3.3"
},
"dependencies": {
"match-index": "^1.0.3",
"textlint-rule-helper": "^2.2.4"
}
}
21 changes: 10 additions & 11 deletions packages/textlint-rule-ja-no-space-around-parentheses/src/index.js
Expand Up @@ -5,7 +5,6 @@
かっこの外側、内側ともにスペースを入れません。
*/
import { RuleHelper } from "textlint-rule-helper";
import { matchCaptureGroupAll } from "match-index";

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

Expand All @@ -26,29 +25,29 @@ function reporter(context) {
const text = getSource(node);
// 左にスペース
leftBrackets.forEach((pattern) => {
matchCaptureGroupAll(text, pattern).forEach((match) => {
const { index } = match;
for (const match of text.matchAll(pattern)) {
const indexZeroBased = match.index;
report(
node,
new RuleError("かっこの外側、内側ともにスペースを入れません。", {
index: index,
fix: fixer.replaceTextRange([index, index + 1], "")
index: indexZeroBased,
fix: fixer.replaceTextRange([indexZeroBased, indexZeroBased + 1], "")
})
);
});
}
});
// 右にスペース
rightBrackets.forEach((pattern) => {
matchCaptureGroupAll(text, pattern).forEach((match) => {
const { index, text } = match;
for (const match of text.matchAll(pattern)) {
const indexOnebased = match.index + 1;
report(
node,
new RuleError("かっこの外側、内側ともにスペースを入れません。", {
index: index,
fix: fixer.replaceTextRange([index, index + 1], "")
index: indexOnebased,
fix: fixer.replaceTextRange([indexOnebased, indexOnebased + 1], "")
})
);
});
}
});
}
};
Expand Down

0 comments on commit 08e6503

Please sign in to comment.