Skip to content

Commit 4db37d8

Browse files
committed
feat(rule): support Parsing error
1 parent 3ad5555 commit 4db37d8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/textlint-rule-eslint.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const reporter = (context, options) => {
1414
throw new Error(`Require options: { "configFile": "path/to/.eslintrc" }`);
1515
}
1616
const availableLang = options.langs || defaultOptions.langs;
17-
const filePath = context.getFilePath();
1817
const textlintRcFilePath = context.config ? context.config.configFile : null;
1918
const textlintRCDir = textlintRcFilePath ? path.dirname(textlintRcFilePath) : process.cwd();
2019
const ESLintOptions = {
@@ -43,18 +42,19 @@ const reporter = (context, options) => {
4342
4443
ESLint message line and column start with 1
4544
*/
45+
const prefix = message.ruleId ? `${message.ruleId}: ` : "";
4646
if (message.fix) {
4747
const paddingIndex = raw.indexOf(code);
4848
const fixedRange = message.fix.range;
4949
const fixedText = message.fix.text;
5050
const fixedWithPadding = [fixedRange[0] + paddingIndex, fixedRange[1] + paddingIndex];
51-
report(node, new RuleError(`${message.ruleId}: ${message.message}`, {
51+
report(node, new RuleError(`${prefix}${message.message}`, {
5252
line: message.line,
5353
column: message.column - 1,
5454
fix: fixer.replaceTextRange(fixedWithPadding, fixedText)
5555
}));
5656
} else {
57-
report(node, new RuleError(`${message.ruleId}: ${message.message}`, {
57+
report(node, new RuleError(`${prefix}${message.message}`, {
5858
line: message.line,
5959
column: message.column - 1
6060
}));

test/textlint-rule-eslint-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ tester.run("textlint-rule-eslint", rule, {
1717
}
1818
],
1919
invalid: [
20+
{
21+
text: "```js\n" +
22+
"+++1+++\n" +
23+
"```",
24+
errors: [
25+
{
26+
message: "Parsing error: Assigning to rvalue",
27+
line: 2,
28+
column: 4
29+
}
30+
],
31+
options: {
32+
configFile: configFilePath
33+
}
34+
},
2035
{
2136
text: "```js\n" +
2237
WrongCode1 + "\n" +

0 commit comments

Comments
 (0)