@amritk/lint 0.6.1 → 0.6.2
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/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/dist/parsers/json.js +21 -2
- package/dist/parsers/yaml.js +8 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -140,8 +140,9 @@ export type IFixResult = {
|
|
|
140
140
|
};
|
|
141
141
|
/**
|
|
142
142
|
* Lints a document and applies the supplied `fixers` repeatedly until the
|
|
143
|
-
* document stops changing (or {@link MAX_FIX_PASSES} is reached)
|
|
144
|
-
*
|
|
143
|
+
* document stops changing (or {@link MAX_FIX_PASSES} is reached). `remaining`
|
|
144
|
+
* reflects the fixed document: the converging pass already linted it, so only
|
|
145
|
+
* a run that hit the cap lints once more. A one-call convenience over
|
|
145
146
|
* {@link lintDocumentWithResult} + `createFixPlugin`. With no `fixers` this is a
|
|
146
147
|
* no-op that just returns the findings.
|
|
147
148
|
*/
|
package/dist/index.js
CHANGED
|
@@ -83,10 +83,12 @@ const fixDocument = async (input, options = {}) => {
|
|
|
83
83
|
let converged = false;
|
|
84
84
|
const applied = [];
|
|
85
85
|
const seen = /* @__PURE__ */ new Set();
|
|
86
|
+
let convergedDiagnostics;
|
|
86
87
|
for (let pass = 0; pass < MAX_FIX_PASSES; pass++) {
|
|
87
88
|
const result = await runLint(current, ruleset, { ...lintOptions, plugins: [plugin] });
|
|
88
89
|
if (result.output === void 0 || result.output === current) {
|
|
89
90
|
converged = true;
|
|
91
|
+
convergedDiagnostics = result.diagnostics;
|
|
90
92
|
break;
|
|
91
93
|
}
|
|
92
94
|
current = result.output;
|
|
@@ -102,7 +104,7 @@ const fixDocument = async (input, options = {}) => {
|
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
|
-
const remaining = (await runLint(current, ruleset, lintOptions)).diagnostics;
|
|
107
|
+
const remaining = convergedDiagnostics ?? (await runLint(current, ruleset, lintOptions)).diagnostics;
|
|
106
108
|
return { output: current, fixed: current !== input, remaining, applied, converged, passes };
|
|
107
109
|
};
|
|
108
110
|
export {
|
package/dist/parsers/json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getNodeValue, parseTree, printParseErrorCode } from "jsonc-parser";
|
|
2
2
|
import { findExcessiveNesting, MAX_NESTING_DEPTH } from "./depth.js";
|
|
3
3
|
import { createLineMap } from "./lines.js";
|
|
4
4
|
import { DiagnosticSeverity } from "./types.js";
|
|
@@ -35,7 +35,7 @@ const parseJson = (source) => {
|
|
|
35
35
|
return void 0;
|
|
36
36
|
const p = path.slice();
|
|
37
37
|
while (true) {
|
|
38
|
-
const node =
|
|
38
|
+
const node = findNode(root, p);
|
|
39
39
|
if (node) {
|
|
40
40
|
return {
|
|
41
41
|
range: {
|
|
@@ -51,6 +51,25 @@ const parseJson = (source) => {
|
|
|
51
51
|
};
|
|
52
52
|
return { data, diagnostics, getLocationForJsonPath };
|
|
53
53
|
};
|
|
54
|
+
const ARRAY_INDEX = /^(?:0|[1-9]\d*)$/;
|
|
55
|
+
const findNode = (root, path) => {
|
|
56
|
+
let node = root;
|
|
57
|
+
for (const segment of path) {
|
|
58
|
+
if (node === void 0)
|
|
59
|
+
return void 0;
|
|
60
|
+
if (node.type === "object") {
|
|
61
|
+
const key = String(segment);
|
|
62
|
+
const property = node.children?.find((child) => child.children?.length === 2 && child.children[0]?.value === key);
|
|
63
|
+
node = property?.children?.[1];
|
|
64
|
+
} else if (node.type === "array") {
|
|
65
|
+
const text = String(segment);
|
|
66
|
+
node = ARRAY_INDEX.test(text) ? node.children?.[Number(text)] : void 0;
|
|
67
|
+
} else {
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return node;
|
|
72
|
+
};
|
|
54
73
|
export {
|
|
55
74
|
parseJson
|
|
56
75
|
};
|
package/dist/parsers/yaml.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { isAlias, isMap, isPair, isScalar, isSeq, parseAllDocuments } from "@amritk/yaml";
|
|
2
2
|
import { createLineMap } from "./lines.js";
|
|
3
3
|
import { DiagnosticSeverity } from "./types.js";
|
|
4
|
-
const pathKey = (path) =>
|
|
4
|
+
const pathKey = (path) => {
|
|
5
|
+
let key = "";
|
|
6
|
+
for (const segment of path) {
|
|
7
|
+
const text = String(segment);
|
|
8
|
+
key += `${text.length}:${text}`;
|
|
9
|
+
}
|
|
10
|
+
return key;
|
|
11
|
+
};
|
|
5
12
|
const serializeComplexKey = (node) => {
|
|
6
13
|
if (isSeq(node)) {
|
|
7
14
|
return node.items.length === 0 ? "[]" : `[ ${node.items.map(flowText).join(", ")} ]`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/lint",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "A fast, format-agnostic JSON/YAML style-guide linter with JSON Schema and custom rules.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -69,12 +69,12 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@amritk/runtime-validators": "^0.15.
|
|
73
|
-
"@amritk/yaml": "^0.7.
|
|
72
|
+
"@amritk/runtime-validators": "^0.15.1",
|
|
73
|
+
"@amritk/yaml": "^0.7.3",
|
|
74
74
|
"jsonc-parser": "^3.3.1"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@amritk/resolve-refs": "^0.
|
|
77
|
+
"@amritk/resolve-refs": "^0.8.0",
|
|
78
78
|
"@stoplight/spectral-core": "^1.23.1",
|
|
79
79
|
"@stoplight/spectral-parsers": "^1.0.5",
|
|
80
80
|
"@stoplight/spectral-rulesets": "^1.22.7"
|