@valbuild/cli 0.47.0 → 0.48.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.
@@ -39,12 +39,27 @@ async function validate({
|
|
39
39
|
ignore: ["node_modules/**"],
|
40
40
|
cwd: projectRoot
|
41
41
|
});
|
42
|
-
|
43
|
-
|
42
|
+
const lintFiles = await fastGlob.glob("**/*.{js,ts}", {
|
43
|
+
ignore: ["node_modules/**"],
|
44
|
+
cwd: projectRoot
|
45
|
+
});
|
46
|
+
console.log("Running eslint...");
|
47
|
+
const eslintResults = await eslint$1.lintFiles(lintFiles);
|
44
48
|
const eslintResultsByFile = eslintResults.reduce((acc, result) => ({
|
45
49
|
...acc,
|
46
50
|
[result.filePath.replaceAll(`${projectRoot}/`, "")]: result
|
47
51
|
}), {});
|
52
|
+
let errors = 0;
|
53
|
+
eslintResults.forEach(result => {
|
54
|
+
result.messages.forEach(async m => {
|
55
|
+
if (m.messageId === "val/export-content-must-be-valid") {
|
56
|
+
errors += 1;
|
57
|
+
logEslintMessage(await fs__default["default"].readFile(result.filePath, "utf-8"), result.filePath, m);
|
58
|
+
}
|
59
|
+
});
|
60
|
+
});
|
61
|
+
console.log(errors === 0 ? picocolors__default["default"].green("✔") : picocolors__default["default"].red("✘"), "ESlint complete", valFiles.length, "files");
|
62
|
+
console.log("Validating...", valFiles.length, "files");
|
48
63
|
async function validateFile(file) {
|
49
64
|
const moduleId = `/${file}`.replace(/(\.val\.(ts|js))$/, ""); // TODO: check if this always works? (Windows?)
|
50
65
|
const start = Date.now();
|
@@ -53,20 +68,10 @@ async function validate({
|
|
53
68
|
const eslintResult = eslintResultsByFile === null || eslintResultsByFile === void 0 ? void 0 : eslintResultsByFile[file];
|
54
69
|
eslintResult === null || eslintResult === void 0 || eslintResult.messages.forEach(m => {
|
55
70
|
// display surrounding code
|
56
|
-
|
57
|
-
const line = lines[m.line - 1];
|
58
|
-
const lineBefore = lines[m.line - 2];
|
59
|
-
const lineAfter = lines[m.line];
|
60
|
-
const isError = m.severity >= 2;
|
61
|
-
console.log(isError ? picocolors__default["default"].red("✘") : picocolors__default["default"].yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${moduleId}:${m.line}:${m.column}\n`, m.message);
|
62
|
-
lineBefore && console.log(picocolors__default["default"].gray(" " + (m.line - 1) + " |"), lineBefore);
|
63
|
-
line && console.log(picocolors__default["default"].gray(" " + m.line + " |"), line);
|
64
|
-
// adds ^ below the relevant line:
|
65
|
-
line && console.log(picocolors__default["default"].gray(" " + " ".repeat(m.line.toString().length) + " |"), " ".repeat(m.column - 1) + (m.endColumn ? (isError ? picocolors__default["default"].red("^") : picocolors__default["default"].yellow("^")).repeat(m.endColumn - m.column - 1) : ""));
|
66
|
-
lineAfter && console.log(picocolors__default["default"].gray(" " + (m.line + 1) + " |"), lineAfter);
|
71
|
+
logEslintMessage(fileContent, moduleId, m);
|
67
72
|
});
|
68
73
|
if (!valModule.errors && (eslintResult === null || eslintResult === void 0 ? void 0 : eslintResult.errorCount) === 0) {
|
69
|
-
console.log(picocolors__default["default"].green("✔"), moduleId, "is valid ("
|
74
|
+
console.log(picocolors__default["default"].green("✔"), moduleId, "is valid (" + (Date.now() - start) + "ms)");
|
70
75
|
return 0;
|
71
76
|
} else {
|
72
77
|
var _eslintResultsByFile$;
|
@@ -100,12 +105,11 @@ async function validate({
|
|
100
105
|
console.log(picocolors__default["default"].red("✘"), moduleId, "is invalid:", fatalError.message);
|
101
106
|
}
|
102
107
|
} else {
|
103
|
-
console.log(picocolors__default["default"].green("✔"), moduleId, "is valid ("
|
108
|
+
console.log(picocolors__default["default"].green("✔"), moduleId, "is valid (" + (Date.now() - start) + "ms)");
|
104
109
|
}
|
105
110
|
return errors;
|
106
111
|
}
|
107
112
|
}
|
108
|
-
let errors = 0;
|
109
113
|
for (const file of valFiles) {
|
110
114
|
errors += await validateFile(file);
|
111
115
|
}
|
@@ -118,6 +122,20 @@ async function validate({
|
|
118
122
|
service.dispose();
|
119
123
|
return;
|
120
124
|
}
|
125
|
+
function logEslintMessage(fileContent, filePath, eslintMessage) {
|
126
|
+
const lines = fileContent.split("\n");
|
127
|
+
const line = lines[eslintMessage.line - 1];
|
128
|
+
const lineBefore = lines[eslintMessage.line - 2];
|
129
|
+
const lineAfter = lines[eslintMessage.line];
|
130
|
+
const isError = eslintMessage.severity >= 2;
|
131
|
+
console.log(isError ? picocolors__default["default"].red("✘") : picocolors__default["default"].yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`, eslintMessage.message);
|
132
|
+
lineBefore && console.log(picocolors__default["default"].gray(" " + (eslintMessage.line - 1) + " |"), lineBefore);
|
133
|
+
line && console.log(picocolors__default["default"].gray(" " + eslintMessage.line + " |"), line);
|
134
|
+
// adds ^ below the relevant line:
|
135
|
+
const amountOfColumns = eslintMessage.endColumn && eslintMessage.endColumn - eslintMessage.column > 0 ? eslintMessage.endColumn - eslintMessage.column : 1;
|
136
|
+
line && console.log(picocolors__default["default"].gray(" " + " ".repeat(eslintMessage.line.toString().length) + " |"), " ".repeat(eslintMessage.column - 1) + (eslintMessage.endColumn ? (isError ? picocolors__default["default"].red("^") : picocolors__default["default"].yellow("^")).repeat(amountOfColumns) : ""));
|
137
|
+
lineAfter && console.log(picocolors__default["default"].gray(" " + (eslintMessage.line + 1) + " |"), lineAfter);
|
138
|
+
}
|
121
139
|
|
122
140
|
async function main() {
|
123
141
|
const {
|
@@ -39,12 +39,27 @@ async function validate({
|
|
39
39
|
ignore: ["node_modules/**"],
|
40
40
|
cwd: projectRoot
|
41
41
|
});
|
42
|
-
|
43
|
-
|
42
|
+
const lintFiles = await fastGlob.glob("**/*.{js,ts}", {
|
43
|
+
ignore: ["node_modules/**"],
|
44
|
+
cwd: projectRoot
|
45
|
+
});
|
46
|
+
console.log("Running eslint...");
|
47
|
+
const eslintResults = await eslint$1.lintFiles(lintFiles);
|
44
48
|
const eslintResultsByFile = eslintResults.reduce((acc, result) => ({
|
45
49
|
...acc,
|
46
50
|
[result.filePath.replaceAll(`${projectRoot}/`, "")]: result
|
47
51
|
}), {});
|
52
|
+
let errors = 0;
|
53
|
+
eslintResults.forEach(result => {
|
54
|
+
result.messages.forEach(async m => {
|
55
|
+
if (m.messageId === "val/export-content-must-be-valid") {
|
56
|
+
errors += 1;
|
57
|
+
logEslintMessage(await fs__default["default"].readFile(result.filePath, "utf-8"), result.filePath, m);
|
58
|
+
}
|
59
|
+
});
|
60
|
+
});
|
61
|
+
console.log(errors === 0 ? picocolors__default["default"].green("✔") : picocolors__default["default"].red("✘"), "ESlint complete", valFiles.length, "files");
|
62
|
+
console.log("Validating...", valFiles.length, "files");
|
48
63
|
async function validateFile(file) {
|
49
64
|
const moduleId = `/${file}`.replace(/(\.val\.(ts|js))$/, ""); // TODO: check if this always works? (Windows?)
|
50
65
|
const start = Date.now();
|
@@ -53,20 +68,10 @@ async function validate({
|
|
53
68
|
const eslintResult = eslintResultsByFile === null || eslintResultsByFile === void 0 ? void 0 : eslintResultsByFile[file];
|
54
69
|
eslintResult === null || eslintResult === void 0 || eslintResult.messages.forEach(m => {
|
55
70
|
// display surrounding code
|
56
|
-
|
57
|
-
const line = lines[m.line - 1];
|
58
|
-
const lineBefore = lines[m.line - 2];
|
59
|
-
const lineAfter = lines[m.line];
|
60
|
-
const isError = m.severity >= 2;
|
61
|
-
console.log(isError ? picocolors__default["default"].red("✘") : picocolors__default["default"].yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${moduleId}:${m.line}:${m.column}\n`, m.message);
|
62
|
-
lineBefore && console.log(picocolors__default["default"].gray(" " + (m.line - 1) + " |"), lineBefore);
|
63
|
-
line && console.log(picocolors__default["default"].gray(" " + m.line + " |"), line);
|
64
|
-
// adds ^ below the relevant line:
|
65
|
-
line && console.log(picocolors__default["default"].gray(" " + " ".repeat(m.line.toString().length) + " |"), " ".repeat(m.column - 1) + (m.endColumn ? (isError ? picocolors__default["default"].red("^") : picocolors__default["default"].yellow("^")).repeat(m.endColumn - m.column - 1) : ""));
|
66
|
-
lineAfter && console.log(picocolors__default["default"].gray(" " + (m.line + 1) + " |"), lineAfter);
|
71
|
+
logEslintMessage(fileContent, moduleId, m);
|
67
72
|
});
|
68
73
|
if (!valModule.errors && (eslintResult === null || eslintResult === void 0 ? void 0 : eslintResult.errorCount) === 0) {
|
69
|
-
console.log(picocolors__default["default"].green("✔"), moduleId, "is valid ("
|
74
|
+
console.log(picocolors__default["default"].green("✔"), moduleId, "is valid (" + (Date.now() - start) + "ms)");
|
70
75
|
return 0;
|
71
76
|
} else {
|
72
77
|
var _eslintResultsByFile$;
|
@@ -100,12 +105,11 @@ async function validate({
|
|
100
105
|
console.log(picocolors__default["default"].red("✘"), moduleId, "is invalid:", fatalError.message);
|
101
106
|
}
|
102
107
|
} else {
|
103
|
-
console.log(picocolors__default["default"].green("✔"), moduleId, "is valid ("
|
108
|
+
console.log(picocolors__default["default"].green("✔"), moduleId, "is valid (" + (Date.now() - start) + "ms)");
|
104
109
|
}
|
105
110
|
return errors;
|
106
111
|
}
|
107
112
|
}
|
108
|
-
let errors = 0;
|
109
113
|
for (const file of valFiles) {
|
110
114
|
errors += await validateFile(file);
|
111
115
|
}
|
@@ -118,6 +122,20 @@ async function validate({
|
|
118
122
|
service.dispose();
|
119
123
|
return;
|
120
124
|
}
|
125
|
+
function logEslintMessage(fileContent, filePath, eslintMessage) {
|
126
|
+
const lines = fileContent.split("\n");
|
127
|
+
const line = lines[eslintMessage.line - 1];
|
128
|
+
const lineBefore = lines[eslintMessage.line - 2];
|
129
|
+
const lineAfter = lines[eslintMessage.line];
|
130
|
+
const isError = eslintMessage.severity >= 2;
|
131
|
+
console.log(isError ? picocolors__default["default"].red("✘") : picocolors__default["default"].yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`, eslintMessage.message);
|
132
|
+
lineBefore && console.log(picocolors__default["default"].gray(" " + (eslintMessage.line - 1) + " |"), lineBefore);
|
133
|
+
line && console.log(picocolors__default["default"].gray(" " + eslintMessage.line + " |"), line);
|
134
|
+
// adds ^ below the relevant line:
|
135
|
+
const amountOfColumns = eslintMessage.endColumn && eslintMessage.endColumn - eslintMessage.column > 0 ? eslintMessage.endColumn - eslintMessage.column : 1;
|
136
|
+
line && console.log(picocolors__default["default"].gray(" " + " ".repeat(eslintMessage.line.toString().length) + " |"), " ".repeat(eslintMessage.column - 1) + (eslintMessage.endColumn ? (isError ? picocolors__default["default"].red("^") : picocolors__default["default"].yellow("^")).repeat(amountOfColumns) : ""));
|
137
|
+
lineAfter && console.log(picocolors__default["default"].gray(" " + (eslintMessage.line + 1) + " |"), lineAfter);
|
138
|
+
}
|
121
139
|
|
122
140
|
async function main() {
|
123
141
|
const {
|
@@ -29,12 +29,27 @@ async function validate({
|
|
29
29
|
ignore: ["node_modules/**"],
|
30
30
|
cwd: projectRoot
|
31
31
|
});
|
32
|
-
|
33
|
-
|
32
|
+
const lintFiles = await glob("**/*.{js,ts}", {
|
33
|
+
ignore: ["node_modules/**"],
|
34
|
+
cwd: projectRoot
|
35
|
+
});
|
36
|
+
console.log("Running eslint...");
|
37
|
+
const eslintResults = await eslint.lintFiles(lintFiles);
|
34
38
|
const eslintResultsByFile = eslintResults.reduce((acc, result) => ({
|
35
39
|
...acc,
|
36
40
|
[result.filePath.replaceAll(`${projectRoot}/`, "")]: result
|
37
41
|
}), {});
|
42
|
+
let errors = 0;
|
43
|
+
eslintResults.forEach(result => {
|
44
|
+
result.messages.forEach(async m => {
|
45
|
+
if (m.messageId === "val/export-content-must-be-valid") {
|
46
|
+
errors += 1;
|
47
|
+
logEslintMessage(await fs.readFile(result.filePath, "utf-8"), result.filePath, m);
|
48
|
+
}
|
49
|
+
});
|
50
|
+
});
|
51
|
+
console.log(errors === 0 ? picocolors.green("✔") : picocolors.red("✘"), "ESlint complete", valFiles.length, "files");
|
52
|
+
console.log("Validating...", valFiles.length, "files");
|
38
53
|
async function validateFile(file) {
|
39
54
|
const moduleId = `/${file}`.replace(/(\.val\.(ts|js))$/, ""); // TODO: check if this always works? (Windows?)
|
40
55
|
const start = Date.now();
|
@@ -43,20 +58,10 @@ async function validate({
|
|
43
58
|
const eslintResult = eslintResultsByFile === null || eslintResultsByFile === void 0 ? void 0 : eslintResultsByFile[file];
|
44
59
|
eslintResult === null || eslintResult === void 0 || eslintResult.messages.forEach(m => {
|
45
60
|
// display surrounding code
|
46
|
-
|
47
|
-
const line = lines[m.line - 1];
|
48
|
-
const lineBefore = lines[m.line - 2];
|
49
|
-
const lineAfter = lines[m.line];
|
50
|
-
const isError = m.severity >= 2;
|
51
|
-
console.log(isError ? picocolors.red("✘") : picocolors.yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${moduleId}:${m.line}:${m.column}\n`, m.message);
|
52
|
-
lineBefore && console.log(picocolors.gray(" " + (m.line - 1) + " |"), lineBefore);
|
53
|
-
line && console.log(picocolors.gray(" " + m.line + " |"), line);
|
54
|
-
// adds ^ below the relevant line:
|
55
|
-
line && console.log(picocolors.gray(" " + " ".repeat(m.line.toString().length) + " |"), " ".repeat(m.column - 1) + (m.endColumn ? (isError ? picocolors.red("^") : picocolors.yellow("^")).repeat(m.endColumn - m.column - 1) : ""));
|
56
|
-
lineAfter && console.log(picocolors.gray(" " + (m.line + 1) + " |"), lineAfter);
|
61
|
+
logEslintMessage(fileContent, moduleId, m);
|
57
62
|
});
|
58
63
|
if (!valModule.errors && (eslintResult === null || eslintResult === void 0 ? void 0 : eslintResult.errorCount) === 0) {
|
59
|
-
console.log(picocolors.green("✔"), moduleId, "is valid ("
|
64
|
+
console.log(picocolors.green("✔"), moduleId, "is valid (" + (Date.now() - start) + "ms)");
|
60
65
|
return 0;
|
61
66
|
} else {
|
62
67
|
var _eslintResultsByFile$;
|
@@ -90,12 +95,11 @@ async function validate({
|
|
90
95
|
console.log(picocolors.red("✘"), moduleId, "is invalid:", fatalError.message);
|
91
96
|
}
|
92
97
|
} else {
|
93
|
-
console.log(picocolors.green("✔"), moduleId, "is valid ("
|
98
|
+
console.log(picocolors.green("✔"), moduleId, "is valid (" + (Date.now() - start) + "ms)");
|
94
99
|
}
|
95
100
|
return errors;
|
96
101
|
}
|
97
102
|
}
|
98
|
-
let errors = 0;
|
99
103
|
for (const file of valFiles) {
|
100
104
|
errors += await validateFile(file);
|
101
105
|
}
|
@@ -108,6 +112,20 @@ async function validate({
|
|
108
112
|
service.dispose();
|
109
113
|
return;
|
110
114
|
}
|
115
|
+
function logEslintMessage(fileContent, filePath, eslintMessage) {
|
116
|
+
const lines = fileContent.split("\n");
|
117
|
+
const line = lines[eslintMessage.line - 1];
|
118
|
+
const lineBefore = lines[eslintMessage.line - 2];
|
119
|
+
const lineAfter = lines[eslintMessage.line];
|
120
|
+
const isError = eslintMessage.severity >= 2;
|
121
|
+
console.log(isError ? picocolors.red("✘") : picocolors.yellow("⚠"), isError ? "Found eslint error:" : "Found eslint warning:", `${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`, eslintMessage.message);
|
122
|
+
lineBefore && console.log(picocolors.gray(" " + (eslintMessage.line - 1) + " |"), lineBefore);
|
123
|
+
line && console.log(picocolors.gray(" " + eslintMessage.line + " |"), line);
|
124
|
+
// adds ^ below the relevant line:
|
125
|
+
const amountOfColumns = eslintMessage.endColumn && eslintMessage.endColumn - eslintMessage.column > 0 ? eslintMessage.endColumn - eslintMessage.column : 1;
|
126
|
+
line && console.log(picocolors.gray(" " + " ".repeat(eslintMessage.line.toString().length) + " |"), " ".repeat(eslintMessage.column - 1) + (eslintMessage.endColumn ? (isError ? picocolors.red("^") : picocolors.yellow("^")).repeat(amountOfColumns) : ""));
|
127
|
+
lineAfter && console.log(picocolors.gray(" " + (eslintMessage.line + 1) + " |"), lineAfter);
|
128
|
+
}
|
111
129
|
|
112
130
|
async function main() {
|
113
131
|
const {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/cli",
|
3
3
|
"private": false,
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.48.0",
|
5
5
|
"description": "Val CLI tools",
|
6
6
|
"bin": {
|
7
7
|
"val": "./bin.js"
|
@@ -17,8 +17,8 @@
|
|
17
17
|
"typecheck": "tsc --noEmit"
|
18
18
|
},
|
19
19
|
"dependencies": {
|
20
|
-
"@valbuild/server": "~0.
|
21
|
-
"@valbuild/eslint-plugin": "~0.
|
20
|
+
"@valbuild/server": "~0.48.0",
|
21
|
+
"@valbuild/eslint-plugin": "~0.48.0",
|
22
22
|
"eslint": "^8.31.0",
|
23
23
|
"chalk": "^4.1.2",
|
24
24
|
"cors": "^2.8.5",
|
package/src/validate.ts
CHANGED
@@ -29,8 +29,13 @@ export async function validate({
|
|
29
29
|
ignore: ["node_modules/**"],
|
30
30
|
cwd: projectRoot,
|
31
31
|
});
|
32
|
-
|
33
|
-
const
|
32
|
+
|
33
|
+
const lintFiles = await glob("**/*.{js,ts}", {
|
34
|
+
ignore: ["node_modules/**"],
|
35
|
+
cwd: projectRoot,
|
36
|
+
});
|
37
|
+
console.log("Running eslint...");
|
38
|
+
const eslintResults = await eslint.lintFiles(lintFiles);
|
34
39
|
const eslintResultsByFile = eslintResults.reduce(
|
35
40
|
(acc, result) => ({
|
36
41
|
...acc,
|
@@ -38,6 +43,28 @@ export async function validate({
|
|
38
43
|
}),
|
39
44
|
{} as Record<string, ESLint.LintResult>
|
40
45
|
);
|
46
|
+
|
47
|
+
let errors = 0;
|
48
|
+
eslintResults.forEach((result) => {
|
49
|
+
result.messages.forEach(async (m) => {
|
50
|
+
if (m.messageId === "val/export-content-must-be-valid") {
|
51
|
+
errors += 1;
|
52
|
+
logEslintMessage(
|
53
|
+
await fs.readFile(result.filePath, "utf-8"),
|
54
|
+
result.filePath,
|
55
|
+
m
|
56
|
+
);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
});
|
60
|
+
console.log(
|
61
|
+
errors === 0 ? picocolors.green("✔") : picocolors.red("✘"),
|
62
|
+
"ESlint complete",
|
63
|
+
valFiles.length,
|
64
|
+
"files"
|
65
|
+
);
|
66
|
+
console.log("Validating...", valFiles.length, "files");
|
67
|
+
|
41
68
|
async function validateFile(file: string): Promise<number> {
|
42
69
|
const moduleId = `/${file}`.replace(/(\.val\.(ts|js))$/, "") as ModuleId; // TODO: check if this always works? (Windows?)
|
43
70
|
const start = Date.now();
|
@@ -49,41 +76,13 @@ export async function validate({
|
|
49
76
|
const eslintResult = eslintResultsByFile?.[file];
|
50
77
|
eslintResult?.messages.forEach((m) => {
|
51
78
|
// display surrounding code
|
52
|
-
|
53
|
-
const line = lines[m.line - 1];
|
54
|
-
const lineBefore = lines[m.line - 2];
|
55
|
-
const lineAfter = lines[m.line];
|
56
|
-
const isError = m.severity >= 2;
|
57
|
-
console.log(
|
58
|
-
isError ? picocolors.red("✘") : picocolors.yellow("⚠"),
|
59
|
-
isError ? "Found eslint error:" : "Found eslint warning:",
|
60
|
-
`${moduleId}:${m.line}:${m.column}\n`,
|
61
|
-
m.message
|
62
|
-
);
|
63
|
-
lineBefore &&
|
64
|
-
console.log(picocolors.gray(" " + (m.line - 1) + " |"), lineBefore);
|
65
|
-
line && console.log(picocolors.gray(" " + m.line + " |"), line);
|
66
|
-
// adds ^ below the relevant line:
|
67
|
-
line &&
|
68
|
-
console.log(
|
69
|
-
picocolors.gray(" " + " ".repeat(m.line.toString().length) + " |"),
|
70
|
-
" ".repeat(m.column - 1) +
|
71
|
-
(m.endColumn
|
72
|
-
? (isError ? picocolors.red("^") : picocolors.yellow("^")).repeat(
|
73
|
-
m.endColumn - m.column - 1
|
74
|
-
)
|
75
|
-
: "")
|
76
|
-
);
|
77
|
-
lineAfter &&
|
78
|
-
console.log(picocolors.gray(" " + (m.line + 1) + " |"), lineAfter);
|
79
|
+
logEslintMessage(fileContent, moduleId, m);
|
79
80
|
});
|
80
81
|
if (!valModule.errors && eslintResult?.errorCount === 0) {
|
81
82
|
console.log(
|
82
83
|
picocolors.green("✔"),
|
83
84
|
moduleId,
|
84
|
-
"is valid ("
|
85
|
-
Date.now() - start,
|
86
|
-
"ms)"
|
85
|
+
"is valid (" + (Date.now() - start) + "ms)"
|
87
86
|
);
|
88
87
|
return 0;
|
89
88
|
} else {
|
@@ -147,16 +146,12 @@ export async function validate({
|
|
147
146
|
console.log(
|
148
147
|
picocolors.green("✔"),
|
149
148
|
moduleId,
|
150
|
-
"is valid ("
|
151
|
-
Date.now() - start,
|
152
|
-
"ms)"
|
149
|
+
"is valid (" + (Date.now() - start) + "ms)"
|
153
150
|
);
|
154
151
|
}
|
155
152
|
return errors;
|
156
153
|
}
|
157
154
|
}
|
158
|
-
|
159
|
-
let errors = 0;
|
160
155
|
for (const file of valFiles) {
|
161
156
|
errors += await validateFile(file);
|
162
157
|
}
|
@@ -175,3 +170,51 @@ export async function validate({
|
|
175
170
|
service.dispose();
|
176
171
|
return;
|
177
172
|
}
|
173
|
+
|
174
|
+
function logEslintMessage(
|
175
|
+
fileContent: string,
|
176
|
+
filePath: string,
|
177
|
+
eslintMessage: ESLint.LintResult["messages"][number]
|
178
|
+
) {
|
179
|
+
const lines = fileContent.split("\n");
|
180
|
+
const line = lines[eslintMessage.line - 1];
|
181
|
+
const lineBefore = lines[eslintMessage.line - 2];
|
182
|
+
const lineAfter = lines[eslintMessage.line];
|
183
|
+
const isError = eslintMessage.severity >= 2;
|
184
|
+
console.log(
|
185
|
+
isError ? picocolors.red("✘") : picocolors.yellow("⚠"),
|
186
|
+
isError ? "Found eslint error:" : "Found eslint warning:",
|
187
|
+
`${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`,
|
188
|
+
eslintMessage.message
|
189
|
+
);
|
190
|
+
lineBefore &&
|
191
|
+
console.log(
|
192
|
+
picocolors.gray(" " + (eslintMessage.line - 1) + " |"),
|
193
|
+
lineBefore
|
194
|
+
);
|
195
|
+
line && console.log(picocolors.gray(" " + eslintMessage.line + " |"), line);
|
196
|
+
// adds ^ below the relevant line:
|
197
|
+
const amountOfColumns =
|
198
|
+
eslintMessage.endColumn &&
|
199
|
+
eslintMessage.endColumn - eslintMessage.column > 0
|
200
|
+
? eslintMessage.endColumn - eslintMessage.column
|
201
|
+
: 1;
|
202
|
+
|
203
|
+
line &&
|
204
|
+
console.log(
|
205
|
+
picocolors.gray(
|
206
|
+
" " + " ".repeat(eslintMessage.line.toString().length) + " |"
|
207
|
+
),
|
208
|
+
" ".repeat(eslintMessage.column - 1) +
|
209
|
+
(eslintMessage.endColumn
|
210
|
+
? (isError ? picocolors.red("^") : picocolors.yellow("^")).repeat(
|
211
|
+
amountOfColumns
|
212
|
+
)
|
213
|
+
: "")
|
214
|
+
);
|
215
|
+
lineAfter &&
|
216
|
+
console.log(
|
217
|
+
picocolors.gray(" " + (eslintMessage.line + 1) + " |"),
|
218
|
+
lineAfter
|
219
|
+
);
|
220
|
+
}
|