@pi-r/eslint 0.7.1 → 0.7.3
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/index.js +43 -15
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -1,25 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const Types = require("@e-mc/types");
|
|
2
4
|
const Document = require("@e-mc/document");
|
|
3
5
|
module.exports = async function transform(context, value, options) {
|
|
4
6
|
context = options.upgrade(context, __dirname);
|
|
5
7
|
const { pathname, filename } = options;
|
|
6
8
|
const timeStamp = Date.now();
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const baseConfig = options.toBaseConfig();
|
|
10
|
+
const instance = new context.ESLint(baseConfig);
|
|
11
|
+
const result = await instance.lintText(value);
|
|
12
|
+
if (result.length) {
|
|
13
|
+
if (baseConfig.fix) {
|
|
14
|
+
await context.ESLint.outputFixes(result);
|
|
15
|
+
}
|
|
16
|
+
const report = result[0];
|
|
17
|
+
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.map(item => item.message).join('\n\n'));
|
|
22
|
+
}
|
|
23
|
+
const attr = Document.hasLogType(options.logType.STDOUT) ? 'logQueued' : 'logAppend';
|
|
24
|
+
if (process.env.ESLINT_FORMATTER_NAME) {
|
|
25
|
+
const formatter = await instance.loadFormatter(process.env.ESLINT_FORMATTER_NAME);
|
|
26
|
+
const output = await formatter.format(result);
|
|
27
|
+
options.out[attr] = [{
|
|
28
|
+
type: Types.STATUS_TYPE.INFO,
|
|
29
|
+
value: output.replace('<text>', pathname && filename ? path.join(pathname, filename) : 'File location: Unknown'),
|
|
30
|
+
timeStamp, duration: Date.now() - timeStamp,
|
|
31
|
+
from: 'eslint', source: process.env.ESLINT_FORMATTER_NAME
|
|
32
|
+
}];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
options.out[attr] = Document.generateLintTable(report.messages.map(item => ({
|
|
36
|
+
ruleId: item.ruleId || 'unknown',
|
|
37
|
+
line: item.line,
|
|
38
|
+
column: item.column,
|
|
39
|
+
message: item.message,
|
|
40
|
+
severity: item.severity
|
|
41
|
+
})), { leadingText: 'eslint', pathname, filename, errorCount: report.errorCount, warningCount: report.warningCount, trailingText: 'https://eslint.org/docs/latest/rules', timeStamp });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
options.out.messageAppend = ` -> valid(${!report || report.errorCount || report.warningCount ? 'NO' : 'YES'})`;
|
|
46
|
+
}
|
|
47
|
+
if (baseConfig.fix && report.output) {
|
|
48
|
+
return report.output;
|
|
49
|
+
}
|
|
12
50
|
}
|
|
13
|
-
options.out[Document.hasLogType(options.logType.STDOUT) ? 'logQueued' : 'logAppend'] = Document.generateLintTable(report.messages.map(item => ({
|
|
14
|
-
ruleId: item.ruleId || 'unknown',
|
|
15
|
-
line: item.line,
|
|
16
|
-
column: item.column,
|
|
17
|
-
message: item.message,
|
|
18
|
-
severity: item.severity
|
|
19
|
-
})), { leadingText: 'eslint', pathname, filename, errorCount: report.errorCount, warningCount: report.warningCount, trailingText: 'https://eslint.org/docs/rules', timeStamp });
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
options.out.messageAppend = ` -> valid(${!report || report.errorCount || report.warningCount ? 'NO' : 'YES'})`;
|
|
23
51
|
}
|
|
24
52
|
return value;
|
|
25
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/eslint",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "eslint transform function for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/document": "^0.9.
|
|
23
|
+
"@e-mc/document": "^0.9.6",
|
|
24
|
+
"@eslint/js": "^8.57.0",
|
|
24
25
|
"eslint": "^8.57.0"
|
|
25
26
|
}
|
|
26
27
|
}
|