Skip to content

Commit aebbbf8

Browse files
committed
refactor(4.2.9): use matchCaptureGroupAll
1 parent d002862 commit aebbbf8

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/4.2.8.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function (context) {
2424
const {index} = match;
2525
report(node, new RuleError("原則として和文ではセミコロン(;)を使用しません。", {
2626
column: index
27-
}))
27+
}));
2828
})
2929
}
3030
};

src/4.2.9.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@ Note: ここでのダッシュはU+2012-U+2015とする
1010
https://ja.wikipedia.org/wiki/%E3%83%80%E3%83%83%E3%82%B7%E3%83%A5_%28%E8%A8%98%E5%8F%B7%29
1111
*/
1212
import {isUserWrittenNode} from "./util/node-util";
13+
import {matchCaptureGroupAll} from "./util/match-index";
14+
import regx from 'regx';
15+
import {japaneseRegExp} from "./util/regexp";
16+
const rx = regx("g");
1317
export default function (context) {
1418
let {Syntax, RuleError, report, getSource} = context;
1519
return {
1620
[Syntax.Str](node){
1721
if (!isUserWrittenNode(node, context)) {
1822
return;
1923
}
20-
let text = getSource(node);
24+
const text = getSource(node);
2125
// 和文でダッシュは使用しない
22-
var matchHanQuestion = /([\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])[\u2012-\u2015]/;
23-
var index = text.search(matchHanQuestion);
24-
if (index !== -1) {
25-
return report(node, new RuleError("原則として和文ではダッシュ(―)を使用しません。", index + 1))
26-
}
26+
const matchRegExp = rx`(?:${japaneseRegExp})([\u2012-\u2015])`;
27+
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
28+
const {index} = match;
29+
report(node, new RuleError("原則として和文ではダッシュ(―)を使用しません。", {
30+
column: index
31+
}));
32+
})
2733
}
2834
};
2935
}

0 commit comments

Comments
 (0)