@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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/dist/core/document.js +12 -10
  3. package/dist/core/formats.js +10 -13
  4. package/dist/core/glob.js +96 -118
  5. package/dist/core/index.js +31 -11
  6. package/dist/core/jsonpath.js +487 -561
  7. package/dist/core/lint.js +78 -85
  8. package/dist/core/plugin.js +21 -29
  9. package/dist/core/pointers.js +107 -151
  10. package/dist/core/ruleset.js +0 -0
  11. package/dist/core/runner.js +214 -272
  12. package/dist/core/types.js +4 -1
  13. package/dist/core/validate-ruleset.js +98 -112
  14. package/dist/fix/apply.js +58 -96
  15. package/dist/fix/index.js +7 -2
  16. package/dist/fix/plugin.js +15 -20
  17. package/dist/functions/alphabetical.js +39 -50
  18. package/dist/functions/casing.js +39 -45
  19. package/dist/functions/defined.js +7 -5
  20. package/dist/functions/enumeration.js +15 -25
  21. package/dist/functions/falsy.js +7 -5
  22. package/dist/functions/index.js +60 -44
  23. package/dist/functions/length.js +22 -32
  24. package/dist/functions/or.js +18 -24
  25. package/dist/functions/pattern.js +39 -49
  26. package/dist/functions/schema.js +93 -119
  27. package/dist/functions/truthy.js +7 -5
  28. package/dist/functions/typed-enum.js +33 -36
  29. package/dist/functions/undefined.js +7 -8
  30. package/dist/functions/unreferenced-reusable-object.js +35 -47
  31. package/dist/functions/xor.js +13 -16
  32. package/dist/index.js +114 -164
  33. package/dist/parsers/edit-model.js +316 -444
  34. package/dist/parsers/index.js +22 -19
  35. package/dist/parsers/json.js +39 -37
  36. package/dist/parsers/lines.js +23 -26
  37. package/dist/parsers/types.js +9 -7
  38. package/dist/parsers/yaml.js +137 -204
  39. package/dist/rules/openapi/fixers.js +166 -221
  40. package/dist/rules/openapi/formats.js +26 -27
  41. package/dist/rules/openapi/functions/example-validation.js +98 -138
  42. package/dist/rules/openapi/functions/helpers.js +8 -10
  43. package/dist/rules/openapi/functions/index.js +98 -72
  44. package/dist/rules/openapi/functions/oas-additional-operations.js +16 -22
  45. package/dist/rules/openapi/functions/oas-discriminator.js +24 -22
  46. package/dist/rules/openapi/functions/oas-example-external-value.js +13 -21
  47. package/dist/rules/openapi/functions/oas-example-value.js +24 -27
  48. package/dist/rules/openapi/functions/oas-mutually-exclusive.js +15 -19
  49. package/dist/rules/openapi/functions/oas-no-nullable.js +13 -21
  50. package/dist/rules/openapi/functions/oas-op-form-data-consume-check.js +21 -19
  51. package/dist/rules/openapi/functions/oas-op-id-unique.js +27 -27
  52. package/dist/rules/openapi/functions/oas-op-params.js +36 -42
  53. package/dist/rules/openapi/functions/oas-op-security-defined.js +40 -39
  54. package/dist/rules/openapi/functions/oas-op-success-response.js +11 -13
  55. package/dist/rules/openapi/functions/oas-path-param.js +75 -96
  56. package/dist/rules/openapi/functions/oas-schema-example-deprecated.js +33 -40
  57. package/dist/rules/openapi/functions/oas-schema.js +9 -14
  58. package/dist/rules/openapi/functions/oas-server-name-unique.js +21 -19
  59. package/dist/rules/openapi/functions/oas-server-variables.js +45 -49
  60. package/dist/rules/openapi/functions/oas-tag-defined.js +20 -20
  61. package/dist/rules/openapi/functions/oas-tag-kind.js +16 -16
  62. package/dist/rules/openapi/functions/oas-tag-parent-defined.js +40 -43
  63. package/dist/rules/openapi/functions/oas-tags-unique.js +18 -16
  64. package/dist/rules/openapi/functions/oas-unused-component.js +48 -58
  65. package/dist/rules/openapi/functions/ref-siblings.js +13 -11
  66. package/dist/rules/openapi/index.js +99 -117
  67. package/dist/rules/openapi/oas.js +524 -536
  68. package/dist/rules/openapi/schemas/index.js +17 -33
  69. package/dist/rules/openapi/schemas/oas20.json +1 -1592
  70. package/dist/rules/openapi/schemas/oas30.json +1 -1651
  71. package/dist/rules/openapi/schemas/oas31.json +1 -1412
  72. package/dist/rules/openapi/schemas/oas32.json +1 -1684
  73. 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.
@@ -1,11 +1,13 @@
1
- import { parseWithPointers, } from '../parsers/index.js';
2
- /** Parses `input` into a {@link Document} with a source map for position lookups. */
3
- export const createDocument = (input, options = {}) => {
4
- const parsed = parseWithPointers(input, options);
5
- return {
6
- source: options.source,
7
- data: parsed.data,
8
- diagnostics: parsed.diagnostics,
9
- getLocationForJsonPath: (path, closest = false) => parsed.getLocationForJsonPath(path, closest),
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
  };
@@ -1,14 +1,11 @@
1
- /**
2
- * Returns the set of registered format names that match the document. The
3
- * `formats` registry is supplied by the caller (a preset provides its own
4
- * format detectors); the engine itself is format-agnostic, so the
5
- * default registry is empty and rules with no `formats` gate run regardless.
6
- */
7
- export const detectFormats = (document, formats = {}) => {
8
- const matched = new Set();
9
- for (const [name, detector] of Object.entries(formats)) {
10
- if (detector(document))
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
- const parts = [];
10
- let depth = 0;
11
- let current = '';
12
- for (const ch of body) {
13
- if (ch === '{')
14
- depth++;
15
- else if (ch === '}')
16
- depth--;
17
- if (ch === ',' && depth === 0) {
18
- parts.push(current);
19
- current = '';
20
- continue;
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
- parts.push(current);
25
- return parts;
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
- const open = glob.indexOf('{');
34
- if (open === -1)
35
- return [glob];
36
- let depth = 0;
37
- let close = -1;
38
- for (let i = open; i < glob.length; i++) {
39
- if (glob[i] === '{')
40
- depth++;
41
- else if (glob[i] === '}') {
42
- depth--;
43
- if (depth === 0) {
44
- close = i;
45
- break;
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
- if (close === -1)
50
- return [glob];
51
- const prefix = glob.slice(0, open);
52
- const body = glob.slice(open + 1, close);
53
- const suffix = glob.slice(close + 1);
54
- const options = splitTopLevel(body);
55
- if (options.length === 1) {
56
- // No alternation keep the braces as literal characters.
57
- return expandBraces(suffix).map((rest) => `${prefix}{${body}}${rest}`);
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
- const results = [];
60
- for (const option of options) {
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
- let source = '';
72
- for (let i = 0; i < glob.length; i++) {
73
- const char = glob[i];
74
- if (char === '*') {
75
- if (glob[i + 1] === '*') {
76
- i++;
77
- if (glob[i + 1] === '/') {
78
- i++;
79
- source += '(?:.*/)?';
80
- }
81
- else {
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
- return source;
80
+ }
81
+ return source;
100
82
  };
101
- // Compiled patterns are cached by their glob string; the ruleset's override
102
- // globs are re-tested against every linted source, so compiling once matters.
103
- const regexCache = new Map();
104
- /** Compiles a glob pattern (`**`, `*`, `?`, `{a,b}`) into an anchored RegExp, cached by string. */
105
- export const globToRegExp = (glob) => {
106
- const cached = regexCache.get(glob);
107
- if (cached)
108
- return cached;
109
- const alternatives = expandBraces(glob).map(globInnerSource);
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
- /** Returns true if `path` matches any of the glob patterns. */
115
- export const matchesGlob = (path, patterns) => {
116
- const basename = path.split('/').pop() ?? path;
117
- return patterns.some((pattern) => {
118
- const regex = globToRegExp(pattern);
119
- if (regex.test(path))
120
- return true;
121
- // A pattern without a slash also matches the basename.
122
- if (!pattern.includes('/'))
123
- return regex.test(basename);
124
- // A relative pattern that contains a slash matches an absolute source by
125
- // suffix, so `src/api.yaml` matches `/home/user/repo/src/api.yaml` — the
126
- // minimatch/Spectral behavior for override globs against absolute paths.
127
- if (!pattern.startsWith('/') && !pattern.startsWith('**')) {
128
- return globToRegExp(`**/${pattern}`).test(path);
129
- }
130
- return false;
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
  };
@@ -1,11 +1,31 @@
1
- export { createDocument } from './document.js';
2
- export { detectFormats } from './formats.js';
3
- export { globToRegExp, matchesGlob } from './glob.js';
4
- export { compileQuery, query, queryCompiled, queryMany } from './jsonpath.js';
5
- export { lint, lintWithResult, } from './lint.js';
6
- export { runPlugins, } from './plugin.js';
7
- export { pointerToPath, resolveSourceOrigin, resolveSourceOriginFromMap, resolveSourcePath, } from './pointers.js';
8
- export { createRuleset, } from './ruleset.js';
9
- export { createLinter } from './runner.js';
10
- export * from './types.js';
11
- export { validateRuleset } from './validate-ruleset.js';
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
+ };