Skip to content

Commit 89b84e5

Browse files
authored
refactor(ja-no-space-between-full-width): replace match-index with String.prototype.matchAll (#75)
* refactor(ja-no-space-between-full-width): replace match-index with String.prototype.matchAll * deps(ja-no-space-between-full-width) remove match-index
1 parent fadd6dd commit 89b84e5

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

packages/textlint-rule-ja-no-space-between-full-width/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
"regx": "^1.0.4",
3736
"textlint-rule-helper": "^2.2.4"
3837
}

packages/textlint-rule-ja-no-space-between-full-width/src/index.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
ただしカタカナ複合語の場合を除きます。
77
*/
88
import { RuleHelper } from "textlint-rule-helper";
9-
import { matchAll } from "match-index";
109
import regx from "regx";
1110
const rx = regx("g");
1211
const japaneseRegExp =
@@ -24,23 +23,21 @@ function reporter(context) {
2423
// 全角同士の間は半角スペースを入れない
2524
const matchReg = rx`${japaneseRegExp}( )${japaneseRegExp}`;
2625
const katakakana = /[-]( )[-]/;
27-
matchAll(text, matchReg).forEach((match) => {
28-
const { input, captureGroups } = match;
26+
for (const match of text.matchAll(matchReg)) {
27+
const input = match[1];
2928
// ただしカタカナ複合語の場合を除きます。
3029
if (katakakana.test(input)) {
3130
return;
3231
}
33-
captureGroups.forEach((captureGroup) => {
34-
const index = captureGroup.index;
35-
report(
36-
node,
37-
new RuleError("原則として、全角文字どうしの間にスペースを入れません。", {
38-
index: index,
39-
fix: fixer.replaceTextRange([index, index + 1], "")
40-
})
41-
);
42-
});
43-
});
32+
const indexOneBased = match.index + 1;
33+
report(
34+
node,
35+
new RuleError("原則として、全角文字どうしの間にスペースを入れません。", {
36+
index: indexOneBased,
37+
fix: fixer.replaceTextRange([indexOneBased, indexOneBased + 1], "")
38+
})
39+
);
40+
}
4441
}
4542
};
4643
}

0 commit comments

Comments
 (0)