@parcel/validator-eslint 2.0.0-beta.3.1 → 2.0.0-dev.1510

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.
@@ -4,106 +4,97 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _plugin() {
9
8
  const data = require("@parcel/plugin");
10
-
11
9
  _plugin = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _diagnostic() {
19
15
  const data = require("@parcel/diagnostic");
20
-
21
16
  _diagnostic = function () {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function _eslint() {
29
22
  const data = _interopRequireDefault(require("eslint"));
30
-
31
23
  _eslint = function () {
32
24
  return data;
33
25
  };
34
-
35
26
  return data;
36
27
  }
37
-
38
28
  function _assert() {
39
29
  const data = _interopRequireDefault(require("assert"));
40
-
41
30
  _assert = function () {
42
31
  return data;
43
32
  };
44
-
45
33
  return data;
46
34
  }
47
-
48
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
49
-
36
+ // For eslint <8.0.0
50
37
  let cliEngine = null;
51
-
52
- var _default = new (_plugin().Validator)({
38
+ // For eslint >=8.0.0
39
+ let eslintEngine = null;
40
+ var _default = exports.default = new (_plugin().Validator)({
53
41
  async validate({
54
42
  asset
55
43
  }) {
56
- if (!cliEngine) {
57
- cliEngine = new (_eslint().default.CLIEngine)({});
44
+ if (!cliEngine && !eslintEngine) {
45
+ if (_eslint().default.ESLint) {
46
+ eslintEngine = new (_eslint().default.ESLint)({});
47
+ } else {
48
+ cliEngine = new (_eslint().default.CLIEngine)({});
49
+ }
58
50
  }
59
-
60
51
  let code = await asset.getCode();
61
- (0, _assert().default)(cliEngine != null);
62
- let report = cliEngine.executeOnText(code, asset.filePath);
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
+ }
63
62
  let validatorResult = {
64
63
  warnings: [],
65
64
  errors: []
66
65
  };
67
-
68
- if (report.results.length > 0) {
69
- for (let result of report.results) {
70
- if (!result.errorCount && !result.warningCount) continue;
71
- let codeframe = {
72
- code: result.source,
73
- codeHighlights: result.messages.map(message => {
74
- let start = {
75
- line: message.line,
76
- column: message.column
77
- };
78
- return {
79
- start,
80
- // Parse errors have no ending
81
- end: message.endLine != null ? {
82
- line: message.endLine,
83
- column: message.endColumn
84
- } : start,
85
- message: (0, _diagnostic().escapeMarkdown)(message.message)
86
- };
87
- })
88
- };
89
- let diagnostic = {
90
- origin: '@parcel/validator-eslint',
91
- message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
92
- filePath: asset.filePath,
93
- codeFrame: codeframe
94
- };
95
-
96
- if (result.errorCount > 0) {
97
- validatorResult.errors.push(diagnostic);
98
- } else {
99
- validatorResult.warnings.push(diagnostic);
100
- }
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);
101
96
  }
102
97
  }
103
-
104
98
  return validatorResult;
105
99
  }
106
-
107
- });
108
-
109
- exports.default = _default;
100
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/validator-eslint",
3
- "version": "2.0.0-beta.3.1",
3
+ "version": "2.0.0-dev.1510+a9bb85adf",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,18 +17,18 @@
17
17
  "source": "src/EslintValidator.js",
18
18
  "engines": {
19
19
  "node": ">= 12.0.0",
20
- "parcel": "^2.0.0-beta.1"
20
+ "parcel": "^2.0.0-dev.1508+a9bb85adf"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/plugin": "2.0.0-beta.3.1",
24
- "@parcel/utils": "2.0.0-beta.3.1",
23
+ "@parcel/plugin": "2.0.0-dev.1510+a9bb85adf",
24
+ "@parcel/utils": "2.0.0-dev.1510+a9bb85adf",
25
25
  "chalk": "^4.1.0"
26
26
  },
27
27
  "devDependencies": {
28
- "eslint": "^6.0.0"
28
+ "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "eslint": "^6.0.0"
31
+ "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
32
32
  },
33
- "gitHead": "daece49d003ba804bbdaa3a7ed3d6aaf446f166d"
33
+ "gitHead": "a9bb85adf8f3b38631e178b3aacaa30c78696e36"
34
34
  }
@@ -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
- cliEngine = new eslint.CLIEngine({});
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
- invariant(cliEngine != null);
17
- let report = cliEngine.executeOnText(code, asset.filePath);
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
- if (report.results.length > 0) {
25
- for (let result of report.results) {
26
- if (!result.errorCount && !result.warningCount) continue;
37
+ for (let result of results) {
38
+ if (!result.errorCount && !result.warningCount) continue;
27
39
 
28
- let codeframe: DiagnosticCodeFrame = {
29
- code: result.source,
30
- codeHighlights: result.messages.map(message => {
31
- let start = {
32
- line: message.line,
33
- column: message.column,
34
- };
35
- return {
36
- start,
37
- // Parse errors have no ending
38
- end:
39
- message.endLine != null
40
- ? {
41
- line: message.endLine,
42
- column: message.endColumn,
43
- }
44
- : start,
45
- message: escapeMarkdown(message.message),
46
- };
47
- }),
48
- };
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
+ };
49
62
 
50
- let diagnostic = {
51
- origin: '@parcel/validator-eslint',
52
- message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
53
- filePath: asset.filePath,
54
- codeFrame: codeframe,
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
- if (result.errorCount > 0) {
58
- validatorResult.errors.push(diagnostic);
59
- } else {
60
- validatorResult.warnings.push(diagnostic);
61
- }
69
+ if (result.errorCount > 0) {
70
+ validatorResult.errors.push(diagnostic);
71
+ } else {
72
+ validatorResult.warnings.push(diagnostic);
62
73
  }
63
74
  }
64
75
 
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@parcel/babel-preset"]
3
- }