@jentic/arazzo-validator 1.0.0-alpha.24 → 1.0.0-alpha.26
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/CHANGELOG.md +12 -0
- package/package.json +4 -5
- package/src/cli/formatters/codeframe.cjs +92 -0
- package/src/cli/formatters/codeframe.mjs +87 -0
- package/src/cli/formatters/github-actions.cjs +47 -0
- package/src/cli/formatters/github-actions.mjs +43 -0
- package/src/cli/formatters/index.cjs +12 -0
- package/src/cli/formatters/index.mjs +4 -0
- package/src/cli/formatters/json.cjs +20 -0
- package/src/cli/formatters/json.mjs +16 -0
- package/src/cli/formatters/stylish.cjs +76 -0
- package/src/cli/formatters/stylish.mjs +69 -0
- package/src/cli/index.cjs +159 -0
- package/src/cli/index.mjs +154 -0
- package/src/config/arazzo/arazzo/lint/index.cjs +8 -0
- package/src/config/arazzo/arazzo/lint/index.mjs +3 -0
- package/src/config/arazzo/arazzo/lint/value--pattern-1-0-X.cjs +30 -0
- package/src/config/arazzo/arazzo/lint/value--pattern-1-0-X.mjs +25 -0
- package/src/config/arazzo/arazzo/meta.cjs +10 -0
- package/src/config/arazzo/arazzo/meta.mjs +5 -0
- package/src/config/arazzo/arazzo-specification-1/lint/allowed-fields.cjs +18 -0
- package/src/config/arazzo/arazzo-specification-1/lint/allowed-fields.mjs +14 -0
- package/src/config/arazzo/arazzo-specification-1/lint/index.cjs +11 -0
- package/src/config/arazzo/arazzo-specification-1/lint/index.mjs +6 -0
- package/src/config/arazzo/arazzo-specification-1/lint/info--required.cjs +27 -0
- package/src/config/arazzo/arazzo-specification-1/lint/info--required.mjs +22 -0
- package/src/config/arazzo/arazzo-specification-1/lint/info--type.cjs +21 -0
- package/src/config/arazzo/arazzo-specification-1/lint/info--type.mjs +16 -0
- package/src/config/arazzo/arazzo-specification-1/lint/required-fields.cjs +44 -0
- package/src/config/arazzo/arazzo-specification-1/lint/required-fields.mjs +39 -0
- package/src/config/arazzo/arazzo-specification-1/meta.cjs +10 -0
- package/src/config/arazzo/arazzo-specification-1/meta.mjs +5 -0
- package/src/config/arazzo/config.cjs +23 -0
- package/src/config/arazzo/config.mjs +18 -0
- package/src/config/arazzo/target-specs.cjs +32 -0
- package/src/config/arazzo/target-specs.mjs +28 -0
- package/src/config/codes.cjs +17 -0
- package/src/config/codes.mjs +13 -0
- package/src/config/config.cjs +19 -0
- package/src/config/config.mjs +14 -0
- package/src/document.cjs +32 -0
- package/src/document.mjs +28 -0
- package/src/index.cjs +18 -0
- package/src/index.mjs +5 -0
- package/src/validators/json-schema-provider.cjs +25 -0
- package/src/validators/json-schema-provider.mjs +21 -0
- package/src/validators/validate-uri.cjs +72 -0
- package/src/validators/validate-uri.mjs +67 -0
- package/src/validators/validate.cjs +85 -0
- package/src/validators/validate.mjs +80 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-alpha.26](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.25...v1.0.0-alpha.26) (2026-03-11)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **parser:** add consistent naming for exported options ([#134](https://github.com/jentic/jentic-arazzo-tools/issues/134)) ([cfa2a54](https://github.com/jentic/jentic-arazzo-tools/commit/cfa2a54fad0189da7d26ca4c76b63bfcc3c60eec))
|
|
11
|
+
|
|
12
|
+
# [1.0.0-alpha.25](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.24...v1.0.0-alpha.25) (2026-03-11)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **release:** fix issue in lerna not publishing _.cjs|_.mjs files ([8982184](https://github.com/jentic/jentic-arazzo-tools/commit/8982184ddae167b6f2a772114f9a9321f3b67d14))
|
|
17
|
+
|
|
6
18
|
# [1.0.0-alpha.24](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.23...v1.0.0-alpha.24) (2026-03-11)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @jentic/arazzo-validator
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jentic/arazzo-validator",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.26",
|
|
4
4
|
"description": "Validator & Linter for Arazzo Documents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arazzo",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"license": "Apache-2.0",
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
59
|
-
"@jentic/arazzo-parser": "1.0.0-alpha.
|
|
59
|
+
"@jentic/arazzo-parser": "1.0.0-alpha.26",
|
|
60
60
|
"@speclynx/apidom-ls": "^2.4.2",
|
|
61
61
|
"@speclynx/apidom-ns-arazzo-1": "^4.0.3",
|
|
62
62
|
"@speclynx/apidom-reference": "^4.0.3",
|
|
@@ -69,8 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"files": [
|
|
71
71
|
"bin/",
|
|
72
|
-
"src
|
|
73
|
-
"src/**/*.cjs",
|
|
72
|
+
"src/",
|
|
74
73
|
"dist/",
|
|
75
74
|
"types/arazzo-validator.d.ts",
|
|
76
75
|
"LICENSE",
|
|
@@ -78,5 +77,5 @@
|
|
|
78
77
|
"README.md",
|
|
79
78
|
"CHANGELOG.md"
|
|
80
79
|
],
|
|
81
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "fa8637a6e4ad80e321a5808da52e4346a1a1f0d7"
|
|
82
81
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.formatCodeframe = formatCodeframe;
|
|
6
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
7
|
+
var _vscodeLanguageserverTypes = require("vscode-languageserver-types");
|
|
8
|
+
var _stylish = require("./stylish.cjs");
|
|
9
|
+
function formatCodeSnippet(sourceLines, diagnostic, gutterWidth) {
|
|
10
|
+
const lines = [];
|
|
11
|
+
const startLine = diagnostic.range.start.line;
|
|
12
|
+
const startChar = diagnostic.range.start.character;
|
|
13
|
+
const endChar = diagnostic.range.end.character;
|
|
14
|
+
|
|
15
|
+
// show context: 1 line before, problem line, 1 line after
|
|
16
|
+
const contextStart = Math.max(0, startLine - 1);
|
|
17
|
+
const contextEnd = Math.min(sourceLines.length - 1, startLine + 1);
|
|
18
|
+
for (let i = contextStart; i <= contextEnd; i++) {
|
|
19
|
+
const lineNum = i + 1;
|
|
20
|
+
const gutter = _chalk.default.dim(`${String(lineNum).padStart(gutterWidth)} |`);
|
|
21
|
+
const sourceLine = sourceLines[i] || '';
|
|
22
|
+
lines.push(`${gutter} ${sourceLine}`);
|
|
23
|
+
|
|
24
|
+
// add caret line under the problem line
|
|
25
|
+
if (i === startLine) {
|
|
26
|
+
const caretGutter = _chalk.default.dim(`${' '.repeat(gutterWidth)} |`);
|
|
27
|
+
const caretLength = Math.max(1, endChar - startChar);
|
|
28
|
+
const carets = _chalk.default.red('^'.repeat(caretLength));
|
|
29
|
+
lines.push(`${caretGutter} ${' '.repeat(startChar)}${carets}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return lines;
|
|
33
|
+
}
|
|
34
|
+
function formatCodeframe(filePath, diagnostics, options = {}) {
|
|
35
|
+
const {
|
|
36
|
+
maxProblems,
|
|
37
|
+
sourceContent
|
|
38
|
+
} = options;
|
|
39
|
+
const limitedDiagnostics = maxProblems ? diagnostics.slice(0, maxProblems) : diagnostics;
|
|
40
|
+
if (limitedDiagnostics.length === 0) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
const sourceLines = sourceContent?.split('\n');
|
|
44
|
+
const maxLineNum = sourceLines?.length ?? 0;
|
|
45
|
+
const gutterWidth = Math.max(String(maxLineNum).length, 2);
|
|
46
|
+
|
|
47
|
+
// calculate max widths for alignment
|
|
48
|
+
const maxLocationLength = Math.max(...limitedDiagnostics.map(d => (0, _stylish.formatLocation)(d).length));
|
|
49
|
+
const maxCodeLength = Math.max(...limitedDiagnostics.map(d => d.code ? String(d.code).length : 0));
|
|
50
|
+
const lines = [];
|
|
51
|
+
|
|
52
|
+
// file path header
|
|
53
|
+
lines.push(_chalk.default.bold(filePath));
|
|
54
|
+
|
|
55
|
+
// diagnostics
|
|
56
|
+
for (const diagnostic of limitedDiagnostics) {
|
|
57
|
+
const locationStr = (0, _stylish.formatLocation)(diagnostic);
|
|
58
|
+
const location = _chalk.default.dim(locationStr.padEnd(maxLocationLength));
|
|
59
|
+
const severity = (0, _stylish.severityToString)(diagnostic.severity);
|
|
60
|
+
const codeStr = diagnostic.code ? String(diagnostic.code) : '';
|
|
61
|
+
const code = codeStr ? _chalk.default.cyan(codeStr.padEnd(maxCodeLength)) : ' '.repeat(maxCodeLength);
|
|
62
|
+
const message = diagnostic.message;
|
|
63
|
+
lines.push(` ${location} ${severity} ${code} ${message}`);
|
|
64
|
+
|
|
65
|
+
// add code snippet if source content is available
|
|
66
|
+
if (sourceLines) {
|
|
67
|
+
lines.push('');
|
|
68
|
+
lines.push(...formatCodeSnippet(sourceLines, diagnostic, gutterWidth));
|
|
69
|
+
lines.push('');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// summary
|
|
74
|
+
const errorCount = limitedDiagnostics.filter(d => d.severity === _vscodeLanguageserverTypes.DiagnosticSeverity.Error).length;
|
|
75
|
+
const warningCount = limitedDiagnostics.filter(d => d.severity === _vscodeLanguageserverTypes.DiagnosticSeverity.Warning).length;
|
|
76
|
+
const infoCount = limitedDiagnostics.filter(d => d.severity === _vscodeLanguageserverTypes.DiagnosticSeverity.Information).length;
|
|
77
|
+
const hintCount = limitedDiagnostics.filter(d => d.severity === _vscodeLanguageserverTypes.DiagnosticSeverity.Hint).length;
|
|
78
|
+
lines.push('');
|
|
79
|
+
const parts = [];
|
|
80
|
+
if (errorCount > 0) parts.push(`${errorCount} ${errorCount === 1 ? 'error' : 'errors'}`);
|
|
81
|
+
if (warningCount > 0) parts.push(`${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}`);
|
|
82
|
+
if (infoCount > 0) parts.push(`${infoCount} ${infoCount === 1 ? 'info' : 'infos'}`);
|
|
83
|
+
if (hintCount > 0) parts.push(`${hintCount} ${hintCount === 1 ? 'hint' : 'hints'}`);
|
|
84
|
+
const symbol = errorCount > 0 ? _chalk.default.red('✖') : _chalk.default.yellow('⚠');
|
|
85
|
+
const problemText = limitedDiagnostics.length === 1 ? 'problem' : 'problems';
|
|
86
|
+
const breakdown = parts.length > 0 ? ` (${parts.join(', ')})` : '';
|
|
87
|
+
lines.push(`${symbol} ${limitedDiagnostics.length} ${problemText}${breakdown}`);
|
|
88
|
+
if (maxProblems && diagnostics.length > maxProblems) {
|
|
89
|
+
lines.push(_chalk.default.dim(`(showing ${maxProblems} of ${diagnostics.length} problems)`));
|
|
90
|
+
}
|
|
91
|
+
return lines.join('\n');
|
|
92
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { DiagnosticSeverity } from 'vscode-languageserver-types';
|
|
3
|
+
import { severityToString, formatLocation } from "./stylish.mjs";
|
|
4
|
+
function formatCodeSnippet(sourceLines, diagnostic, gutterWidth) {
|
|
5
|
+
const lines = [];
|
|
6
|
+
const startLine = diagnostic.range.start.line;
|
|
7
|
+
const startChar = diagnostic.range.start.character;
|
|
8
|
+
const endChar = diagnostic.range.end.character;
|
|
9
|
+
|
|
10
|
+
// show context: 1 line before, problem line, 1 line after
|
|
11
|
+
const contextStart = Math.max(0, startLine - 1);
|
|
12
|
+
const contextEnd = Math.min(sourceLines.length - 1, startLine + 1);
|
|
13
|
+
for (let i = contextStart; i <= contextEnd; i++) {
|
|
14
|
+
const lineNum = i + 1;
|
|
15
|
+
const gutter = chalk.dim(`${String(lineNum).padStart(gutterWidth)} |`);
|
|
16
|
+
const sourceLine = sourceLines[i] || '';
|
|
17
|
+
lines.push(`${gutter} ${sourceLine}`);
|
|
18
|
+
|
|
19
|
+
// add caret line under the problem line
|
|
20
|
+
if (i === startLine) {
|
|
21
|
+
const caretGutter = chalk.dim(`${' '.repeat(gutterWidth)} |`);
|
|
22
|
+
const caretLength = Math.max(1, endChar - startChar);
|
|
23
|
+
const carets = chalk.red('^'.repeat(caretLength));
|
|
24
|
+
lines.push(`${caretGutter} ${' '.repeat(startChar)}${carets}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return lines;
|
|
28
|
+
}
|
|
29
|
+
export function formatCodeframe(filePath, diagnostics, options = {}) {
|
|
30
|
+
const {
|
|
31
|
+
maxProblems,
|
|
32
|
+
sourceContent
|
|
33
|
+
} = options;
|
|
34
|
+
const limitedDiagnostics = maxProblems ? diagnostics.slice(0, maxProblems) : diagnostics;
|
|
35
|
+
if (limitedDiagnostics.length === 0) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
const sourceLines = sourceContent?.split('\n');
|
|
39
|
+
const maxLineNum = sourceLines?.length ?? 0;
|
|
40
|
+
const gutterWidth = Math.max(String(maxLineNum).length, 2);
|
|
41
|
+
|
|
42
|
+
// calculate max widths for alignment
|
|
43
|
+
const maxLocationLength = Math.max(...limitedDiagnostics.map(d => formatLocation(d).length));
|
|
44
|
+
const maxCodeLength = Math.max(...limitedDiagnostics.map(d => d.code ? String(d.code).length : 0));
|
|
45
|
+
const lines = [];
|
|
46
|
+
|
|
47
|
+
// file path header
|
|
48
|
+
lines.push(chalk.bold(filePath));
|
|
49
|
+
|
|
50
|
+
// diagnostics
|
|
51
|
+
for (const diagnostic of limitedDiagnostics) {
|
|
52
|
+
const locationStr = formatLocation(diagnostic);
|
|
53
|
+
const location = chalk.dim(locationStr.padEnd(maxLocationLength));
|
|
54
|
+
const severity = severityToString(diagnostic.severity);
|
|
55
|
+
const codeStr = diagnostic.code ? String(diagnostic.code) : '';
|
|
56
|
+
const code = codeStr ? chalk.cyan(codeStr.padEnd(maxCodeLength)) : ' '.repeat(maxCodeLength);
|
|
57
|
+
const message = diagnostic.message;
|
|
58
|
+
lines.push(` ${location} ${severity} ${code} ${message}`);
|
|
59
|
+
|
|
60
|
+
// add code snippet if source content is available
|
|
61
|
+
if (sourceLines) {
|
|
62
|
+
lines.push('');
|
|
63
|
+
lines.push(...formatCodeSnippet(sourceLines, diagnostic, gutterWidth));
|
|
64
|
+
lines.push('');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// summary
|
|
69
|
+
const errorCount = limitedDiagnostics.filter(d => d.severity === DiagnosticSeverity.Error).length;
|
|
70
|
+
const warningCount = limitedDiagnostics.filter(d => d.severity === DiagnosticSeverity.Warning).length;
|
|
71
|
+
const infoCount = limitedDiagnostics.filter(d => d.severity === DiagnosticSeverity.Information).length;
|
|
72
|
+
const hintCount = limitedDiagnostics.filter(d => d.severity === DiagnosticSeverity.Hint).length;
|
|
73
|
+
lines.push('');
|
|
74
|
+
const parts = [];
|
|
75
|
+
if (errorCount > 0) parts.push(`${errorCount} ${errorCount === 1 ? 'error' : 'errors'}`);
|
|
76
|
+
if (warningCount > 0) parts.push(`${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}`);
|
|
77
|
+
if (infoCount > 0) parts.push(`${infoCount} ${infoCount === 1 ? 'info' : 'infos'}`);
|
|
78
|
+
if (hintCount > 0) parts.push(`${hintCount} ${hintCount === 1 ? 'hint' : 'hints'}`);
|
|
79
|
+
const symbol = errorCount > 0 ? chalk.red('✖') : chalk.yellow('⚠');
|
|
80
|
+
const problemText = limitedDiagnostics.length === 1 ? 'problem' : 'problems';
|
|
81
|
+
const breakdown = parts.length > 0 ? ` (${parts.join(', ')})` : '';
|
|
82
|
+
lines.push(`${symbol} ${limitedDiagnostics.length} ${problemText}${breakdown}`);
|
|
83
|
+
if (maxProblems && diagnostics.length > maxProblems) {
|
|
84
|
+
lines.push(chalk.dim(`(showing ${maxProblems} of ${diagnostics.length} problems)`));
|
|
85
|
+
}
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.formatGitHubActions = formatGitHubActions;
|
|
5
|
+
var _vscodeLanguageserverTypes = require("vscode-languageserver-types");
|
|
6
|
+
function severityToGitHub(severity) {
|
|
7
|
+
switch (severity) {
|
|
8
|
+
case _vscodeLanguageserverTypes.DiagnosticSeverity.Error:
|
|
9
|
+
return 'error';
|
|
10
|
+
case _vscodeLanguageserverTypes.DiagnosticSeverity.Warning:
|
|
11
|
+
return 'warning';
|
|
12
|
+
case _vscodeLanguageserverTypes.DiagnosticSeverity.Information:
|
|
13
|
+
case _vscodeLanguageserverTypes.DiagnosticSeverity.Hint:
|
|
14
|
+
return 'notice';
|
|
15
|
+
default:
|
|
16
|
+
return 'notice';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function escapeData(data) {
|
|
20
|
+
return data.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
|
21
|
+
}
|
|
22
|
+
function escapeProperty(value) {
|
|
23
|
+
return value.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A').replace(/:/g, '%3A').replace(/,/g, '%2C');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Formats diagnostics as GitHub Actions workflow commands.
|
|
27
|
+
* @see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
|
|
28
|
+
*/
|
|
29
|
+
function formatGitHubActions(filePath, diagnostics, options = {}) {
|
|
30
|
+
const {
|
|
31
|
+
maxProblems
|
|
32
|
+
} = options;
|
|
33
|
+
const limitedDiagnostics = maxProblems ? diagnostics.slice(0, maxProblems) : diagnostics;
|
|
34
|
+
const lines = [];
|
|
35
|
+
for (const diagnostic of limitedDiagnostics) {
|
|
36
|
+
const level = severityToGitHub(diagnostic.severity);
|
|
37
|
+
const line = diagnostic.range.start.line + 1;
|
|
38
|
+
const col = diagnostic.range.start.character + 1;
|
|
39
|
+
const endLine = diagnostic.range.end.line + 1;
|
|
40
|
+
const endCol = diagnostic.range.end.character + 1;
|
|
41
|
+
const message = escapeData(diagnostic.message);
|
|
42
|
+
const title = escapeProperty(diagnostic.code ? String(diagnostic.code) : 'validation');
|
|
43
|
+
const file = escapeProperty(filePath);
|
|
44
|
+
lines.push(`::${level} file=${file},line=${line},col=${col},endLine=${endLine},endColumn=${endCol},title=${title}::${message}`);
|
|
45
|
+
}
|
|
46
|
+
return lines.join('\n');
|
|
47
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DiagnosticSeverity } from 'vscode-languageserver-types';
|
|
2
|
+
function severityToGitHub(severity) {
|
|
3
|
+
switch (severity) {
|
|
4
|
+
case DiagnosticSeverity.Error:
|
|
5
|
+
return 'error';
|
|
6
|
+
case DiagnosticSeverity.Warning:
|
|
7
|
+
return 'warning';
|
|
8
|
+
case DiagnosticSeverity.Information:
|
|
9
|
+
case DiagnosticSeverity.Hint:
|
|
10
|
+
return 'notice';
|
|
11
|
+
default:
|
|
12
|
+
return 'notice';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function escapeData(data) {
|
|
16
|
+
return data.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
|
17
|
+
}
|
|
18
|
+
function escapeProperty(value) {
|
|
19
|
+
return value.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A').replace(/:/g, '%3A').replace(/,/g, '%2C');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Formats diagnostics as GitHub Actions workflow commands.
|
|
23
|
+
* @see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
|
|
24
|
+
*/
|
|
25
|
+
export function formatGitHubActions(filePath, diagnostics, options = {}) {
|
|
26
|
+
const {
|
|
27
|
+
maxProblems
|
|
28
|
+
} = options;
|
|
29
|
+
const limitedDiagnostics = maxProblems ? diagnostics.slice(0, maxProblems) : diagnostics;
|
|
30
|
+
const lines = [];
|
|
31
|
+
for (const diagnostic of limitedDiagnostics) {
|
|
32
|
+
const level = severityToGitHub(diagnostic.severity);
|
|
33
|
+
const line = diagnostic.range.start.line + 1;
|
|
34
|
+
const col = diagnostic.range.start.character + 1;
|
|
35
|
+
const endLine = diagnostic.range.end.line + 1;
|
|
36
|
+
const endCol = diagnostic.range.end.character + 1;
|
|
37
|
+
const message = escapeData(diagnostic.message);
|
|
38
|
+
const title = escapeProperty(diagnostic.code ? String(diagnostic.code) : 'validation');
|
|
39
|
+
const file = escapeProperty(filePath);
|
|
40
|
+
lines.push(`::${level} file=${file},line=${line},col=${col},endLine=${endLine},endColumn=${endCol},title=${title}::${message}`);
|
|
41
|
+
}
|
|
42
|
+
return lines.join('\n');
|
|
43
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.formatStylish = exports.formatJSON = exports.formatGitHubActions = exports.formatCodeframe = void 0;
|
|
5
|
+
var _stylish = require("./stylish.cjs");
|
|
6
|
+
exports.formatStylish = _stylish.formatStylish;
|
|
7
|
+
var _codeframe = require("./codeframe.cjs");
|
|
8
|
+
exports.formatCodeframe = _codeframe.formatCodeframe;
|
|
9
|
+
var _json = require("./json.cjs");
|
|
10
|
+
exports.formatJSON = _json.formatJSON;
|
|
11
|
+
var _githubActions = require("./github-actions.cjs");
|
|
12
|
+
exports.formatGitHubActions = _githubActions.formatGitHubActions;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.formatJSON = formatJSON;
|
|
5
|
+
function formatJSON(filePath, diagnostics, options = {}) {
|
|
6
|
+
const {
|
|
7
|
+
maxProblems
|
|
8
|
+
} = options;
|
|
9
|
+
const limitedDiagnostics = maxProblems ? diagnostics.slice(0, maxProblems) : diagnostics;
|
|
10
|
+
const output = {
|
|
11
|
+
filePath,
|
|
12
|
+
diagnostics: limitedDiagnostics,
|
|
13
|
+
summary: {
|
|
14
|
+
total: limitedDiagnostics.length,
|
|
15
|
+
truncated: maxProblems ? diagnostics.length > maxProblems : false,
|
|
16
|
+
originalTotal: diagnostics.length
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return JSON.stringify(output, null, 2);
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function formatJSON(filePath, diagnostics, options = {}) {
|
|
2
|
+
const {
|
|
3
|
+
maxProblems
|
|
4
|
+
} = options;
|
|
5
|
+
const limitedDiagnostics = maxProblems ? diagnostics.slice(0, maxProblems) : diagnostics;
|
|
6
|
+
const output = {
|
|
7
|
+
filePath,
|
|
8
|
+
diagnostics: limitedDiagnostics,
|
|
9
|
+
summary: {
|
|
10
|
+
total: limitedDiagnostics.length,
|
|
11
|
+
truncated: maxProblems ? diagnostics.length > maxProblems : false,
|
|
12
|
+
originalTotal: diagnostics.length
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
return JSON.stringify(output, null, 2);
|
|
16
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.formatLocation = formatLocation;
|
|
6
|
+
exports.formatStylish = formatStylish;
|
|
7
|
+
exports.severityToString = severityToString;
|
|
8
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
|
+
var _vscodeLanguageserverTypes = require("vscode-languageserver-types");
|
|
10
|
+
function severityToString(severity) {
|
|
11
|
+
switch (severity) {
|
|
12
|
+
case _vscodeLanguageserverTypes.DiagnosticSeverity.Error:
|
|
13
|
+
return _chalk.default.red('error');
|
|
14
|
+
case _vscodeLanguageserverTypes.DiagnosticSeverity.Warning:
|
|
15
|
+
return _chalk.default.yellow('warning');
|
|
16
|
+
case _vscodeLanguageserverTypes.DiagnosticSeverity.Information:
|
|
17
|
+
return _chalk.default.blue('info');
|
|
18
|
+
case _vscodeLanguageserverTypes.DiagnosticSeverity.Hint:
|
|
19
|
+
return _chalk.default.cyan('hint');
|
|
20
|
+
default:
|
|
21
|
+
return 'unknown';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function formatLocation(diagnostic) {
|
|
25
|
+
const line = diagnostic.range.start.line + 1;
|
|
26
|
+
const col = diagnostic.range.start.character + 1;
|
|
27
|
+
return `${line}:${col}`;
|
|
28
|
+
}
|
|
29
|
+
function formatStylish(filePath, diagnostics, options = {}) {
|
|
30
|
+
const {
|
|
31
|
+
maxProblems
|
|
32
|
+
} = options;
|
|
33
|
+
const limitedDiagnostics = maxProblems ? diagnostics.slice(0, maxProblems) : diagnostics;
|
|
34
|
+
if (limitedDiagnostics.length === 0) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
const lines = [];
|
|
38
|
+
|
|
39
|
+
// calculate max widths for alignment
|
|
40
|
+
const maxLocationLength = Math.max(...limitedDiagnostics.map(d => formatLocation(d).length));
|
|
41
|
+
const maxCodeLength = Math.max(...limitedDiagnostics.map(d => d.code ? String(d.code).length : 0));
|
|
42
|
+
|
|
43
|
+
// file path header
|
|
44
|
+
lines.push(_chalk.default.bold(filePath));
|
|
45
|
+
|
|
46
|
+
// diagnostics
|
|
47
|
+
for (const diagnostic of limitedDiagnostics) {
|
|
48
|
+
const locationStr = formatLocation(diagnostic);
|
|
49
|
+
const location = _chalk.default.dim(locationStr.padEnd(maxLocationLength));
|
|
50
|
+
const severity = severityToString(diagnostic.severity);
|
|
51
|
+
const codeStr = diagnostic.code ? String(diagnostic.code) : '';
|
|
52
|
+
const code = codeStr ? _chalk.default.cyan(codeStr.padEnd(maxCodeLength)) : ' '.repeat(maxCodeLength);
|
|
53
|
+
const message = diagnostic.message;
|
|
54
|
+
lines.push(` ${location} ${severity} ${code} ${message}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// summary
|
|
58
|
+
const errorCount = limitedDiagnostics.filter(d => d.severity === _vscodeLanguageserverTypes.DiagnosticSeverity.Error).length;
|
|
59
|
+
const warningCount = limitedDiagnostics.filter(d => d.severity === _vscodeLanguageserverTypes.DiagnosticSeverity.Warning).length;
|
|
60
|
+
const infoCount = limitedDiagnostics.filter(d => d.severity === _vscodeLanguageserverTypes.DiagnosticSeverity.Information).length;
|
|
61
|
+
const hintCount = limitedDiagnostics.filter(d => d.severity === _vscodeLanguageserverTypes.DiagnosticSeverity.Hint).length;
|
|
62
|
+
lines.push('');
|
|
63
|
+
const parts = [];
|
|
64
|
+
if (errorCount > 0) parts.push(`${errorCount} ${errorCount === 1 ? 'error' : 'errors'}`);
|
|
65
|
+
if (warningCount > 0) parts.push(`${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}`);
|
|
66
|
+
if (infoCount > 0) parts.push(`${infoCount} ${infoCount === 1 ? 'info' : 'infos'}`);
|
|
67
|
+
if (hintCount > 0) parts.push(`${hintCount} ${hintCount === 1 ? 'hint' : 'hints'}`);
|
|
68
|
+
const symbol = errorCount > 0 ? _chalk.default.red('✖') : _chalk.default.yellow('⚠');
|
|
69
|
+
const problemText = limitedDiagnostics.length === 1 ? 'problem' : 'problems';
|
|
70
|
+
const breakdown = parts.length > 0 ? ` (${parts.join(', ')})` : '';
|
|
71
|
+
lines.push(`${symbol} ${limitedDiagnostics.length} ${problemText}${breakdown}`);
|
|
72
|
+
if (maxProblems && diagnostics.length > maxProblems) {
|
|
73
|
+
lines.push(_chalk.default.dim(`(showing ${maxProblems} of ${diagnostics.length} problems)`));
|
|
74
|
+
}
|
|
75
|
+
return lines.join('\n');
|
|
76
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { DiagnosticSeverity } from 'vscode-languageserver-types';
|
|
3
|
+
export function severityToString(severity) {
|
|
4
|
+
switch (severity) {
|
|
5
|
+
case DiagnosticSeverity.Error:
|
|
6
|
+
return chalk.red('error');
|
|
7
|
+
case DiagnosticSeverity.Warning:
|
|
8
|
+
return chalk.yellow('warning');
|
|
9
|
+
case DiagnosticSeverity.Information:
|
|
10
|
+
return chalk.blue('info');
|
|
11
|
+
case DiagnosticSeverity.Hint:
|
|
12
|
+
return chalk.cyan('hint');
|
|
13
|
+
default:
|
|
14
|
+
return 'unknown';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function formatLocation(diagnostic) {
|
|
18
|
+
const line = diagnostic.range.start.line + 1;
|
|
19
|
+
const col = diagnostic.range.start.character + 1;
|
|
20
|
+
return `${line}:${col}`;
|
|
21
|
+
}
|
|
22
|
+
export function formatStylish(filePath, diagnostics, options = {}) {
|
|
23
|
+
const {
|
|
24
|
+
maxProblems
|
|
25
|
+
} = options;
|
|
26
|
+
const limitedDiagnostics = maxProblems ? diagnostics.slice(0, maxProblems) : diagnostics;
|
|
27
|
+
if (limitedDiagnostics.length === 0) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
const lines = [];
|
|
31
|
+
|
|
32
|
+
// calculate max widths for alignment
|
|
33
|
+
const maxLocationLength = Math.max(...limitedDiagnostics.map(d => formatLocation(d).length));
|
|
34
|
+
const maxCodeLength = Math.max(...limitedDiagnostics.map(d => d.code ? String(d.code).length : 0));
|
|
35
|
+
|
|
36
|
+
// file path header
|
|
37
|
+
lines.push(chalk.bold(filePath));
|
|
38
|
+
|
|
39
|
+
// diagnostics
|
|
40
|
+
for (const diagnostic of limitedDiagnostics) {
|
|
41
|
+
const locationStr = formatLocation(diagnostic);
|
|
42
|
+
const location = chalk.dim(locationStr.padEnd(maxLocationLength));
|
|
43
|
+
const severity = severityToString(diagnostic.severity);
|
|
44
|
+
const codeStr = diagnostic.code ? String(diagnostic.code) : '';
|
|
45
|
+
const code = codeStr ? chalk.cyan(codeStr.padEnd(maxCodeLength)) : ' '.repeat(maxCodeLength);
|
|
46
|
+
const message = diagnostic.message;
|
|
47
|
+
lines.push(` ${location} ${severity} ${code} ${message}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// summary
|
|
51
|
+
const errorCount = limitedDiagnostics.filter(d => d.severity === DiagnosticSeverity.Error).length;
|
|
52
|
+
const warningCount = limitedDiagnostics.filter(d => d.severity === DiagnosticSeverity.Warning).length;
|
|
53
|
+
const infoCount = limitedDiagnostics.filter(d => d.severity === DiagnosticSeverity.Information).length;
|
|
54
|
+
const hintCount = limitedDiagnostics.filter(d => d.severity === DiagnosticSeverity.Hint).length;
|
|
55
|
+
lines.push('');
|
|
56
|
+
const parts = [];
|
|
57
|
+
if (errorCount > 0) parts.push(`${errorCount} ${errorCount === 1 ? 'error' : 'errors'}`);
|
|
58
|
+
if (warningCount > 0) parts.push(`${warningCount} ${warningCount === 1 ? 'warning' : 'warnings'}`);
|
|
59
|
+
if (infoCount > 0) parts.push(`${infoCount} ${infoCount === 1 ? 'info' : 'infos'}`);
|
|
60
|
+
if (hintCount > 0) parts.push(`${hintCount} ${hintCount === 1 ? 'hint' : 'hints'}`);
|
|
61
|
+
const symbol = errorCount > 0 ? chalk.red('✖') : chalk.yellow('⚠');
|
|
62
|
+
const problemText = limitedDiagnostics.length === 1 ? 'problem' : 'problems';
|
|
63
|
+
const breakdown = parts.length > 0 ? ` (${parts.join(', ')})` : '';
|
|
64
|
+
lines.push(`${symbol} ${limitedDiagnostics.length} ${problemText}${breakdown}`);
|
|
65
|
+
if (maxProblems && diagnostics.length > maxProblems) {
|
|
66
|
+
lines.push(chalk.dim(`(showing ${maxProblems} of ${diagnostics.length} problems)`));
|
|
67
|
+
}
|
|
68
|
+
return lines.join('\n');
|
|
69
|
+
}
|