@pi-r/eslint 0.7.3 → 0.8.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/README.md +1 -1
- package/index.js +12 -10
- package/package.json +6 -6
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -2,23 +2,25 @@
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const Types = require("@e-mc/types");
|
|
4
4
|
const Document = require("@e-mc/document");
|
|
5
|
+
const { loadESLint } = require('eslint');
|
|
5
6
|
module.exports = async function transform(context, value, options) {
|
|
6
7
|
context = options.upgrade(context, __dirname);
|
|
7
8
|
const { pathname, filename } = options;
|
|
8
9
|
const timeStamp = Date.now();
|
|
9
10
|
const baseConfig = options.toBaseConfig();
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const ESLint = (process.env.ESLINT_USE_FLAT_CONFIG === 'true' || options.version.startsWith('9.')) && !context.ESLint.version.startsWith('9.') ? await loadESLint({ useFlatConfig: true }) : (process.env.ESLINT_USE_FLAT_CONFIG === 'false' || options.version.startsWith('8.')) && !context.ESLint.version.startsWith('8.') ? await loadESLint({ useFlatConfig: false }) : context.ESLint;
|
|
12
|
+
const instance = new ESLint(baseConfig);
|
|
13
|
+
const result = await instance.lintText(value, { filePath: pathname && filename && path.join(pathname, filename) });
|
|
14
|
+
if (result.length > 0) {
|
|
13
15
|
if (baseConfig.fix) {
|
|
14
|
-
await
|
|
16
|
+
await ESLint.outputFixes(result);
|
|
15
17
|
}
|
|
16
18
|
const report = result[0];
|
|
17
19
|
if (report) {
|
|
18
|
-
if (report.messages.length) {
|
|
19
|
-
const fatal = report.messages.filter(item => item.fatal);
|
|
20
|
-
if (fatal.length) {
|
|
21
|
-
throw new Error(fatal.
|
|
20
|
+
if (report.messages.length > 0) {
|
|
21
|
+
const fatal = report.messages.filter(item => item.fatal).map(item => item.message);
|
|
22
|
+
if (fatal.length > 0) {
|
|
23
|
+
throw new Error(fatal.join('\n\n'));
|
|
22
24
|
}
|
|
23
25
|
const attr = Document.hasLogType(options.logType.STDOUT) ? 'logQueued' : 'logAppend';
|
|
24
26
|
if (process.env.ESLINT_FORMATTER_NAME) {
|
|
@@ -26,7 +28,7 @@ module.exports = async function transform(context, value, options) {
|
|
|
26
28
|
const output = await formatter.format(result);
|
|
27
29
|
options.out[attr] = [{
|
|
28
30
|
type: Types.STATUS_TYPE.INFO,
|
|
29
|
-
value: output.replace('<text>',
|
|
31
|
+
value: output.replace('<text>', 'File location: Unknown'),
|
|
30
32
|
timeStamp, duration: Date.now() - timeStamp,
|
|
31
33
|
from: 'eslint', source: process.env.ESLINT_FORMATTER_NAME
|
|
32
34
|
}];
|
|
@@ -38,7 +40,7 @@ module.exports = async function transform(context, value, options) {
|
|
|
38
40
|
column: item.column,
|
|
39
41
|
message: item.message,
|
|
40
42
|
severity: item.severity
|
|
41
|
-
})), { leadingText: 'eslint', pathname, filename, errorCount: report.errorCount, warningCount: report.warningCount, trailingText: 'https://eslint.org/docs/latest/rules', timeStamp });
|
|
43
|
+
})), { leadingText: 'eslint', pathname, filename, errorCount: [report.errorCount, report.fixableErrorCount], warningCount: [report.warningCount, report.fixableWarningCount], trailingText: 'https://eslint.org/docs/latest/rules', timeStamp });
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
else {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/eslint",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "ESLint transform function for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
-
"directory": "src/
|
|
12
|
+
"directory": "src/document/eslint"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"squared",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/document": "^0.
|
|
24
|
-
"@eslint/js": "^8.
|
|
25
|
-
"eslint": "^8.
|
|
23
|
+
"@e-mc/document": "^0.10.0",
|
|
24
|
+
"@eslint/js": "^9.8.0",
|
|
25
|
+
"eslint": "^9.8.0"
|
|
26
26
|
}
|
|
27
27
|
}
|