@parcel/validator-eslint 2.0.0-nightly.151 → 2.0.0-nightly.1514

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,66 +4,97 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _plugin = require("@parcel/plugin");
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
- var _default = new _plugin.Validator({
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
- let eslint = await options.packageManager.require('eslint', asset.filePath);
18
-
19
- if (!cliEngine) {
20
- cliEngine = new eslint.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
+ }
21
50
  }
22
-
23
51
  let code = await asset.getCode();
24
- 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
+ }
25
62
  let validatorResult = {
26
63
  warnings: [],
27
64
  errors: []
28
65
  };
29
-
30
- if (report.results.length > 0) {
31
- for (let result of report.results) {
32
- if (!result.errorCount && !result.warningCount) continue;
33
- let codeframe = {
34
- code: result.source,
35
- codeHighlights: result.messages.map(message => {
36
- return {
37
- start: {
38
- line: message.line,
39
- column: message.column
40
- },
41
- end: {
42
- line: message.endLine,
43
- column: message.endColumn
44
- },
45
- message: message.message
46
- };
47
- })
48
- };
49
- let diagnostic = {
50
- origin: '@parcel/validator-eslint',
51
- message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
52
- filePath: asset.filePath,
53
- codeFrame: codeframe
54
- };
55
-
56
- if (result.errorCount > 0) {
57
- validatorResult.errors.push(diagnostic);
58
- } else {
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.151+1af603e1",
3
+ "version": "2.0.0-nightly.1514+61a89cf80",
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": ">= 10.0.0",
16
- "parcel": "^2.0.0-alpha.1.1"
19
+ "node": ">= 12.0.0",
20
+ "parcel": "2.0.0-nightly.1512+61a89cf80"
17
21
  },
18
22
  "dependencies": {
19
- "@parcel/plugin": "2.0.0-nightly.151+1af603e1",
20
- "@parcel/utils": "2.0.0-nightly.151+1af603e1",
21
- "chalk": "^2.4.2"
23
+ "@parcel/plugin": "2.0.0-nightly.1514+61a89cf80",
24
+ "@parcel/utils": "2.0.0-nightly.1514+61a89cf80",
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": "1af603e1cfab014585ded8aec4d3dcdb7e685987"
33
+ "gitHead": "61a89cf8004a831a6c946fba44b51dab84f7639d"
24
34
  }
@@ -1,59 +1,78 @@
1
1
  // @flow
2
2
  import {Validator} from '@parcel/plugin';
3
- import type {DiagnosticCodeFrame} from '@parcel/diagnostic';
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, options}) {
9
- let eslint = await options.packageManager.require('eslint', asset.filePath);
10
- if (!cliEngine) {
11
- cliEngine = new eslint.CLIEngine({});
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
- let report = cliEngine.executeOnText(code, asset.filePath);
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
- if (report.results.length > 0) {
22
- for (let result of report.results) {
23
- if (!result.errorCount && !result.warningCount) continue;
24
-
25
- let codeframe: DiagnosticCodeFrame = {
26
- code: result.source,
27
- codeHighlights: result.messages.map(message => {
28
- return {
29
- start: {
30
- line: message.line,
31
- column: message.column,
32
- },
33
- end: {
34
- line: message.endLine,
35
- column: message.endColumn,
36
- },
37
- message: message.message,
38
- };
39
- }),
40
- };
41
-
42
- let diagnostic = {
43
- origin: '@parcel/validator-eslint',
44
- message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
45
- filePath: asset.filePath,
46
- codeFrame: codeframe,
47
- };
48
-
49
- if (result.errorCount > 0) {
50
- validatorResult.errors.push(diagnostic);
51
- } else {
52
- validatorResult.warnings.push(diagnostic);
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
@@ -1,4 +0,0 @@
1
-
2
- {
3
- "presets": ["@parcel/babel-preset"]
4
- }