Skip to content

Commit

Permalink
refactor(ja-space-after-exclamation): replace match-index with String…
Browse files Browse the repository at this point in the history
….prototype.matchAll (#72)

* refactor(ja-space-after-exclamation): replace match-index with String.prototype.matchAll

* deps(ja-space-after-exclamation) remove match-index
  • Loading branch information
chick-p committed Apr 27, 2024
1 parent bbd0fef commit 2b2f0d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"textlint-scripts": "^13.3.3"
},
"dependencies": {
"match-index": "^1.0.3",
"textlint-rule-helper": "^2.2.4"
}
}
15 changes: 7 additions & 8 deletions packages/textlint-rule-ja-space-after-exclamation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
文中に感嘆符を使用する場合はスペースを挿入しません。
*/
import { RuleHelper } from "textlint-rule-helper";
import { matchCaptureGroupAll } from "match-index";
function reporter(context) {
const { Syntax, RuleError, report, fixer, getSource } = context;
const helper = new RuleHelper();
Expand All @@ -18,17 +17,17 @@ function reporter(context) {
let text = getSource(node);
// !の後ろは全角スペースが推奨
// 半角スペースである場合
const matchAfter = /!( )[^\n]/;
matchCaptureGroupAll(text, matchAfter).forEach((match) => {
const { index } = match;
return report(
const matchAfter = /!( )[^\n]/g;
for (const match of text.matchAll(matchAfter)) {
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 2b2f0d7

Please sign in to comment.