Skip to content

Commit 0011c0a

Browse files
committed
fix(rule): always use RuleError instead of object literal
ref textlint/textlint#144
1 parent b540485 commit 0011c0a

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

src/1.1.2.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ function mixer(context) {
2929
let matchReg = /(\s*?)$/;
3030
let index = text.search(matchReg);
3131
if (index !== -1) {
32-
report(node, {
33-
message: "見出しの文末には、句点(。)を付けません。",
32+
report(node, new RuleError("見出しの文末には、句点(。)を付けません。", {
3433
index: index,
3534
fix: fixer.removeRange([index, index + 1])
36-
});
35+
}));
3736
}
3837
// TODO: いずれの場合も、すべての見出しを通して複数の文体をできるだけ混在させないことが重要です。
3938
}

src/1.2.1.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const replaceSymbol = {
2929
};
3030

3131
const reporter = (context) => {
32-
let {Syntax, report, fixer, getSource} = context;
32+
let {Syntax, RuleError, report, fixer, getSource} = context;
3333
return {
3434
[Syntax.Str](node){
3535
if (!isUserWrittenNode(node, context)) {
@@ -42,11 +42,10 @@ const reporter = (context) => {
4242
matches.forEach(match => {
4343
const symbol = replaceSymbol[match.text];
4444
const indexOfSymbol = match.index;
45-
report(node, {
46-
message: "句読点には全角の「、」と「。」を使います。和文の句読点としてピリオド(.)とカンマ(,)を使用しません。",
45+
report(node, new RuleError("句読点には全角の「、」と「。」を使います。和文の句読点としてピリオド(.)とカンマ(,)を使用しません。", {
4746
index: indexOfSymbol,
4847
fix: fixer.replaceTextRange([indexOfSymbol, indexOfSymbol + 1], symbol)
49-
});
48+
}));
5049
})
5150
}
5251
}

src/1.2.2.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const replaceSymbol = {
1313
",": ","
1414
};
1515
function report(context) {
16-
let {Syntax, fixer, report, getSource} = context;
16+
let {Syntax, RuleError, fixer, report, getSource} = context;
1717
return {
1818
[Syntax.Str](node){
1919
if (!isUserWrittenNode(node, context)) {
@@ -24,11 +24,10 @@ function report(context) {
2424
if (/[]/.test(text)) {
2525
const index = text.search(/[]/);
2626
const symbol = replaceSymbol[text[index]];
27-
report(node, {
28-
message: "全角のピリオドとカンマは使用しません。",
27+
report(node, new RuleError("全角のピリオドとカンマは使用しません。", {
2928
index: index,
3029
fix: fixer.replaceTextRange([index, index + 1], symbol)
31-
});
30+
}));
3231
}
3332
}
3433
}

src/2.1.5.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function toZenkaku(string) {
2626

2727

2828
function reporter(context) {
29-
let {Syntax, fixer, report, getSource} = context;
29+
let {Syntax, RuleError, fixer, report, getSource} = context;
3030
// 辞書ベースのカタカタ表記のチェックを行う
3131
let dictRule = prh.fixer(context, {
3232
rulePaths: [path.join(__dirname, "..", "dict", "2.1.5.yml")]
@@ -42,11 +42,10 @@ function reporter(context) {
4242
const matches = matchCaptureGroupAll(text, /([\uFF65-\uFF9F]+)/g);
4343
matches.forEach(match => {
4444
const {index, text} = match;
45-
report(node, {
46-
message: "カタカナは「全角」で表記します。",
45+
report(node, new RuleError("カタカナは「全角」で表記します。", {
4746
index: index,
4847
fix: fixer.replaceTextRange([index, index + text.length], toZenkaku(text))
49-
});
48+
}));
5049

5150
});
5251
};

src/2.1.8.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ function reporter(context) {
2323
const matchRegExp = /([-]+)/;
2424
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
2525
const {index, text} = match;
26-
report(node, {
27-
message: "算用数字は「半角」で表記します。",
26+
report(node, new RuleError("算用数字は「半角」で表記します。", {
2827
index: index,
2928
fix: fixer.replaceTextRange([index, index + text.length], toHankaku(text))
30-
})
29+
}));
3130
});
3231
}
3332
};

src/2.1.9.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ function reporter(context) {
2323
const matchRegExp = /([-]+)/;
2424
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
2525
const {index, text} = match;
26-
report(node, {
27-
message: "アルファベットは「半角」で表記します。",
26+
report(node, new RuleError("アルファベットは「半角」で表記します。", {
2827
index: index,
2928
fix: fixer.replaceTextRange([index, index + text.length], toHankaku(text))
30-
})
29+
}));
3130
});
3231
}
3332
}

0 commit comments

Comments
 (0)