@redocly/openapi-core 0.0.0-snapshot.1737554067
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 +268 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.js +38 -0
- package/lib/benchmark/benches/lint-with-nested-rule.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-nested-rule.bench.js +44 -0
- package/lib/benchmark/benches/lint-with-no-rules.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-no-rules.bench.js +25 -0
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +37 -0
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +36 -0
- package/lib/benchmark/benches/recommended-oas3.bench.d.ts +3 -0
- package/lib/benchmark/benches/recommended-oas3.bench.js +21 -0
- package/lib/benchmark/benches/resolve-with-no-external.bench.d.ts +3 -0
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +22 -0
- package/lib/benchmark/utils.d.ts +6 -0
- package/lib/benchmark/utils.js +34 -0
- package/lib/bundle.d.ts +50 -0
- package/lib/bundle.js +385 -0
- package/lib/config/all.d.ts +3 -0
- package/lib/config/all.js +227 -0
- package/lib/config/builtIn.d.ts +3 -0
- package/lib/config/builtIn.js +53 -0
- package/lib/config/config-resolvers.d.ts +30 -0
- package/lib/config/config-resolvers.js +447 -0
- package/lib/config/config.d.ts +53 -0
- package/lib/config/config.js +320 -0
- package/lib/config/index.d.ts +7 -0
- package/lib/config/index.js +23 -0
- package/lib/config/load.d.ts +38 -0
- package/lib/config/load.js +140 -0
- package/lib/config/minimal.d.ts +3 -0
- package/lib/config/minimal.js +203 -0
- package/lib/config/recommended-strict.d.ts +3 -0
- package/lib/config/recommended-strict.js +203 -0
- package/lib/config/recommended.d.ts +3 -0
- package/lib/config/recommended.js +203 -0
- package/lib/config/rules.d.ts +10 -0
- package/lib/config/rules.js +37 -0
- package/lib/config/spec.d.ts +3 -0
- package/lib/config/spec.js +29 -0
- package/lib/config/types.d.ts +189 -0
- package/lib/config/types.js +2 -0
- package/lib/config/utils.d.ts +19 -0
- package/lib/config/utils.js +308 -0
- package/lib/decorators/arazzo/index.d.ts +1 -0
- package/lib/decorators/arazzo/index.js +4 -0
- package/lib/decorators/async2/index.d.ts +1 -0
- package/lib/decorators/async2/index.js +4 -0
- package/lib/decorators/async3/index.d.ts +1 -0
- package/lib/decorators/async3/index.js +4 -0
- package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
- package/lib/decorators/common/filters/filter-helper.js +66 -0
- package/lib/decorators/common/filters/filter-in.d.ts +2 -0
- package/lib/decorators/common/filters/filter-in.js +17 -0
- package/lib/decorators/common/filters/filter-out.d.ts +2 -0
- package/lib/decorators/common/filters/filter-out.js +17 -0
- package/lib/decorators/common/info-description-override.d.ts +2 -0
- package/lib/decorators/common/info-description-override.js +24 -0
- package/lib/decorators/common/info-override.d.ts +2 -0
- package/lib/decorators/common/info-override.js +17 -0
- package/lib/decorators/common/media-type-examples-override.d.ts +2 -0
- package/lib/decorators/common/media-type-examples-override.js +59 -0
- package/lib/decorators/common/operation-description-override.d.ts +2 -0
- package/lib/decorators/common/operation-description-override.js +29 -0
- package/lib/decorators/common/registry-dependencies.d.ts +2 -0
- package/lib/decorators/common/registry-dependencies.js +24 -0
- package/lib/decorators/common/remove-x-internal.d.ts +2 -0
- package/lib/decorators/common/remove-x-internal.js +69 -0
- package/lib/decorators/common/tag-description-override.d.ts +2 -0
- package/lib/decorators/common/tag-description-override.js +25 -0
- package/lib/decorators/oas2/index.d.ts +11 -0
- package/lib/decorators/oas2/index.js +21 -0
- package/lib/decorators/oas2/remove-unused-components.d.ts +2 -0
- package/lib/decorators/oas2/remove-unused-components.js +89 -0
- package/lib/decorators/oas3/index.d.ts +12 -0
- package/lib/decorators/oas3/index.js +23 -0
- package/lib/decorators/oas3/remove-unused-components.d.ts +2 -0
- package/lib/decorators/oas3/remove-unused-components.js +100 -0
- package/lib/env.d.ts +2 -0
- package/lib/env.js +7 -0
- package/lib/format/codeframes.d.ts +22 -0
- package/lib/format/codeframes.js +185 -0
- package/lib/format/format.d.ts +20 -0
- package/lib/format/format.js +365 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +98 -0
- package/lib/js-yaml/index.d.ts +3 -0
- package/lib/js-yaml/index.js +15 -0
- package/lib/lint.d.ts +32 -0
- package/lib/lint.js +118 -0
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/oas-types.d.ts +36 -0
- package/lib/oas-types.js +92 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/domains.d.ts +14 -0
- package/lib/redocly/domains.js +41 -0
- package/lib/redocly/index.d.ts +30 -0
- package/lib/redocly/index.js +131 -0
- package/lib/redocly/redocly-client-types.d.ts +8 -0
- package/lib/redocly/redocly-client-types.js +2 -0
- package/lib/redocly/registry-api-types.d.ts +29 -0
- package/lib/redocly/registry-api-types.js +2 -0
- package/lib/redocly/registry-api.d.ts +17 -0
- package/lib/redocly/registry-api.js +96 -0
- package/lib/ref-utils.d.ts +27 -0
- package/lib/ref-utils.js +85 -0
- package/lib/resolve.d.ts +66 -0
- package/lib/resolve.js +342 -0
- package/lib/rules/ajv.d.ts +10 -0
- package/lib/rules/ajv.js +82 -0
- package/lib/rules/arazzo/criteria-unique.d.ts +2 -0
- package/lib/rules/arazzo/criteria-unique.js +71 -0
- package/lib/rules/arazzo/index.d.ts +3 -0
- package/lib/rules/arazzo/index.js +36 -0
- package/lib/rules/arazzo/parameters-unique.d.ts +2 -0
- package/lib/rules/arazzo/parameters-unique.js +32 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.d.ts +2 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.js +28 -0
- package/lib/rules/arazzo/sourceDescription-type.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescription-type.js +22 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.js +24 -0
- package/lib/rules/arazzo/sourceDescriptions-not-empty.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-not-empty.js +18 -0
- package/lib/rules/arazzo/step-onFailure-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onFailure-unique.js +32 -0
- package/lib/rules/arazzo/step-onSuccess-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onSuccess-unique.js +32 -0
- package/lib/rules/arazzo/stepId-unique.d.ts +2 -0
- package/lib/rules/arazzo/stepId-unique.js +26 -0
- package/lib/rules/arazzo/workflow-dependsOn.d.ts +2 -0
- package/lib/rules/arazzo/workflow-dependsOn.js +56 -0
- package/lib/rules/arazzo/workflowId-unique.d.ts +2 -0
- package/lib/rules/arazzo/workflowId-unique.js +22 -0
- package/lib/rules/async2/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async2/channels-kebab-case.js +19 -0
- package/lib/rules/async2/index.d.ts +3 -0
- package/lib/rules/async2/index.js +27 -0
- package/lib/rules/async2/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async2/no-channel-trailing-slash.js +16 -0
- package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async3/channels-kebab-case.js +19 -0
- package/lib/rules/async3/index.d.ts +3 -0
- package/lib/rules/async3/index.js +27 -0
- package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
- package/lib/rules/common/assertions/asserts.d.ts +30 -0
- package/lib/rules/common/assertions/asserts.js +281 -0
- package/lib/rules/common/assertions/index.d.ts +27 -0
- package/lib/rules/common/assertions/index.js +24 -0
- package/lib/rules/common/assertions/utils.d.ts +28 -0
- package/lib/rules/common/assertions/utils.js +226 -0
- package/lib/rules/common/info-contact.d.ts +2 -0
- package/lib/rules/common/info-contact.js +17 -0
- package/lib/rules/common/info-license-strict.d.ts +2 -0
- package/lib/rules/common/info-license-strict.js +26 -0
- package/lib/rules/common/info-license-url.d.ts +2 -0
- package/lib/rules/common/info-license-url.js +12 -0
- package/lib/rules/common/info-license.d.ts +2 -0
- package/lib/rules/common/info-license.js +17 -0
- package/lib/rules/common/no-ambiguous-paths.d.ts +2 -0
- package/lib/rules/common/no-ambiguous-paths.js +45 -0
- package/lib/rules/common/no-enum-type-mismatch.d.ts +2 -0
- package/lib/rules/common/no-enum-type-mismatch.js +41 -0
- package/lib/rules/common/no-http-verbs-in-paths.d.ts +2 -0
- package/lib/rules/common/no-http-verbs-in-paths.js +33 -0
- package/lib/rules/common/no-identical-paths.d.ts +2 -0
- package/lib/rules/common/no-identical-paths.js +24 -0
- package/lib/rules/common/no-invalid-parameter-examples.d.ts +1 -0
- package/lib/rules/common/no-invalid-parameter-examples.js +24 -0
- package/lib/rules/common/no-invalid-schema-examples.d.ts +1 -0
- package/lib/rules/common/no-invalid-schema-examples.js +22 -0
- package/lib/rules/common/no-path-trailing-slash.d.ts +2 -0
- package/lib/rules/common/no-path-trailing-slash.js +16 -0
- package/lib/rules/common/no-required-schema-properties-undefined.d.ts +2 -0
- package/lib/rules/common/no-required-schema-properties-undefined.js +36 -0
- package/lib/rules/common/operation-2xx-response.d.ts +2 -0
- package/lib/rules/common/operation-2xx-response.js +23 -0
- package/lib/rules/common/operation-4xx-response.d.ts +2 -0
- package/lib/rules/common/operation-4xx-response.js +23 -0
- package/lib/rules/common/operation-description.d.ts +2 -0
- package/lib/rules/common/operation-description.js +12 -0
- package/lib/rules/common/operation-operationId-unique.d.ts +2 -0
- package/lib/rules/common/operation-operationId-unique.js +20 -0
- package/lib/rules/common/operation-operationId-url-safe.d.ts +2 -0
- package/lib/rules/common/operation-operationId-url-safe.js +18 -0
- package/lib/rules/common/operation-operationId.d.ts +2 -0
- package/lib/rules/common/operation-operationId.js +16 -0
- package/lib/rules/common/operation-parameters-unique.d.ts +2 -0
- package/lib/rules/common/operation-parameters-unique.js +40 -0
- package/lib/rules/common/operation-singular-tag.d.ts +2 -0
- package/lib/rules/common/operation-singular-tag.js +16 -0
- package/lib/rules/common/operation-summary.d.ts +2 -0
- package/lib/rules/common/operation-summary.js +12 -0
- package/lib/rules/common/operation-tag-defined.d.ts +2 -0
- package/lib/rules/common/operation-tag-defined.js +24 -0
- package/lib/rules/common/parameter-description.d.ts +2 -0
- package/lib/rules/common/parameter-description.js +22 -0
- package/lib/rules/common/path-declaration-must-exist.d.ts +2 -0
- package/lib/rules/common/path-declaration-must-exist.js +16 -0
- package/lib/rules/common/path-excludes-patterns.d.ts +2 -0
- package/lib/rules/common/path-excludes-patterns.js +22 -0
- package/lib/rules/common/path-http-verbs-order.d.ts +2 -0
- package/lib/rules/common/path-http-verbs-order.js +26 -0
- package/lib/rules/common/path-not-include-query.d.ts +2 -0
- package/lib/rules/common/path-not-include-query.js +18 -0
- package/lib/rules/common/path-params-defined.d.ts +2 -0
- package/lib/rules/common/path-params-defined.js +58 -0
- package/lib/rules/common/path-segment-plural.d.ts +2 -0
- package/lib/rules/common/path-segment-plural.js +33 -0
- package/lib/rules/common/paths-kebab-case.d.ts +2 -0
- package/lib/rules/common/paths-kebab-case.js +20 -0
- package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
- package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
- package/lib/rules/common/response-contains-header.d.ts +2 -0
- package/lib/rules/common/response-contains-header.js +29 -0
- package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
- package/lib/rules/common/scalar-property-missing-example.js +42 -0
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/security-defined.js +65 -0
- package/lib/rules/common/spec-strict-refs.d.ts +2 -0
- package/lib/rules/common/spec-strict-refs.js +30 -0
- package/lib/rules/common/struct.d.ts +2 -0
- package/lib/rules/common/struct.js +158 -0
- package/lib/rules/common/tag-description.d.ts +2 -0
- package/lib/rules/common/tag-description.js +12 -0
- package/lib/rules/common/tags-alphabetical.d.ts +2 -0
- package/lib/rules/common/tags-alphabetical.js +23 -0
- package/lib/rules/no-unresolved-refs.d.ts +5 -0
- package/lib/rules/no-unresolved-refs.js +46 -0
- package/lib/rules/oas2/boolean-parameter-prefixes.d.ts +5 -0
- package/lib/rules/oas2/boolean-parameter-prefixes.js +22 -0
- package/lib/rules/oas2/index.d.ts +3 -0
- package/lib/rules/oas2/index.js +98 -0
- package/lib/rules/oas2/request-mime-type.d.ts +2 -0
- package/lib/rules/oas2/request-mime-type.js +17 -0
- package/lib/rules/oas2/response-contains-property.d.ts +2 -0
- package/lib/rules/oas2/response-contains-property.js +37 -0
- package/lib/rules/oas2/response-mime-type.d.ts +2 -0
- package/lib/rules/oas2/response-mime-type.js +17 -0
- package/lib/rules/oas3/array-parameter-serialization.d.ts +5 -0
- package/lib/rules/oas3/array-parameter-serialization.js +29 -0
- package/lib/rules/oas3/boolean-parameter-prefixes.d.ts +5 -0
- package/lib/rules/oas3/boolean-parameter-prefixes.js +24 -0
- package/lib/rules/oas3/component-name-unique.d.ts +2 -0
- package/lib/rules/oas3/component-name-unique.js +133 -0
- package/lib/rules/oas3/index.d.ts +3 -0
- package/lib/rules/oas3/index.js +122 -0
- package/lib/rules/oas3/no-empty-servers.d.ts +2 -0
- package/lib/rules/oas3/no-empty-servers.js +23 -0
- package/lib/rules/oas3/no-example-value-and-externalValue.d.ts +2 -0
- package/lib/rules/oas3/no-example-value-and-externalValue.js +16 -0
- package/lib/rules/oas3/no-invalid-media-type-examples.d.ts +2 -0
- package/lib/rules/oas3/no-invalid-media-type-examples.js +39 -0
- package/lib/rules/oas3/no-server-example.com.d.ts +2 -0
- package/lib/rules/oas3/no-server-example.com.js +18 -0
- package/lib/rules/oas3/no-server-trailing-slash.d.ts +2 -0
- package/lib/rules/oas3/no-server-trailing-slash.js +18 -0
- package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/no-server-variables-empty-enum.js +66 -0
- package/lib/rules/oas3/no-undefined-server-variable.d.ts +2 -0
- package/lib/rules/oas3/no-undefined-server-variable.js +31 -0
- package/lib/rules/oas3/no-unused-components.d.ts +2 -0
- package/lib/rules/oas3/no-unused-components.js +73 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
- package/lib/rules/oas3/request-mime-type.d.ts +2 -0
- package/lib/rules/oas3/request-mime-type.js +31 -0
- package/lib/rules/oas3/response-contains-property.d.ts +2 -0
- package/lib/rules/oas3/response-contains-property.js +39 -0
- package/lib/rules/oas3/response-mime-type.d.ts +2 -0
- package/lib/rules/oas3/response-mime-type.js +31 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +62 -0
- package/lib/rules/other/stats.d.ts +41 -0
- package/lib/rules/other/stats.js +75 -0
- package/lib/rules/spot/no-criteria-xpath.d.ts +2 -0
- package/lib/rules/spot/no-criteria-xpath.js +21 -0
- package/lib/rules/spot/spot-supported-versions.d.ts +2 -0
- package/lib/rules/spot/spot-supported-versions.js +21 -0
- package/lib/rules/utils.d.ts +22 -0
- package/lib/rules/utils.js +183 -0
- package/lib/types/arazzo.d.ts +2 -0
- package/lib/types/arazzo.js +311 -0
- package/lib/types/asyncapi2.d.ts +17 -0
- package/lib/types/asyncapi2.js +1008 -0
- package/lib/types/asyncapi3.d.ts +2 -0
- package/lib/types/asyncapi3.js +347 -0
- package/lib/types/index.d.ts +57 -0
- package/lib/types/index.js +94 -0
- package/lib/types/json-schema-adapter.d.ts +3 -0
- package/lib/types/json-schema-adapter.js +159 -0
- package/lib/types/oas2.d.ts +3 -0
- package/lib/types/oas2.js +456 -0
- package/lib/types/oas3.d.ts +7 -0
- package/lib/types/oas3.js +554 -0
- package/lib/types/oas3_1.d.ts +6 -0
- package/lib/types/oas3_1.js +285 -0
- package/lib/types/redocly-yaml.d.ts +26 -0
- package/lib/types/redocly-yaml.js +1126 -0
- package/lib/typings/arazzo.d.ts +131 -0
- package/lib/typings/arazzo.js +5 -0
- package/lib/typings/asyncapi.d.ts +21 -0
- package/lib/typings/asyncapi.js +2 -0
- package/lib/typings/asyncapi3.d.ts +53 -0
- package/lib/typings/asyncapi3.js +2 -0
- package/lib/typings/common.d.ts +8 -0
- package/lib/typings/common.js +2 -0
- package/lib/typings/openapi.d.ts +355 -0
- package/lib/typings/openapi.js +2 -0
- package/lib/typings/swagger.d.ts +217 -0
- package/lib/typings/swagger.js +2 -0
- package/lib/utils.d.ts +70 -0
- package/lib/utils.js +301 -0
- package/lib/visitors.d.ts +229 -0
- package/lib/visitors.js +176 -0
- package/lib/walk.d.ts +78 -0
- package/lib/walk.js +290 -0
- package/package.json +59 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCodeframe = getCodeframe;
|
|
4
|
+
exports.getLineColLocation = getLineColLocation;
|
|
5
|
+
exports.getAstNodeByPointer = getAstNodeByPointer;
|
|
6
|
+
const yamlAst = require("yaml-ast-parser");
|
|
7
|
+
const ref_utils_1 = require("../ref-utils");
|
|
8
|
+
const logger_1 = require("../logger");
|
|
9
|
+
const MAX_LINE_LENGTH = 150;
|
|
10
|
+
const MAX_CODEFRAME_LINES = 3;
|
|
11
|
+
// TODO: temporary
|
|
12
|
+
function parsePointer(pointer) {
|
|
13
|
+
return pointer.substr(2).split('/').map(ref_utils_1.unescapePointer);
|
|
14
|
+
}
|
|
15
|
+
function getCodeframe(location, color) {
|
|
16
|
+
logger_1.colorOptions.enabled = color;
|
|
17
|
+
const { start, end = { line: start.line, col: start.col + 1 }, source } = location;
|
|
18
|
+
const lines = source.getLines();
|
|
19
|
+
const startLineNum = start.line;
|
|
20
|
+
const endLineNum = Math.max(Math.min(end.line, lines.length), start.line);
|
|
21
|
+
let skipLines = Math.max(endLineNum - startLineNum - MAX_CODEFRAME_LINES + 1, 0);
|
|
22
|
+
if (skipLines < 2)
|
|
23
|
+
skipLines = 0; // do not skip one line
|
|
24
|
+
// Lines specified like this: ["prefix", "string"],
|
|
25
|
+
const prefixedLines = [];
|
|
26
|
+
let currentPad = 0;
|
|
27
|
+
for (let i = startLineNum; i <= endLineNum; i++) {
|
|
28
|
+
if (skipLines > 0 && i >= endLineNum - skipLines)
|
|
29
|
+
break;
|
|
30
|
+
const line = lines[i - 1] || '';
|
|
31
|
+
if (line !== '')
|
|
32
|
+
currentPad = padSize(line);
|
|
33
|
+
const startIdx = i === startLineNum ? start.col - 1 : currentPad;
|
|
34
|
+
const endIdx = i === endLineNum ? end.col - 1 : line.length;
|
|
35
|
+
prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx, logger_1.colorize.red)]);
|
|
36
|
+
if (!color)
|
|
37
|
+
prefixedLines.push(['', underlineLine(line, startIdx, endIdx)]);
|
|
38
|
+
}
|
|
39
|
+
if (skipLines > 0) {
|
|
40
|
+
prefixedLines.push([
|
|
41
|
+
`…`,
|
|
42
|
+
`${whitespace(currentPad)}${logger_1.colorize.gray(`< ${skipLines} more lines >`)}`,
|
|
43
|
+
]);
|
|
44
|
+
// print last line
|
|
45
|
+
prefixedLines.push([
|
|
46
|
+
`${endLineNum}`,
|
|
47
|
+
markLine(lines[endLineNum - 1], -1, end.col - 1, logger_1.colorize.red),
|
|
48
|
+
]);
|
|
49
|
+
if (!color)
|
|
50
|
+
prefixedLines.push(['', underlineLine(lines[endLineNum - 1], -1, end.col - 1)]);
|
|
51
|
+
}
|
|
52
|
+
return printPrefixedLines([
|
|
53
|
+
[`${startLineNum - 2}`, markLine(lines[startLineNum - 1 - 2])],
|
|
54
|
+
[`${startLineNum - 1}`, markLine(lines[startLineNum - 1 - 1])],
|
|
55
|
+
...prefixedLines,
|
|
56
|
+
[`${endLineNum + 1}`, markLine(lines[endLineNum - 1 + 1])],
|
|
57
|
+
[`${endLineNum + 2}`, markLine(lines[endLineNum - 1 + 2])],
|
|
58
|
+
]);
|
|
59
|
+
function markLine(line, startIdx = -1, endIdx = +Infinity, variant = logger_1.colorize.gray) {
|
|
60
|
+
if (!color)
|
|
61
|
+
return line;
|
|
62
|
+
if (!line)
|
|
63
|
+
return line;
|
|
64
|
+
if (startIdx === -1) {
|
|
65
|
+
startIdx = padSize(line);
|
|
66
|
+
}
|
|
67
|
+
endIdx = Math.min(endIdx, line.length);
|
|
68
|
+
return (line.substr(0, startIdx) + variant(line.substring(startIdx, endIdx)) + line.substr(endIdx));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function printPrefixedLines(lines) {
|
|
72
|
+
const existingLines = lines.filter(([_, line]) => line !== undefined);
|
|
73
|
+
const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
|
|
74
|
+
const dedentLen = Math.min(...existingLines.map(([_, line]) => (line === '' ? Infinity : padSize(line))));
|
|
75
|
+
return existingLines
|
|
76
|
+
.map(([prefix, line]) => logger_1.colorize.gray(leftPad(padLen, prefix) + ' |') +
|
|
77
|
+
(line ? ' ' + limitLineLength(line.substring(dedentLen)) : ''))
|
|
78
|
+
.join('\n');
|
|
79
|
+
}
|
|
80
|
+
function limitLineLength(line, maxLen = MAX_LINE_LENGTH) {
|
|
81
|
+
const overflowLen = line.length - maxLen;
|
|
82
|
+
if (overflowLen > 0) {
|
|
83
|
+
const charsMoreText = logger_1.colorize.gray(`...<${overflowLen} chars>`);
|
|
84
|
+
return line.substring(0, maxLen - charsMoreText.length) + charsMoreText;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return line;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function underlineLine(line, startIdx = -1, endIdx = +Infinity) {
|
|
91
|
+
if (startIdx === -1) {
|
|
92
|
+
startIdx = padSize(line);
|
|
93
|
+
}
|
|
94
|
+
endIdx = Math.min(endIdx, line.length);
|
|
95
|
+
return whitespace(startIdx) + '^'.repeat(Math.max(endIdx - startIdx, 1));
|
|
96
|
+
}
|
|
97
|
+
function whitespace(len) {
|
|
98
|
+
return ' '.repeat(len);
|
|
99
|
+
}
|
|
100
|
+
function leftPad(len, str) {
|
|
101
|
+
return whitespace(len - str.length) + str;
|
|
102
|
+
}
|
|
103
|
+
function padSize(line) {
|
|
104
|
+
for (let i = 0; i < line.length; i++) {
|
|
105
|
+
if (line[i] !== ' ')
|
|
106
|
+
return i;
|
|
107
|
+
}
|
|
108
|
+
return line.length;
|
|
109
|
+
}
|
|
110
|
+
function getLineColLocation(location) {
|
|
111
|
+
if (location.pointer === undefined)
|
|
112
|
+
return location;
|
|
113
|
+
const { source, pointer, reportOnKey } = location;
|
|
114
|
+
const ast = source.getAst(yamlAst.safeLoad);
|
|
115
|
+
const astNode = getAstNodeByPointer(ast, pointer, !!reportOnKey);
|
|
116
|
+
return {
|
|
117
|
+
...location,
|
|
118
|
+
pointer: undefined,
|
|
119
|
+
...positionsToLoc(source.body, astNode?.startPosition ?? 1, astNode?.endPosition ?? 1),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function positionsToLoc(source, startPos, endPos) {
|
|
123
|
+
let currentLine = 1;
|
|
124
|
+
let currentCol = 1;
|
|
125
|
+
let start = { line: 1, col: 1 };
|
|
126
|
+
for (let i = 0; i < endPos - 1; i++) {
|
|
127
|
+
if (i === startPos - 1) {
|
|
128
|
+
start = { line: currentLine, col: currentCol + 1 };
|
|
129
|
+
}
|
|
130
|
+
if (source[i] === '\n') {
|
|
131
|
+
currentLine++;
|
|
132
|
+
currentCol = 1;
|
|
133
|
+
if (i === startPos - 1) {
|
|
134
|
+
start = { line: currentLine, col: currentCol };
|
|
135
|
+
}
|
|
136
|
+
if (source[i + 1] === '\r')
|
|
137
|
+
i++; // TODO: test it
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
currentCol++;
|
|
141
|
+
}
|
|
142
|
+
const end = startPos === endPos ? { ...start } : { line: currentLine, col: currentCol + 1 };
|
|
143
|
+
return { start, end };
|
|
144
|
+
}
|
|
145
|
+
function getAstNodeByPointer(root, pointer, reportOnKey) {
|
|
146
|
+
const pointerSegments = parsePointer(pointer);
|
|
147
|
+
if (root === undefined) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
let currentNode = root;
|
|
151
|
+
for (const key of pointerSegments) {
|
|
152
|
+
if (currentNode.kind === yamlAst.Kind.MAP) {
|
|
153
|
+
const mapping = currentNode.mappings.find((m) => m.key.value === key);
|
|
154
|
+
if (!mapping)
|
|
155
|
+
break;
|
|
156
|
+
currentNode = mapping;
|
|
157
|
+
if (!mapping?.value)
|
|
158
|
+
break; // If node has value - return value, if not - return node itself
|
|
159
|
+
currentNode = mapping.value;
|
|
160
|
+
}
|
|
161
|
+
else if (currentNode.kind === yamlAst.Kind.SEQ) {
|
|
162
|
+
const elem = currentNode.items[parseInt(key, 10)];
|
|
163
|
+
if (!elem)
|
|
164
|
+
break;
|
|
165
|
+
currentNode = elem;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!reportOnKey) {
|
|
169
|
+
return currentNode;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
const parent = currentNode.parent;
|
|
173
|
+
if (!parent)
|
|
174
|
+
return currentNode;
|
|
175
|
+
if (parent.kind === yamlAst.Kind.SEQ) {
|
|
176
|
+
return currentNode;
|
|
177
|
+
}
|
|
178
|
+
else if (parent.kind === yamlAst.Kind.MAPPING) {
|
|
179
|
+
return parent.key;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
return currentNode;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { NormalizedProblem } from '../walk';
|
|
2
|
+
export type Totals = {
|
|
3
|
+
errors: number;
|
|
4
|
+
warnings: number;
|
|
5
|
+
ignored: number;
|
|
6
|
+
};
|
|
7
|
+
export type OutputFormat = 'codeframe' | 'stylish' | 'json' | 'checkstyle' | 'codeclimate' | 'summary' | 'github-actions' | 'markdown';
|
|
8
|
+
export declare function getTotals(problems: (NormalizedProblem & {
|
|
9
|
+
ignored?: boolean;
|
|
10
|
+
})[]): Totals;
|
|
11
|
+
export declare function formatProblems(problems: (NormalizedProblem & {
|
|
12
|
+
ignored?: boolean;
|
|
13
|
+
})[], opts: {
|
|
14
|
+
maxProblems?: number;
|
|
15
|
+
cwd?: string;
|
|
16
|
+
format?: OutputFormat;
|
|
17
|
+
color?: boolean;
|
|
18
|
+
totals: Totals;
|
|
19
|
+
version: string;
|
|
20
|
+
}): void;
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTotals = getTotals;
|
|
4
|
+
exports.formatProblems = formatProblems;
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
const output_1 = require("../output");
|
|
8
|
+
const codeframes_1 = require("./codeframes");
|
|
9
|
+
const env_1 = require("../env");
|
|
10
|
+
const ref_utils_1 = require("../ref-utils");
|
|
11
|
+
const coreVersion = require('../../package.json').version;
|
|
12
|
+
const ERROR_MESSAGE = {
|
|
13
|
+
INVALID_SEVERITY_LEVEL: 'Invalid severity level; accepted values: error or warn',
|
|
14
|
+
};
|
|
15
|
+
const BG_COLORS = {
|
|
16
|
+
warn: (str) => logger_1.colorize.bgYellow(logger_1.colorize.black(str)),
|
|
17
|
+
error: logger_1.colorize.bgRed,
|
|
18
|
+
};
|
|
19
|
+
const COLORS = {
|
|
20
|
+
warn: logger_1.colorize.yellow,
|
|
21
|
+
error: logger_1.colorize.red,
|
|
22
|
+
};
|
|
23
|
+
const SEVERITY_NAMES = {
|
|
24
|
+
warn: 'Warning',
|
|
25
|
+
error: 'Error',
|
|
26
|
+
};
|
|
27
|
+
const CODECLIMATE_SEVERITY_MAPPING = {
|
|
28
|
+
error: 'critical',
|
|
29
|
+
warn: 'minor',
|
|
30
|
+
};
|
|
31
|
+
const MAX_SUGGEST = 5;
|
|
32
|
+
function severityToNumber(severity) {
|
|
33
|
+
return severity === 'error' ? 1 : 2;
|
|
34
|
+
}
|
|
35
|
+
function getTotals(problems) {
|
|
36
|
+
let errors = 0;
|
|
37
|
+
let warnings = 0;
|
|
38
|
+
let ignored = 0;
|
|
39
|
+
for (const m of problems) {
|
|
40
|
+
if (m.ignored) {
|
|
41
|
+
ignored++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (m.severity === 'error')
|
|
45
|
+
errors++;
|
|
46
|
+
if (m.severity === 'warn')
|
|
47
|
+
warnings++;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
errors,
|
|
51
|
+
warnings,
|
|
52
|
+
ignored,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function formatProblems(problems, opts) {
|
|
56
|
+
const { maxProblems = 100, cwd = env_1.isBrowser ? '' : process.cwd(), format = 'codeframe', color = logger_1.colorOptions.enabled, totals = getTotals(problems), version = coreVersion, } = opts;
|
|
57
|
+
logger_1.colorOptions.enabled = color; // force colors if specified
|
|
58
|
+
const totalProblems = problems.length;
|
|
59
|
+
problems = problems.filter((m) => !m.ignored);
|
|
60
|
+
const ignoredProblems = totalProblems - problems.length;
|
|
61
|
+
problems = problems
|
|
62
|
+
.sort((a, b) => severityToNumber(a.severity) - severityToNumber(b.severity))
|
|
63
|
+
.slice(0, maxProblems);
|
|
64
|
+
if (!totalProblems && format !== 'json')
|
|
65
|
+
return;
|
|
66
|
+
switch (format) {
|
|
67
|
+
case 'json':
|
|
68
|
+
outputJSON();
|
|
69
|
+
break;
|
|
70
|
+
case 'codeframe':
|
|
71
|
+
for (let i = 0; i < problems.length; i++) {
|
|
72
|
+
const problem = problems[i];
|
|
73
|
+
logger_1.logger.info(`${formatCodeframe(problem, i)}\n`);
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case 'stylish': {
|
|
77
|
+
const groupedByFile = groupByFiles(problems);
|
|
78
|
+
for (const [file, { ruleIdPad, locationPad: positionPad, fileProblems }] of Object.entries(groupedByFile)) {
|
|
79
|
+
logger_1.logger.info(`${logger_1.colorize.blue((0, ref_utils_1.isAbsoluteUrl)(file) ? file : path.relative(cwd, file))}:\n`);
|
|
80
|
+
for (let i = 0; i < fileProblems.length; i++) {
|
|
81
|
+
const problem = fileProblems[i];
|
|
82
|
+
logger_1.logger.info(`${formatStylish(problem, positionPad, ruleIdPad)}\n`);
|
|
83
|
+
}
|
|
84
|
+
logger_1.logger.info('\n');
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'markdown': {
|
|
89
|
+
const groupedByFile = groupByFiles(problems);
|
|
90
|
+
for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
|
|
91
|
+
output_1.output.write(`## Lint: ${(0, ref_utils_1.isAbsoluteUrl)(file) ? file : path.relative(cwd, file)}\n\n`);
|
|
92
|
+
output_1.output.write(`| Severity | Location | Problem | Message |\n`);
|
|
93
|
+
output_1.output.write(`|---|---|---|---|\n`);
|
|
94
|
+
for (let i = 0; i < fileProblems.length; i++) {
|
|
95
|
+
const problem = fileProblems[i];
|
|
96
|
+
output_1.output.write(`${formatMarkdown(problem)}\n`);
|
|
97
|
+
}
|
|
98
|
+
output_1.output.write('\n');
|
|
99
|
+
if (totals.errors > 0) {
|
|
100
|
+
output_1.output.write(`Validation failed\nErrors: ${totals.errors}\n`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
output_1.output.write('Validation successful\n');
|
|
104
|
+
}
|
|
105
|
+
if (totals.warnings > 0) {
|
|
106
|
+
output_1.output.write(`Warnings: ${totals.warnings}\n`);
|
|
107
|
+
}
|
|
108
|
+
output_1.output.write('\n');
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case 'checkstyle': {
|
|
113
|
+
const groupedByFile = groupByFiles(problems);
|
|
114
|
+
output_1.output.write('<?xml version="1.0" encoding="UTF-8"?>\n');
|
|
115
|
+
output_1.output.write('<checkstyle version="4.3">\n');
|
|
116
|
+
for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
|
|
117
|
+
output_1.output.write(`<file name="${xmlEscape((0, ref_utils_1.isAbsoluteUrl)(file) ? file : path.relative(cwd, file))}">\n`);
|
|
118
|
+
fileProblems.forEach(formatCheckstyle);
|
|
119
|
+
output_1.output.write(`</file>\n`);
|
|
120
|
+
}
|
|
121
|
+
output_1.output.write(`</checkstyle>\n`);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case 'codeclimate':
|
|
125
|
+
outputForCodeClimate();
|
|
126
|
+
break;
|
|
127
|
+
case 'summary':
|
|
128
|
+
formatSummary(problems);
|
|
129
|
+
break;
|
|
130
|
+
case 'github-actions':
|
|
131
|
+
outputForGithubActions(problems, cwd);
|
|
132
|
+
}
|
|
133
|
+
if (totalProblems - ignoredProblems > maxProblems) {
|
|
134
|
+
logger_1.logger.info(`< ... ${totalProblems - maxProblems} more problems hidden > ${logger_1.colorize.gray('increase with `--max-problems N`')}\n`);
|
|
135
|
+
}
|
|
136
|
+
function outputForCodeClimate() {
|
|
137
|
+
const issues = problems.map((p) => {
|
|
138
|
+
const location = p.location[0]; // TODO: support multiple location
|
|
139
|
+
const lineCol = (0, codeframes_1.getLineColLocation)(location);
|
|
140
|
+
return {
|
|
141
|
+
description: p.message,
|
|
142
|
+
location: {
|
|
143
|
+
path: (0, ref_utils_1.isAbsoluteUrl)(location.source.absoluteRef)
|
|
144
|
+
? location.source.absoluteRef
|
|
145
|
+
: path.relative(cwd, location.source.absoluteRef),
|
|
146
|
+
lines: {
|
|
147
|
+
begin: lineCol.start.line,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
severity: CODECLIMATE_SEVERITY_MAPPING[p.severity],
|
|
151
|
+
fingerprint: `${p.ruleId}${p.location.length > 0 ? '-' + p.location[0].pointer : ''}`,
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
output_1.output.write(JSON.stringify(issues, null, 2));
|
|
155
|
+
}
|
|
156
|
+
function outputJSON() {
|
|
157
|
+
const resultObject = {
|
|
158
|
+
totals,
|
|
159
|
+
version,
|
|
160
|
+
problems: problems.map((p) => {
|
|
161
|
+
const problem = {
|
|
162
|
+
...p,
|
|
163
|
+
location: p.location.map((location) => ({
|
|
164
|
+
...location,
|
|
165
|
+
source: {
|
|
166
|
+
ref: (0, ref_utils_1.isAbsoluteUrl)(location.source.absoluteRef)
|
|
167
|
+
? location.source.absoluteRef
|
|
168
|
+
: path.relative(cwd, location.source.absoluteRef),
|
|
169
|
+
},
|
|
170
|
+
})),
|
|
171
|
+
from: p.from
|
|
172
|
+
? {
|
|
173
|
+
...p.from,
|
|
174
|
+
source: {
|
|
175
|
+
ref: (0, ref_utils_1.isAbsoluteUrl)(p.from?.source.absoluteRef)
|
|
176
|
+
? p.from?.source.absoluteRef
|
|
177
|
+
: path.relative(cwd, p.from?.source.absoluteRef || cwd),
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
: undefined,
|
|
181
|
+
};
|
|
182
|
+
if (env_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
|
|
183
|
+
const location = p.location[0]; // TODO: support multiple locations
|
|
184
|
+
const loc = (0, codeframes_1.getLineColLocation)(location);
|
|
185
|
+
problem.codeframe = (0, codeframes_1.getCodeframe)(loc, color);
|
|
186
|
+
}
|
|
187
|
+
return problem;
|
|
188
|
+
}),
|
|
189
|
+
};
|
|
190
|
+
output_1.output.write(JSON.stringify(resultObject, null, 2));
|
|
191
|
+
}
|
|
192
|
+
function getBgColor(problem) {
|
|
193
|
+
const { severity } = problem;
|
|
194
|
+
if (!BG_COLORS[severity]) {
|
|
195
|
+
throw new Error(ERROR_MESSAGE.INVALID_SEVERITY_LEVEL);
|
|
196
|
+
}
|
|
197
|
+
return BG_COLORS[severity];
|
|
198
|
+
}
|
|
199
|
+
function formatCodeframe(problem, idx) {
|
|
200
|
+
const bgColor = getBgColor(problem);
|
|
201
|
+
const location = problem.location[0]; // TODO: support multiple locations
|
|
202
|
+
const relativePath = (0, ref_utils_1.isAbsoluteUrl)(location.source.absoluteRef)
|
|
203
|
+
? location.source.absoluteRef
|
|
204
|
+
: path.relative(cwd, location.source.absoluteRef);
|
|
205
|
+
const loc = (0, codeframes_1.getLineColLocation)(location);
|
|
206
|
+
const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
|
|
207
|
+
const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
|
|
208
|
+
return (`[${idx + 1}] ${bgColor(fileWithLoc)} ${atPointer}\n\n` +
|
|
209
|
+
`${problem.message}\n\n` +
|
|
210
|
+
formatDidYouMean(problem) +
|
|
211
|
+
(0, codeframes_1.getCodeframe)(loc, color) +
|
|
212
|
+
'\n\n' +
|
|
213
|
+
formatFrom(cwd, problem.from) +
|
|
214
|
+
`${SEVERITY_NAMES[problem.severity]} was generated by the ${logger_1.colorize.blue(problem.ruleId)} rule.\n\n`);
|
|
215
|
+
}
|
|
216
|
+
function formatStylish(problem, locationPad, ruleIdPad) {
|
|
217
|
+
const color = COLORS[problem.severity];
|
|
218
|
+
if (!SEVERITY_NAMES[problem.severity]) {
|
|
219
|
+
return 'Error not found severity. Please check your config file. Allowed values: `warn,error,off`';
|
|
220
|
+
}
|
|
221
|
+
const severityName = color(SEVERITY_NAMES[problem.severity].toLowerCase().padEnd(7));
|
|
222
|
+
const { start } = problem.location[0];
|
|
223
|
+
return ` ${`${start.line}:${start.col}`.padEnd(locationPad)} ${severityName} ${problem.ruleId.padEnd(ruleIdPad)} ${problem.message}`;
|
|
224
|
+
}
|
|
225
|
+
function formatMarkdown(problem) {
|
|
226
|
+
if (!SEVERITY_NAMES[problem.severity]) {
|
|
227
|
+
return 'Error not found severity. Please check your config file. Allowed values: `warn,error,off`';
|
|
228
|
+
}
|
|
229
|
+
const severityName = SEVERITY_NAMES[problem.severity].toLowerCase();
|
|
230
|
+
const { start } = problem.location[0];
|
|
231
|
+
return `| ${severityName} | line ${`${start.line}:${start.col}`} | [${problem.ruleId}](https://redocly.com/docs/cli/rules/${problem.ruleId}/) | ${problem.message} |`;
|
|
232
|
+
}
|
|
233
|
+
function formatCheckstyle(problem) {
|
|
234
|
+
const { line, col } = problem.location[0].start;
|
|
235
|
+
const severity = problem.severity == 'warn' ? 'warning' : 'error';
|
|
236
|
+
const message = xmlEscape(problem.message);
|
|
237
|
+
const source = xmlEscape(problem.ruleId);
|
|
238
|
+
output_1.output.write(`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function formatSummary(problems) {
|
|
242
|
+
const counts = {};
|
|
243
|
+
for (const problem of problems) {
|
|
244
|
+
counts[problem.ruleId] = counts[problem.ruleId] || { count: 0, severity: problem.severity };
|
|
245
|
+
counts[problem.ruleId].count++;
|
|
246
|
+
}
|
|
247
|
+
const sorted = Object.entries(counts).sort(([, a], [, b]) => {
|
|
248
|
+
const severityDiff = severityToNumber(a.severity) - severityToNumber(b.severity);
|
|
249
|
+
return severityDiff || b.count - a.count;
|
|
250
|
+
});
|
|
251
|
+
for (const [ruleId, info] of sorted) {
|
|
252
|
+
const color = COLORS[info.severity];
|
|
253
|
+
const severityName = color(SEVERITY_NAMES[info.severity].toLowerCase().padEnd(7));
|
|
254
|
+
logger_1.logger.info(`${severityName} ${ruleId}: ${info.count}\n`);
|
|
255
|
+
}
|
|
256
|
+
logger_1.logger.info('\n');
|
|
257
|
+
}
|
|
258
|
+
function formatFrom(cwd, location) {
|
|
259
|
+
if (!location)
|
|
260
|
+
return '';
|
|
261
|
+
const relativePath = path.relative(cwd, location.source.absoluteRef);
|
|
262
|
+
const loc = (0, codeframes_1.getLineColLocation)(location);
|
|
263
|
+
const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
|
|
264
|
+
const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
|
|
265
|
+
return `referenced from ${logger_1.colorize.blue(fileWithLoc)} ${atPointer} \n\n`;
|
|
266
|
+
}
|
|
267
|
+
function formatDidYouMean(problem) {
|
|
268
|
+
if (problem.suggest.length === 0)
|
|
269
|
+
return '';
|
|
270
|
+
if (problem.suggest.length === 1) {
|
|
271
|
+
return `Did you mean: ${problem.suggest[0]} ?\n\n`;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
return `Did you mean:\n - ${problem.suggest.slice(0, MAX_SUGGEST).join('\n - ')}\n\n`;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const groupByFiles = (problems) => {
|
|
278
|
+
const fileGroups = {};
|
|
279
|
+
for (const problem of problems) {
|
|
280
|
+
const absoluteRef = problem.location[0].source.absoluteRef; // TODO: multiple errors
|
|
281
|
+
fileGroups[absoluteRef] = fileGroups[absoluteRef] || {
|
|
282
|
+
fileProblems: [],
|
|
283
|
+
ruleIdPad: 0,
|
|
284
|
+
locationPad: 0,
|
|
285
|
+
};
|
|
286
|
+
const mappedProblem = { ...problem, location: problem.location.map(codeframes_1.getLineColLocation) };
|
|
287
|
+
fileGroups[absoluteRef].fileProblems.push(mappedProblem);
|
|
288
|
+
fileGroups[absoluteRef].ruleIdPad = Math.max(problem.ruleId.length, fileGroups[absoluteRef].ruleIdPad);
|
|
289
|
+
fileGroups[absoluteRef].locationPad = Math.max(Math.max(...mappedProblem.location.map((loc) => `${loc.start.line}:${loc.start.col}`.length)), fileGroups[absoluteRef].locationPad);
|
|
290
|
+
}
|
|
291
|
+
return fileGroups;
|
|
292
|
+
};
|
|
293
|
+
function xmlEscape(s) {
|
|
294
|
+
// eslint-disable-next-line no-control-regex
|
|
295
|
+
return s.replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, (char) => {
|
|
296
|
+
switch (char) {
|
|
297
|
+
case '<':
|
|
298
|
+
return '<';
|
|
299
|
+
case '>':
|
|
300
|
+
return '>';
|
|
301
|
+
case '&':
|
|
302
|
+
return '&';
|
|
303
|
+
case '"':
|
|
304
|
+
return '"';
|
|
305
|
+
case "'":
|
|
306
|
+
return ''';
|
|
307
|
+
default:
|
|
308
|
+
return `&#${char.charCodeAt(0)};`;
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function outputForGithubActions(problems, cwd) {
|
|
313
|
+
for (const problem of problems) {
|
|
314
|
+
for (const location of problem.location.map(codeframes_1.getLineColLocation)) {
|
|
315
|
+
let command;
|
|
316
|
+
switch (problem.severity) {
|
|
317
|
+
case 'error':
|
|
318
|
+
command = 'error';
|
|
319
|
+
break;
|
|
320
|
+
case 'warn':
|
|
321
|
+
command = 'warning';
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
const suggest = formatDidYouMean(problem);
|
|
325
|
+
const message = suggest !== '' ? problem.message + '\n\n' + suggest : problem.message;
|
|
326
|
+
const properties = {
|
|
327
|
+
title: problem.ruleId,
|
|
328
|
+
file: (0, ref_utils_1.isAbsoluteUrl)(location.source.absoluteRef)
|
|
329
|
+
? location.source.absoluteRef
|
|
330
|
+
: path.relative(cwd, location.source.absoluteRef),
|
|
331
|
+
line: location.start.line,
|
|
332
|
+
col: location.start.col,
|
|
333
|
+
endLine: location.end?.line,
|
|
334
|
+
endColumn: location.end?.col,
|
|
335
|
+
};
|
|
336
|
+
output_1.output.write(`::${command} ${formatProperties(properties)}::${escapeMessage(message)}\n`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function formatProperties(props) {
|
|
340
|
+
return Object.entries(props)
|
|
341
|
+
.filter(([, v]) => v !== null && v !== undefined)
|
|
342
|
+
.map(([k, v]) => `${k}=${escapeProperty(v)}`)
|
|
343
|
+
.join(',');
|
|
344
|
+
}
|
|
345
|
+
function toString(v) {
|
|
346
|
+
if (v === null || v === undefined) {
|
|
347
|
+
return '';
|
|
348
|
+
}
|
|
349
|
+
else if (typeof v === 'string' || v instanceof String) {
|
|
350
|
+
return v;
|
|
351
|
+
}
|
|
352
|
+
return JSON.stringify(v);
|
|
353
|
+
}
|
|
354
|
+
function escapeMessage(v) {
|
|
355
|
+
return toString(v).replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
|
356
|
+
}
|
|
357
|
+
function escapeProperty(v) {
|
|
358
|
+
return toString(v)
|
|
359
|
+
.replace(/%/g, '%25')
|
|
360
|
+
.replace(/\r/g, '%0D')
|
|
361
|
+
.replace(/\n/g, '%0A')
|
|
362
|
+
.replace(/:/g, '%3A')
|
|
363
|
+
.replace(/,/g, '%2C');
|
|
364
|
+
}
|
|
365
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy, getProxyAgent, pause, } from './utils';
|
|
2
|
+
export { Oas3_1Types } from './types/oas3_1';
|
|
3
|
+
export { Arazzo1Types } from './types/arazzo';
|
|
4
|
+
export { Oas3Types } from './types/oas3';
|
|
5
|
+
export { Oas2Types } from './types/oas2';
|
|
6
|
+
export { AsyncApi2Types } from './types/asyncapi2';
|
|
7
|
+
export { AsyncApi3Types } from './types/asyncapi3';
|
|
8
|
+
export { ConfigTypes } from './types/redocly-yaml';
|
|
9
|
+
export type { Oas3Definition, Oas3_1Definition, Oas3Components, Oas3_1Components, Oas3PathItem, Oas3Paths, Oas3ComponentName, Oas3Schema, Oas3_1Schema, Oas3Tag, Referenced, OasRef, } from './typings/openapi';
|
|
10
|
+
export type { Oas2Definition } from './typings/swagger';
|
|
11
|
+
export type { StatsAccumulator, StatsName } from './typings/common';
|
|
12
|
+
export { normalizeTypes } from './types';
|
|
13
|
+
export { Stats } from './rules/other/stats';
|
|
14
|
+
export { Config, StyleguideConfig, RawConfig, RawUniversalConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity, createConfig, ResolvedApi, } from './config';
|
|
15
|
+
export { RedoclyClient } from './redocly';
|
|
16
|
+
export * from './redocly/domains';
|
|
17
|
+
export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
|
|
18
|
+
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
19
|
+
export { unescapePointer, isRef, isAbsoluteUrl } from './ref-utils';
|
|
20
|
+
export { SpecMajorVersion, getMajorSpecVersion, SpecVersion, detectSpec, getTypes, } from './oas-types';
|
|
21
|
+
export { normalizeVisitors } from './visitors';
|
|
22
|
+
export { WalkContext, walkDocument, NormalizedProblem, ProblemSeverity, LineColLocationObject, LocationObject, Loc, } from './walk';
|
|
23
|
+
export { getAstNodeByPointer, getLineColLocation } from './format/codeframes';
|
|
24
|
+
export { formatProblems, OutputFormat, getTotals, Totals } from './format/format';
|
|
25
|
+
export { lint, lint as validate, lintDocument, lintFromString, lintConfig } from './lint';
|
|
26
|
+
export { bundle, bundleDocument, mapTypeToComponent, bundleFromString } from './bundle';
|