Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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