@parcel/validator-eslint 2.0.0-nightly.151 → 2.0.0-nightly.1511
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 +81 -50
- package/package.json +17 -7
- package/src/EslintValidator.js +60 -41
- package/.babelrc +0 -4
package/lib/EslintValidator.js
CHANGED
|
@@ -4,66 +4,97 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
function _plugin() {
|
|
8
|
+
const data = require("@parcel/plugin");
|
|
9
|
+
_plugin = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _diagnostic() {
|
|
15
|
+
const data = require("@parcel/diagnostic");
|
|
16
|
+
_diagnostic = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _eslint() {
|
|
22
|
+
const data = _interopRequireDefault(require("eslint"));
|
|
23
|
+
_eslint = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _assert() {
|
|
29
|
+
const data = _interopRequireDefault(require("assert"));
|
|
30
|
+
_assert = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
|
+
// For eslint <8.0.0
|
|
10
37
|
let cliEngine = null;
|
|
11
|
-
|
|
12
|
-
|
|
38
|
+
// For eslint >=8.0.0
|
|
39
|
+
let eslintEngine = null;
|
|
40
|
+
var _default = exports.default = new (_plugin().Validator)({
|
|
13
41
|
async validate({
|
|
14
|
-
asset
|
|
15
|
-
options
|
|
42
|
+
asset
|
|
16
43
|
}) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
44
|
+
if (!cliEngine && !eslintEngine) {
|
|
45
|
+
if (_eslint().default.ESLint) {
|
|
46
|
+
eslintEngine = new (_eslint().default.ESLint)({});
|
|
47
|
+
} else {
|
|
48
|
+
cliEngine = new (_eslint().default.CLIEngine)({});
|
|
49
|
+
}
|
|
21
50
|
}
|
|
22
|
-
|
|
23
51
|
let code = await asset.getCode();
|
|
24
|
-
let
|
|
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
|
+
}
|
|
25
62
|
let validatorResult = {
|
|
26
63
|
warnings: [],
|
|
27
64
|
errors: []
|
|
28
65
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
validatorResult.warnings.push(diagnostic);
|
|
60
|
-
}
|
|
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);
|
|
61
96
|
}
|
|
62
97
|
}
|
|
63
|
-
|
|
64
98
|
return validatorResult;
|
|
65
99
|
}
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
exports.default = _default;
|
|
100
|
+
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/validator-eslint",
|
|
3
|
-
"version": "2.0.0-nightly.
|
|
3
|
+
"version": "2.0.0-nightly.1511+2059029ee",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
+
"funding": {
|
|
9
|
+
"type": "opencollective",
|
|
10
|
+
"url": "https://opencollective.com/parcel"
|
|
11
|
+
},
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
10
14
|
"url": "https://github.com/parcel-bundler/parcel.git"
|
|
@@ -12,13 +16,19 @@
|
|
|
12
16
|
"main": "lib/EslintValidator.js",
|
|
13
17
|
"source": "src/EslintValidator.js",
|
|
14
18
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
16
|
-
"parcel": "
|
|
19
|
+
"node": ">= 12.0.0",
|
|
20
|
+
"parcel": "2.0.0-nightly.1509+2059029ee"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@parcel/plugin": "2.0.0-nightly.
|
|
20
|
-
"@parcel/utils": "2.0.0-nightly.
|
|
21
|
-
"chalk": "^
|
|
23
|
+
"@parcel/plugin": "2.0.0-nightly.1511+2059029ee",
|
|
24
|
+
"@parcel/utils": "2.0.0-nightly.1511+2059029ee",
|
|
25
|
+
"chalk": "^4.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
22
32
|
},
|
|
23
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "2059029ee91e5f03a273b0954d3e629d7375f986"
|
|
24
34
|
}
|
package/src/EslintValidator.js
CHANGED
|
@@ -1,59 +1,78 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {Validator} from '@parcel/plugin';
|
|
3
|
-
import type
|
|
3
|
+
import {type DiagnosticCodeFrame, escapeMarkdown} from '@parcel/diagnostic';
|
|
4
|
+
import eslint from 'eslint';
|
|
5
|
+
import invariant from 'assert';
|
|
4
6
|
|
|
7
|
+
// For eslint <8.0.0
|
|
5
8
|
let cliEngine = null;
|
|
9
|
+
// For eslint >=8.0.0
|
|
10
|
+
let eslintEngine = null;
|
|
6
11
|
|
|
7
|
-
export default new Validator({
|
|
8
|
-
async validate({asset
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
export default (new Validator({
|
|
13
|
+
async validate({asset}) {
|
|
14
|
+
if (!cliEngine && !eslintEngine) {
|
|
15
|
+
if (eslint.ESLint) {
|
|
16
|
+
eslintEngine = new eslint.ESLint({});
|
|
17
|
+
} else {
|
|
18
|
+
cliEngine = new eslint.CLIEngine({});
|
|
19
|
+
}
|
|
12
20
|
}
|
|
13
21
|
let code = await asset.getCode();
|
|
14
|
-
|
|
22
|
+
|
|
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
|
+
}
|
|
15
31
|
|
|
16
32
|
let validatorResult = {
|
|
17
33
|
warnings: [],
|
|
18
34
|
errors: [],
|
|
19
35
|
};
|
|
20
36
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
for (let result of results) {
|
|
38
|
+
if (!result.errorCount && !result.warningCount) continue;
|
|
39
|
+
|
|
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
|
+
};
|
|
62
|
+
|
|
63
|
+
let diagnostic = {
|
|
64
|
+
origin: '@parcel/validator-eslint',
|
|
65
|
+
message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
|
|
66
|
+
codeFrames: [codeframe],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (result.errorCount > 0) {
|
|
70
|
+
validatorResult.errors.push(diagnostic);
|
|
71
|
+
} else {
|
|
72
|
+
validatorResult.warnings.push(diagnostic);
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
|
|
57
76
|
return validatorResult;
|
|
58
77
|
},
|
|
59
|
-
});
|
|
78
|
+
}): Validator);
|
package/.babelrc
DELETED