Skip to content

Commit bd58825

Browse files
lilaconleeazu
authored andcommitted
feat(eslint): Add ignoreParsingErrors option (#16)
This adds the ability to ignore parsing errors without comments.
1 parent 078aba3 commit bd58825

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ Sometimes, we want to write broken JavaScript code into a JS CodeBlock for synta
3232

3333
<!-- textlint-enable eslint -->
3434

35+
To ignore ESLint parsing errors that cannot be ignored from the config file, you can use `ignoreParsingErrors`:
36+
37+
```js
38+
{
39+
"rules": {
40+
"eslint": {
41+
"configFile": "path/to/.eslintrc"
42+
"ignoreParsingErrors": true
43+
}
44+
}
45+
}
46+
```
47+
3548
## Installation
3649

3750
Install with [npm](https://www.npmjs.com/):
@@ -68,6 +81,9 @@ textlint --rule eslint README.md
6881
- `langs`: `string[]`
6982
- Default: `["js", "javascript", "node", "jsx"]`
7083
- recognize lang of CodeBlock
84+
- `ignoreParsingErrors`: `Boolean`
85+
- Default: `false`
86+
- ignore ESLint parsing errors while still reporting other ESLint errors
7187

7288
```js
7389
{
@@ -77,6 +93,8 @@ textlint --rule eslint README.md
7793
"configFile": "path/to/.eslintrc",
7894
// recognize lang of CodeBlock
7995
"langs": ["js", "javascript", "node", "jsx"]
96+
// Ignore ESLint parsing errors
97+
"ignoreParsingErrors": true
8098
}
8199
}
82100
}

src/textlint-rule-eslint.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const reporter = (context, options) => {
5353
5454
ESLint message line and column start with 1
5555
*/
56+
if (options.ignoreParsingErrors && message.message.includes("Parsing error")) {
57+
return;
58+
}
59+
5660
const prefix = message.ruleId ? `${message.ruleId}: ` : "";
5761
if (message.fix) {
5862
const paddingIndex = raw.indexOf(code);

test/textlint-rule-eslint-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ tester.run("textlint-rule-eslint", rule, {
3131
configFile: configFilePath
3232
}
3333
},
34+
{
35+
text: "```js\n\n" +
36+
"+++1+++\n" +
37+
"```",
38+
options: {
39+
configFile: configFilePath,
40+
ignoreParsingErrors: true
41+
}
42+
},
3443
],
3544
invalid: [
3645
{

0 commit comments

Comments
 (0)