Skip to content

Commit 5c3d8e3

Browse files
committed
feat(4.2.5): fixer support
1 parent fd8be9f commit 5c3d8e3

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/4.2.5.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@
55
数値の範囲を示す場合に使用します。
66
*/
77
import {isUserWrittenNode} from "./util/node-util";
8-
export default function (context) {
9-
let {Syntax, RuleError, report, getSource} = context;
8+
import {matchCaptureGroupAll} from "./util/match-index";
9+
10+
function reporter(context) {
11+
let {Syntax, RuleError, report, fixer, getSource} = context;
1012
return {
1113
[Syntax.Str](node){
1214
if (!isUserWrittenNode(node, context)) {
1315
return;
1416
}
15-
let text = getSource(node);
17+
const text = getSource(node);
1618
// 和文で半角の?は利用しない
17-
var matchHanQuestion = /\d(~)\d/;
18-
var index = text.search(matchHanQuestion);
19-
if (index !== -1) {
20-
return report(node, new RuleError("数値の範囲を示す場合には全角の〜を使用します。", index + 1 + 1));
21-
}
19+
const matchHanQuestion = /\d(~)\d/g;
20+
matchCaptureGroupAll(text, matchHanQuestion).forEach(match => {
21+
const {index} = match;
22+
report(node, new RuleError("数値の範囲を示す場合には全角の〜を使用します。", {
23+
column: index,
24+
fix: fixer.replaceTextRange([index, index + 1], "〜")
25+
}));
26+
});
2227
}
2328
};
29+
}
30+
export default {
31+
linter: reporter,
32+
fixer: reporter
2433
}

test/4.2.5-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ tester.run("4.2.5.波線(~)", rule, {
1111
invalid: [
1212
{
1313
text: "18~22歳まで",
14+
output: "18〜22歳まで",
1415
errors: [
1516
{
1617
message: "数値の範囲を示す場合には全角の〜を使用します。",
17-
column: 4
18+
column: 3
1819
}
1920
]
2021
}

0 commit comments

Comments
 (0)