-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path4.2.5.js
36 lines (35 loc) · 1.11 KB
/
4.2.5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// LICENSE : MIT
"use strict";
/*
4.2.5.波線(〜)
数値の範囲を示す場合に使用します。
*/
import { isUserWrittenNode } from "./util/node-util";
import { matchCaptureGroupAll } from "match-index";
function reporter(context) {
let { Syntax, RuleError, report, fixer, getSource } = context;
return {
[Syntax.Str](node) {
if (!isUserWrittenNode(node, context)) {
return;
}
const text = getSource(node);
// 数値の区切りに半角の~は利用しない
const matchHanQuestion = /\d(~)\d/g;
matchCaptureGroupAll(text, matchHanQuestion).forEach((match) => {
const { index } = match;
report(
node,
new RuleError("数値の範囲を示す場合には全角の〜を使用します。", {
index: index,
fix: fixer.replaceTextRange([index, index + 1], "〜")
})
);
});
}
};
}
module.exports = {
linter: reporter,
fixer: reporter
};