Skip to content

Commit

Permalink
refactor(ja-space-after-question): replace match-index with String.pr…
Browse files Browse the repository at this point in the history
…ototype.matchAll (#73)

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

* deps(ja-space-after-question) remove match-index
  • Loading branch information
chick-p authored Apr 27, 2024
1 parent 08e6503 commit bbd0fef
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.1",
"textlint-rule-helper": "^2.2.4"
}
}
15 changes: 7 additions & 8 deletions packages/textlint-rule-ja-space-after-question/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 bbd0fef

Please sign in to comment.