Skip to content

Commit 2b2f0d7

Browse files
authored
refactor(ja-space-after-exclamation): replace match-index with String.prototype.matchAll (#72)
* refactor(ja-space-after-exclamation): replace match-index with String.prototype.matchAll * deps(ja-space-after-exclamation) remove match-index
1 parent bbd0fef commit 2b2f0d7

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

packages/textlint-rule-ja-space-after-exclamation/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-space-after-exclamation/src/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
文中に感嘆符を使用する場合はスペースを挿入しません。
77
*/
88
import { RuleHelper } from "textlint-rule-helper";
9-
import { matchCaptureGroupAll } from "match-index";
109
function reporter(context) {
1110
const { Syntax, RuleError, report, fixer, getSource } = context;
1211
const helper = new RuleHelper();
@@ -18,17 +17,17 @@ function reporter(context) {
1817
let text = getSource(node);
1918
// !の後ろは全角スペースが推奨
2019
// 半角スペースである場合
21-
const matchAfter = /( )[^\n]/;
22-
matchCaptureGroupAll(text, matchAfter).forEach((match) => {
23-
const { index } = match;
24-
return report(
20+
const matchAfter = /( )[^\n]/g;
21+
for (const match of text.matchAll(matchAfter)) {
22+
const indexOneBased = match.index + 1;
23+
report(
2524
node,
2625
new RuleError("文末に感嘆符を使用し、後に別の文が続く場合は、直後に全角スペースを挿入します。", {
27-
index: index,
28-
fix: fixer.replaceTextRange([index, index + 1], " ")
26+
index: indexOneBased,
27+
fix: fixer.replaceTextRange([indexOneBased, indexOneBased + 1], " ")
2928
})
3029
);
31-
});
30+
}
3231
}
3332
};
3433
}

0 commit comments

Comments
 (0)