@parcel/validator-eslint 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/EslintValidator.js +50 -37
- package/package.json +10 -9
- package/src/EslintValidator.js +50 -39
package/lib/EslintValidator.js
CHANGED
|
@@ -32,54 +32,67 @@ function _assert() {
|
|
|
32
32
|
};
|
|
33
33
|
return data;
|
|
34
34
|
}
|
|
35
|
-
function _interopRequireDefault(
|
|
35
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
36
|
+
// For eslint <8.0.0
|
|
36
37
|
let cliEngine = null;
|
|
38
|
+
// For eslint >=8.0.0
|
|
39
|
+
let eslintEngine = null;
|
|
37
40
|
var _default = exports.default = new (_plugin().Validator)({
|
|
38
41
|
async validate({
|
|
39
42
|
asset
|
|
40
43
|
}) {
|
|
41
|
-
if (!cliEngine) {
|
|
42
|
-
|
|
44
|
+
if (!cliEngine && !eslintEngine) {
|
|
45
|
+
if (_eslint().default.ESLint) {
|
|
46
|
+
eslintEngine = new (_eslint().default.ESLint)({});
|
|
47
|
+
} else {
|
|
48
|
+
cliEngine = new (_eslint().default.CLIEngine)({});
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
let code = await asset.getCode();
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
let results;
|
|
53
|
+
if (cliEngine != null) {
|
|
54
|
+
results = cliEngine.executeOnText(code, asset.filePath).results;
|
|
55
|
+
} else if (eslintEngine != null) {
|
|
56
|
+
results = await eslintEngine.lintText(code, {
|
|
57
|
+
filePath: asset.filePath
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
(0, _assert().default)(false);
|
|
61
|
+
}
|
|
47
62
|
let validatorResult = {
|
|
48
63
|
warnings: [],
|
|
49
64
|
errors: []
|
|
50
65
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
validatorResult.warnings.push(diagnostic);
|
|
82
|
-
}
|
|
66
|
+
for (let result of results) {
|
|
67
|
+
if (!result.errorCount && !result.warningCount) continue;
|
|
68
|
+
let codeframe = {
|
|
69
|
+
filePath: asset.filePath,
|
|
70
|
+
code: result.source,
|
|
71
|
+
codeHighlights: result.messages.map(message => {
|
|
72
|
+
let start = {
|
|
73
|
+
line: message.line,
|
|
74
|
+
column: message.column
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
start,
|
|
78
|
+
// Parse errors have no ending
|
|
79
|
+
end: message.endLine != null ? {
|
|
80
|
+
line: message.endLine,
|
|
81
|
+
column: message.endColumn - 1
|
|
82
|
+
} : start,
|
|
83
|
+
message: (0, _diagnostic().escapeMarkdown)(message.message)
|
|
84
|
+
};
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
let diagnostic = {
|
|
88
|
+
origin: '@parcel/validator-eslint',
|
|
89
|
+
message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
|
|
90
|
+
codeFrames: [codeframe]
|
|
91
|
+
};
|
|
92
|
+
if (result.errorCount > 0) {
|
|
93
|
+
validatorResult.errors.push(diagnostic);
|
|
94
|
+
} else {
|
|
95
|
+
validatorResult.warnings.push(diagnostic);
|
|
83
96
|
}
|
|
84
97
|
}
|
|
85
98
|
return validatorResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/validator-eslint",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,19 +16,20 @@
|
|
|
16
16
|
"main": "lib/EslintValidator.js",
|
|
17
17
|
"source": "src/EslintValidator.js",
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
20
|
-
"parcel": "^2.
|
|
19
|
+
"node": ">= 16.0.0",
|
|
20
|
+
"parcel": "^2.13.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/
|
|
24
|
-
"@parcel/
|
|
25
|
-
"
|
|
23
|
+
"@parcel/diagnostic": "2.13.0",
|
|
24
|
+
"@parcel/plugin": "2.13.0",
|
|
25
|
+
"@parcel/utils": "2.13.0",
|
|
26
|
+
"chalk": "^4.1.2"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"eslint": "^6.0.0 || ^7.0.0"
|
|
29
|
+
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
|
-
"eslint": "^6.0.0 || ^7.0.0"
|
|
32
|
+
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "a53f8f3ba1025c7ea8653e9719e0a61ef9717079"
|
|
34
35
|
}
|
package/src/EslintValidator.js
CHANGED
|
@@ -4,61 +4,72 @@ import {type DiagnosticCodeFrame, escapeMarkdown} from '@parcel/diagnostic';
|
|
|
4
4
|
import eslint from 'eslint';
|
|
5
5
|
import invariant from 'assert';
|
|
6
6
|
|
|
7
|
+
// For eslint <8.0.0
|
|
7
8
|
let cliEngine = null;
|
|
9
|
+
// For eslint >=8.0.0
|
|
10
|
+
let eslintEngine = null;
|
|
8
11
|
|
|
9
12
|
export default (new Validator({
|
|
10
13
|
async validate({asset}) {
|
|
11
|
-
if (!cliEngine) {
|
|
12
|
-
|
|
14
|
+
if (!cliEngine && !eslintEngine) {
|
|
15
|
+
if (eslint.ESLint) {
|
|
16
|
+
eslintEngine = new eslint.ESLint({});
|
|
17
|
+
} else {
|
|
18
|
+
cliEngine = new eslint.CLIEngine({});
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
21
|
let code = await asset.getCode();
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
let results;
|
|
24
|
+
if (cliEngine != null) {
|
|
25
|
+
results = cliEngine.executeOnText(code, asset.filePath).results;
|
|
26
|
+
} else if (eslintEngine != null) {
|
|
27
|
+
results = await eslintEngine.lintText(code, {filePath: asset.filePath});
|
|
28
|
+
} else {
|
|
29
|
+
invariant(false);
|
|
30
|
+
}
|
|
18
31
|
|
|
19
32
|
let validatorResult = {
|
|
20
33
|
warnings: [],
|
|
21
34
|
errors: [],
|
|
22
35
|
};
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!result.errorCount && !result.warningCount) continue;
|
|
37
|
+
for (let result of results) {
|
|
38
|
+
if (!result.errorCount && !result.warningCount) continue;
|
|
27
39
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
let codeframe: DiagnosticCodeFrame = {
|
|
41
|
+
filePath: asset.filePath,
|
|
42
|
+
code: result.source,
|
|
43
|
+
codeHighlights: result.messages.map(message => {
|
|
44
|
+
let start = {
|
|
45
|
+
line: message.line,
|
|
46
|
+
column: message.column,
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
start,
|
|
50
|
+
// Parse errors have no ending
|
|
51
|
+
end:
|
|
52
|
+
message.endLine != null
|
|
53
|
+
? {
|
|
54
|
+
line: message.endLine,
|
|
55
|
+
column: message.endColumn - 1,
|
|
56
|
+
}
|
|
57
|
+
: start,
|
|
58
|
+
message: escapeMarkdown(message.message),
|
|
59
|
+
};
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
50
62
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
let diagnostic = {
|
|
64
|
+
origin: '@parcel/validator-eslint',
|
|
65
|
+
message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
|
|
66
|
+
codeFrames: [codeframe],
|
|
67
|
+
};
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
69
|
+
if (result.errorCount > 0) {
|
|
70
|
+
validatorResult.errors.push(diagnostic);
|
|
71
|
+
} else {
|
|
72
|
+
validatorResult.warnings.push(diagnostic);
|
|
62
73
|
}
|
|
63
74
|
}
|
|
64
75
|
|