Skip to content

Commit 49b1a26

Browse files
committed
feat(4.1.3): fixer support
1 parent ed4c3bb commit 49b1a26

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/4.1.3.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,29 @@
88
和文の句読点としては使用しません。「1.2.2 ピリオド(.)とカンマ(,)」を 参照してください
99
*/
1010
import {isUserWrittenNode} from "./util/node-util";
11-
export default function (context) {
12-
let {Syntax, RuleError, report, getSource} = context;
11+
import {matchCaptureGroupAll} from "./util/match-index";
12+
13+
function reporter(context) {
14+
let {Syntax, RuleError, report, fixer, getSource} = context;
1315
return {
1416
[Syntax.Str](node){
1517
if (!isUserWrittenNode(node, context)) {
1618
return;
1719
}
1820
let text = getSource(node);
1921
// 和文. はエラー
20-
if (/([\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])\./.test(text)) {
21-
report(node, new RuleError("和文の句読点としてはピリオドを使用しません。"));
22-
}
22+
const matchReg = /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])(\.)/g;
23+
matchCaptureGroupAll(text, matchReg).forEach(match => {
24+
const index = match.index;
25+
report(node, new RuleError("和文の句読点としてはピリオドを使用しません。", {
26+
column: index,
27+
fix: fixer.replaceTextRange([index, index + 1], "。")
28+
}));
29+
});
2330
}
2431
};
32+
}
33+
export default {
34+
linter: reporter,
35+
fixer: reporter
2536
}

test/4.1.3-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ tester.run("4.1.3. ピリオド(.)、カンマ(,)", rule, {
1313
{
1414
text: "和文の終わりがピリオド.",
1515
errors: [
16-
{message: "和文の句読点としてはピリオドを使用しません。"}
16+
{
17+
message: "和文の句読点としてはピリオドを使用しません。",
18+
column: 12
19+
}
1720
]
1821
}
1922
]

0 commit comments

Comments
 (0)