@amritk/lint 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/core/document.js +12 -10
- package/dist/core/formats.js +10 -13
- package/dist/core/glob.js +96 -118
- package/dist/core/index.js +31 -11
- package/dist/core/jsonpath.js +487 -561
- package/dist/core/lint.js +78 -85
- package/dist/core/plugin.js +21 -29
- package/dist/core/pointers.js +107 -151
- package/dist/core/ruleset.js +0 -0
- package/dist/core/runner.js +214 -272
- package/dist/core/types.js +4 -1
- package/dist/core/validate-ruleset.js +98 -112
- package/dist/fix/apply.js +58 -96
- package/dist/fix/index.js +7 -2
- package/dist/fix/plugin.js +15 -20
- package/dist/functions/alphabetical.js +39 -50
- package/dist/functions/casing.js +39 -45
- package/dist/functions/defined.js +7 -5
- package/dist/functions/enumeration.js +15 -25
- package/dist/functions/falsy.js +7 -5
- package/dist/functions/index.js +60 -44
- package/dist/functions/length.js +22 -32
- package/dist/functions/or.js +18 -24
- package/dist/functions/pattern.js +39 -49
- package/dist/functions/schema.js +93 -119
- package/dist/functions/truthy.js +7 -5
- package/dist/functions/typed-enum.js +33 -36
- package/dist/functions/undefined.js +7 -8
- package/dist/functions/unreferenced-reusable-object.js +35 -47
- package/dist/functions/xor.js +13 -16
- package/dist/index.js +114 -164
- package/dist/parsers/edit-model.js +316 -444
- package/dist/parsers/index.js +22 -19
- package/dist/parsers/json.js +39 -37
- package/dist/parsers/lines.js +23 -26
- package/dist/parsers/types.js +9 -7
- package/dist/parsers/yaml.js +137 -204
- package/dist/rules/openapi/fixers.js +166 -221
- package/dist/rules/openapi/formats.js +26 -27
- package/dist/rules/openapi/functions/example-validation.js +98 -138
- package/dist/rules/openapi/functions/helpers.js +8 -10
- package/dist/rules/openapi/functions/index.js +98 -72
- package/dist/rules/openapi/functions/oas-additional-operations.js +16 -22
- package/dist/rules/openapi/functions/oas-discriminator.js +24 -22
- package/dist/rules/openapi/functions/oas-example-external-value.js +13 -21
- package/dist/rules/openapi/functions/oas-example-value.js +24 -27
- package/dist/rules/openapi/functions/oas-mutually-exclusive.js +15 -19
- package/dist/rules/openapi/functions/oas-no-nullable.js +13 -21
- package/dist/rules/openapi/functions/oas-op-form-data-consume-check.js +21 -19
- package/dist/rules/openapi/functions/oas-op-id-unique.js +27 -27
- package/dist/rules/openapi/functions/oas-op-params.js +36 -42
- package/dist/rules/openapi/functions/oas-op-security-defined.js +40 -39
- package/dist/rules/openapi/functions/oas-op-success-response.js +11 -13
- package/dist/rules/openapi/functions/oas-path-param.js +75 -96
- package/dist/rules/openapi/functions/oas-schema-example-deprecated.js +33 -40
- package/dist/rules/openapi/functions/oas-schema.js +9 -14
- package/dist/rules/openapi/functions/oas-server-name-unique.js +21 -19
- package/dist/rules/openapi/functions/oas-server-variables.js +45 -49
- package/dist/rules/openapi/functions/oas-tag-defined.js +20 -20
- package/dist/rules/openapi/functions/oas-tag-kind.js +16 -16
- package/dist/rules/openapi/functions/oas-tag-parent-defined.js +40 -43
- package/dist/rules/openapi/functions/oas-tags-unique.js +18 -16
- package/dist/rules/openapi/functions/oas-unused-component.js +48 -58
- package/dist/rules/openapi/functions/ref-siblings.js +13 -11
- package/dist/rules/openapi/index.js +99 -117
- package/dist/rules/openapi/oas.js +524 -536
- package/dist/rules/openapi/schemas/index.js +17 -33
- package/dist/rules/openapi/schemas/oas20.json +1 -1592
- package/dist/rules/openapi/schemas/oas30.json +1 -1651
- package/dist/rules/openapi/schemas/oas31.json +1 -1412
- package/dist/rules/openapi/schemas/oas32.json +1 -1684
- package/package.json +5 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 amritk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/core/document.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { parseWithPointers
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { parseWithPointers } from "../parsers/index.js";
|
|
2
|
+
const createDocument = (input, options = {}) => {
|
|
3
|
+
const parsed = parseWithPointers(input, options);
|
|
4
|
+
return {
|
|
5
|
+
source: options.source,
|
|
6
|
+
data: parsed.data,
|
|
7
|
+
diagnostics: parsed.diagnostics,
|
|
8
|
+
getLocationForJsonPath: (path, closest = false) => parsed.getLocationForJsonPath(path, closest)
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
createDocument
|
|
11
13
|
};
|
package/dist/core/formats.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
matched.add(name);
|
|
12
|
-
}
|
|
13
|
-
return matched;
|
|
1
|
+
const detectFormats = (document, formats = {}) => {
|
|
2
|
+
const matched = /* @__PURE__ */ new Set();
|
|
3
|
+
for (const [name, detector] of Object.entries(formats)) {
|
|
4
|
+
if (detector(document))
|
|
5
|
+
matched.add(name);
|
|
6
|
+
}
|
|
7
|
+
return matched;
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
detectFormats
|
|
14
11
|
};
|
package/dist/core/glob.js
CHANGED
|
@@ -1,132 +1,110 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal glob → RegExp for matching override `files` patterns against document
|
|
3
|
-
* paths. Supports `**` (any path segments), `*` (within a segment), `?`, and
|
|
4
|
-
* brace expansion (`{a,b}`).
|
|
5
|
-
*/
|
|
6
1
|
const REGEXP_SPECIAL = /[\\^$.*+?()[\]{}|/]/;
|
|
7
|
-
/** Splits brace-group content on top-level commas (commas nested in inner braces stay put). */
|
|
8
2
|
const splitTopLevel = (body) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
current += ch;
|
|
3
|
+
const parts = [];
|
|
4
|
+
let depth = 0;
|
|
5
|
+
let current = "";
|
|
6
|
+
for (const ch of body) {
|
|
7
|
+
if (ch === "{")
|
|
8
|
+
depth++;
|
|
9
|
+
else if (ch === "}")
|
|
10
|
+
depth--;
|
|
11
|
+
if (ch === "," && depth === 0) {
|
|
12
|
+
parts.push(current);
|
|
13
|
+
current = "";
|
|
14
|
+
continue;
|
|
23
15
|
}
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
current += ch;
|
|
17
|
+
}
|
|
18
|
+
parts.push(current);
|
|
19
|
+
return parts;
|
|
26
20
|
};
|
|
27
|
-
/**
|
|
28
|
-
* Expands brace alternations (`a.{yaml,yml}` → `a.yaml`, `a.yml`) into concrete
|
|
29
|
-
* globs, cartesian across multiple groups. A group with no top-level comma is
|
|
30
|
-
* left literal (mirroring minimatch), so `{}` in a path does not vanish.
|
|
31
|
-
*/
|
|
32
21
|
const expandBraces = (glob) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
22
|
+
const open = glob.indexOf("{");
|
|
23
|
+
if (open === -1)
|
|
24
|
+
return [glob];
|
|
25
|
+
let depth = 0;
|
|
26
|
+
let close = -1;
|
|
27
|
+
for (let i = open; i < glob.length; i++) {
|
|
28
|
+
if (glob[i] === "{")
|
|
29
|
+
depth++;
|
|
30
|
+
else if (glob[i] === "}") {
|
|
31
|
+
depth--;
|
|
32
|
+
if (depth === 0) {
|
|
33
|
+
close = i;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
48
36
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
37
|
+
}
|
|
38
|
+
if (close === -1)
|
|
39
|
+
return [glob];
|
|
40
|
+
const prefix = glob.slice(0, open);
|
|
41
|
+
const body = glob.slice(open + 1, close);
|
|
42
|
+
const suffix = glob.slice(close + 1);
|
|
43
|
+
const options = splitTopLevel(body);
|
|
44
|
+
if (options.length === 1) {
|
|
45
|
+
return expandBraces(suffix).map((rest) => `${prefix}{${body}}${rest}`);
|
|
46
|
+
}
|
|
47
|
+
const results = [];
|
|
48
|
+
for (const option of options) {
|
|
49
|
+
for (const expandedOption of expandBraces(option)) {
|
|
50
|
+
for (const expandedSuffix of expandBraces(suffix)) {
|
|
51
|
+
results.push(prefix + expandedOption + expandedSuffix);
|
|
52
|
+
}
|
|
58
53
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
for (const expandedOption of expandBraces(option)) {
|
|
62
|
-
for (const expandedSuffix of expandBraces(suffix)) {
|
|
63
|
-
results.push(prefix + expandedOption + expandedSuffix);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return results;
|
|
54
|
+
}
|
|
55
|
+
return results;
|
|
68
56
|
};
|
|
69
|
-
/** Compiles a single (brace-free) glob into an un-anchored RegExp source. */
|
|
70
57
|
const globInnerSource = (glob) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
source += '.*';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
source += '[^/]*';
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else if (char === '?') {
|
|
90
|
-
source += '[^/]';
|
|
91
|
-
}
|
|
92
|
-
else if (char && REGEXP_SPECIAL.test(char)) {
|
|
93
|
-
source += `\\${char}`;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
source += char;
|
|
58
|
+
let source = "";
|
|
59
|
+
for (let i = 0; i < glob.length; i++) {
|
|
60
|
+
const char = glob[i];
|
|
61
|
+
if (char === "*") {
|
|
62
|
+
if (glob[i + 1] === "*") {
|
|
63
|
+
i++;
|
|
64
|
+
if (glob[i + 1] === "/") {
|
|
65
|
+
i++;
|
|
66
|
+
source += "(?:.*/)?";
|
|
67
|
+
} else {
|
|
68
|
+
source += ".*";
|
|
97
69
|
}
|
|
70
|
+
} else {
|
|
71
|
+
source += "[^/]*";
|
|
72
|
+
}
|
|
73
|
+
} else if (char === "?") {
|
|
74
|
+
source += "[^/]";
|
|
75
|
+
} else if (char && REGEXP_SPECIAL.test(char)) {
|
|
76
|
+
source += `\\${char}`;
|
|
77
|
+
} else {
|
|
78
|
+
source += char;
|
|
98
79
|
}
|
|
99
|
-
|
|
80
|
+
}
|
|
81
|
+
return source;
|
|
100
82
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const regex = new RegExp(`^(?:${alternatives.join('|')})$`);
|
|
111
|
-
regexCache.set(glob, regex);
|
|
112
|
-
return regex;
|
|
83
|
+
const regexCache = /* @__PURE__ */ new Map();
|
|
84
|
+
const globToRegExp = (glob) => {
|
|
85
|
+
const cached = regexCache.get(glob);
|
|
86
|
+
if (cached)
|
|
87
|
+
return cached;
|
|
88
|
+
const alternatives = expandBraces(glob).map(globInnerSource);
|
|
89
|
+
const regex = new RegExp(`^(?:${alternatives.join("|")})$`);
|
|
90
|
+
regexCache.set(glob, regex);
|
|
91
|
+
return regex;
|
|
113
92
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
93
|
+
const matchesGlob = (path, patterns) => {
|
|
94
|
+
const basename = path.split("/").pop() ?? path;
|
|
95
|
+
return patterns.some((pattern) => {
|
|
96
|
+
const regex = globToRegExp(pattern);
|
|
97
|
+
if (regex.test(path))
|
|
98
|
+
return true;
|
|
99
|
+
if (!pattern.includes("/"))
|
|
100
|
+
return regex.test(basename);
|
|
101
|
+
if (!pattern.startsWith("/") && !pattern.startsWith("**")) {
|
|
102
|
+
return globToRegExp(`**/${pattern}`).test(path);
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
export {
|
|
108
|
+
globToRegExp,
|
|
109
|
+
matchesGlob
|
|
132
110
|
};
|
package/dist/core/index.js
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export * from
|
|
11
|
-
|
|
1
|
+
import { createDocument } from "./document.js";
|
|
2
|
+
import { detectFormats } from "./formats.js";
|
|
3
|
+
import { globToRegExp, matchesGlob } from "./glob.js";
|
|
4
|
+
import { compileQuery, query, queryCompiled, queryMany } from "./jsonpath.js";
|
|
5
|
+
import { lint, lintWithResult } from "./lint.js";
|
|
6
|
+
import { runPlugins } from "./plugin.js";
|
|
7
|
+
import { pointerToPath, resolveSourceOrigin, resolveSourceOriginFromMap, resolveSourcePath } from "./pointers.js";
|
|
8
|
+
import { createRuleset } from "./ruleset.js";
|
|
9
|
+
import { createLinter } from "./runner.js";
|
|
10
|
+
export * from "./types.js";
|
|
11
|
+
import { validateRuleset } from "./validate-ruleset.js";
|
|
12
|
+
export {
|
|
13
|
+
compileQuery,
|
|
14
|
+
createDocument,
|
|
15
|
+
createLinter,
|
|
16
|
+
createRuleset,
|
|
17
|
+
detectFormats,
|
|
18
|
+
globToRegExp,
|
|
19
|
+
lint,
|
|
20
|
+
lintWithResult,
|
|
21
|
+
matchesGlob,
|
|
22
|
+
pointerToPath,
|
|
23
|
+
query,
|
|
24
|
+
queryCompiled,
|
|
25
|
+
queryMany,
|
|
26
|
+
resolveSourceOrigin,
|
|
27
|
+
resolveSourceOriginFromMap,
|
|
28
|
+
resolveSourcePath,
|
|
29
|
+
runPlugins,
|
|
30
|
+
validateRuleset
|
|
31
|
+
};
|