Skip to content

Commit d002862

Browse files
committed
refactor(4.2.8): use matchCaptureGroupAll
1 parent 8f8fb38 commit d002862

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/4.2.8.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,26 @@
66
原文でセミコロンが使われている場合も、和文では使用しません。
77
*/
88
import {isUserWrittenNode} from "./util/node-util";
9+
import {matchCaptureGroupAll} from "./util/match-index";
10+
import regx from 'regx';
11+
import {japaneseRegExp} from "./util/regexp";
12+
const rx = regx("g");
913
export default function (context) {
1014
let {Syntax, RuleError, report, getSource} = context;
1115
return {
1216
[Syntax.Str](node){
1317
if (!isUserWrittenNode(node, context)) {
1418
return;
1519
}
16-
let text = getSource(node);
20+
const text = getSource(node);
1721
// "和文;" というような半角;は使用しない
18-
var matchHanQuestion = /([\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--]);/;
19-
var index = text.search(matchHanQuestion);
20-
if (index !== -1) {
21-
return report(node, new RuleError("原則として和文ではセミコロン(;)を使用しません。", index + 1))
22-
}
22+
const matchRegExp = rx`(?:${japaneseRegExp})(;)`;
23+
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
24+
const {index} = match;
25+
report(node, new RuleError("原則として和文ではセミコロン(;)を使用しません。", {
26+
column: index
27+
}))
28+
})
2329
}
2430
};
2531
}

0 commit comments

Comments
 (0)