sitecore-lint 0.1.0 → 0.1.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/README.md +26 -19
- package/dist/api.d.ts +64 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +114 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +73 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +284 -0
- package/dist/config.js.map +1 -0
- package/dist/configs/all.d.ts +14 -0
- package/dist/configs/all.d.ts.map +1 -0
- package/dist/configs/all.js +60 -0
- package/dist/configs/all.js.map +1 -0
- package/dist/configs/recommended.d.ts +11 -0
- package/dist/configs/recommended.d.ts.map +1 -0
- package/dist/configs/recommended.js +57 -0
- package/dist/configs/recommended.js.map +1 -0
- package/dist/configs/rule-metadata.d.ts +10 -0
- package/dist/configs/rule-metadata.d.ts.map +1 -0
- package/dist/configs/rule-metadata.js +157 -0
- package/dist/configs/rule-metadata.js.map +1 -0
- package/dist/configs/strict.d.ts +13 -0
- package/dist/configs/strict.d.ts.map +1 -0
- package/dist/configs/strict.js +59 -0
- package/dist/configs/strict.js.map +1 -0
- package/dist/generated/version.d.ts +2 -0
- package/dist/generated/version.d.ts.map +1 -0
- package/dist/generated/version.js +6 -0
- package/dist/generated/version.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +321 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +8 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +43 -0
- package/dist/init.js.map +1 -0
- package/dist/output/github.d.ts +13 -0
- package/dist/output/github.d.ts.map +1 -0
- package/dist/output/github.js +47 -0
- package/dist/output/github.js.map +1 -0
- package/dist/output/json.d.ts +26 -0
- package/dist/output/json.d.ts.map +1 -0
- package/dist/output/json.js +38 -0
- package/dist/output/json.js.map +1 -0
- package/dist/output/junit.d.ts +14 -0
- package/dist/output/junit.d.ts.map +1 -0
- package/dist/output/junit.js +65 -0
- package/dist/output/junit.js.map +1 -0
- package/dist/output/sarif.d.ts +11 -0
- package/dist/output/sarif.d.ts.map +1 -0
- package/dist/output/sarif.js +113 -0
- package/dist/output/sarif.js.map +1 -0
- package/dist/output/text.d.ts +12 -0
- package/dist/output/text.d.ts.map +1 -0
- package/dist/output/text.js +52 -0
- package/dist/output/text.js.map +1 -0
- package/dist/plugins.d.ts +74 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +67 -0
- package/dist/plugins.js.map +1 -0
- package/dist/presets.d.ts +13 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/presets.js +19 -0
- package/dist/presets.js.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -78,31 +78,38 @@ Accepted severity values: `"error"` · `"warning"` · `"info"` · `"off"`
|
|
|
78
78
|
## CLI reference
|
|
79
79
|
|
|
80
80
|
```text
|
|
81
|
-
Usage: sitecore-lint [options]
|
|
81
|
+
Usage: sitecore-lint [options] [command]
|
|
82
82
|
|
|
83
83
|
Options:
|
|
84
|
-
-c, --config <path>
|
|
85
|
-
--sitecore-json <path>
|
|
86
|
-
--format <stylish|json|junit|github> Output format (default: stylish)
|
|
87
|
-
-q, --quiet
|
|
88
|
-
--max-errors <n>
|
|
89
|
-
--fix
|
|
90
|
-
--verbose
|
|
91
|
-
--debug
|
|
92
|
-
--cache
|
|
93
|
-
--cache-location <path>
|
|
94
|
-
-
|
|
95
|
-
-
|
|
84
|
+
-c, --config <path> Path to config file (auto-discovered when omitted)
|
|
85
|
+
--sitecore-json <path> Path to sitecore.json for zero-config discovery
|
|
86
|
+
--format <stylish|json|junit|github|sarif> Output format (default: stylish)
|
|
87
|
+
-q, --quiet Suppress output; only set exit code
|
|
88
|
+
--max-errors <n> Exit 1 only when N or more errors are found
|
|
89
|
+
--fix Report fixable rules (auto-fix stub)
|
|
90
|
+
--verbose Print rule descriptions alongside diagnostics
|
|
91
|
+
--debug Print debug information to stderr
|
|
92
|
+
--cache Enable incremental lint cache
|
|
93
|
+
--cache-location <path> Path to the cache file
|
|
94
|
+
--list-rules Print all built-in rules with descriptions and exit
|
|
95
|
+
-o, --output-file <path> Write output to a file instead of stdout
|
|
96
|
+
--stats Print scan summary statistics to stderr
|
|
97
|
+
-V, --version Show version
|
|
98
|
+
-h, --help Show help
|
|
99
|
+
|
|
100
|
+
Commands:
|
|
101
|
+
init Create a .sitecore-lint.json config file
|
|
96
102
|
```
|
|
97
103
|
|
|
98
104
|
### Output formats
|
|
99
105
|
|
|
100
|
-
| Format | Description
|
|
101
|
-
| --------- |
|
|
102
|
-
| `stylish` | Human-readable grouped output with icons (default)
|
|
103
|
-
| `json` | `{ summary, diagnostics }` JSON for downstream tooling
|
|
104
|
-
| `junit` | JUnit XML for CI artifact reporters (e.g. GitHub Actions test reporter)
|
|
105
|
-
| `github` | GitHub Actions `::error` / `::warning` / `::notice` annotations
|
|
106
|
+
| Format | Description |
|
|
107
|
+
| --------- | ----------------------------------------------------------------------------------------------- |
|
|
108
|
+
| `stylish` | Human-readable grouped output with icons (default) |
|
|
109
|
+
| `json` | `{ summary, diagnostics }` JSON for downstream tooling |
|
|
110
|
+
| `junit` | JUnit XML for CI artifact reporters (e.g. GitHub Actions test reporter) |
|
|
111
|
+
| `github` | GitHub Actions `::error` / `::warning` / `::notice` annotations |
|
|
112
|
+
| `sarif` | [SARIF 2.1.0](https://sarifweb.azurewebsites.net/) for GitHub Code Scanning and other consumers |
|
|
106
113
|
|
|
107
114
|
### Exit codes
|
|
108
115
|
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sitecore-lint — public programmatic API
|
|
3
|
+
*
|
|
4
|
+
* Import from this package to consume the linter as a Node.js library:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { lintAsync, loadConfig } from 'sitecore-lint/api';
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export type { JsItem, JsDiagnostic } from '@sitecore-lint/engine';
|
|
11
|
+
export { lint, lintFromSitecoreJson, lintWithIar, loadItems } from '@sitecore-lint/engine';
|
|
12
|
+
export type { Config, RuleConfig, Severity } from './config';
|
|
13
|
+
export { loadConfig, findConfig, normaliseSeverity } from './config';
|
|
14
|
+
export { recommended } from './configs/recommended';
|
|
15
|
+
export { strict } from './configs/strict';
|
|
16
|
+
export { all } from './configs/all';
|
|
17
|
+
import type { JsDiagnostic } from '@sitecore-lint/engine';
|
|
18
|
+
export interface LintOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Glob patterns for Sitecore serialized YAML item files, resolved relative
|
|
21
|
+
* to `cwd` (default: `process.cwd()`).
|
|
22
|
+
* Overrides any `sources` in the loaded config.
|
|
23
|
+
*/
|
|
24
|
+
paths?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Path to a `.sitecore-lint.*` config file. When omitted, auto-discovery
|
|
27
|
+
* walks up from `cwd`.
|
|
28
|
+
*/
|
|
29
|
+
config?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Path to a `sitecore.json` project manifest for zero-config mode.
|
|
32
|
+
* When provided, `paths` / `config` are ignored.
|
|
33
|
+
*/
|
|
34
|
+
sitecoreJson?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Output format passed to the CLI. Has no effect in programmatic use
|
|
37
|
+
* (callers receive raw `JsDiagnostic[]`), but is included so that option
|
|
38
|
+
* objects built for CLI invocation can be reused here without stripping
|
|
39
|
+
* unsupported keys.
|
|
40
|
+
*/
|
|
41
|
+
format?: 'stylish' | 'json' | 'junit' | 'github';
|
|
42
|
+
/**
|
|
43
|
+
* Per-rule severity overrides. Values accepted: `"error"`, `"warning"`,
|
|
44
|
+
* `"info"`, `"off"`. `"off"` disables the rule entirely.
|
|
45
|
+
*/
|
|
46
|
+
rules?: Record<string, string>;
|
|
47
|
+
/** Working directory used for glob resolution and config discovery (default: `process.cwd()`). */
|
|
48
|
+
cwd?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Run the Sitecore linter programmatically and return all diagnostics.
|
|
52
|
+
*
|
|
53
|
+
* Combines config loading, engine invocation, and — when `sitecoreJson` is
|
|
54
|
+
* provided — zero-config mode via `lintFromSitecoreJson`.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { lintAsync } from 'sitecore-lint/api';
|
|
58
|
+
*
|
|
59
|
+
* const diagnostics = await lintAsync({ sitecoreJson: './sitecore.json' });
|
|
60
|
+
* const errors = diagnostics.filter(d => d.severity === 'error');
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function lintAsync(options?: LintOptions): Promise<JsDiagnostic[]>;
|
|
64
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAM3F,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAMrE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAM1D,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IACjD;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,kGAAkG;IAClG,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,SAAS,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CA6FlF"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* sitecore-lint — public programmatic API
|
|
4
|
+
*
|
|
5
|
+
* Import from this package to consume the linter as a Node.js library:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { lintAsync, loadConfig } from 'sitecore-lint/api';
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.all = exports.strict = exports.recommended = exports.normaliseSeverity = exports.findConfig = exports.loadConfig = exports.loadItems = exports.lintWithIar = exports.lintFromSitecoreJson = exports.lint = void 0;
|
|
13
|
+
exports.lintAsync = lintAsync;
|
|
14
|
+
var engine_1 = require("@sitecore-lint/engine");
|
|
15
|
+
Object.defineProperty(exports, "lint", { enumerable: true, get: function () { return engine_1.lint; } });
|
|
16
|
+
Object.defineProperty(exports, "lintFromSitecoreJson", { enumerable: true, get: function () { return engine_1.lintFromSitecoreJson; } });
|
|
17
|
+
Object.defineProperty(exports, "lintWithIar", { enumerable: true, get: function () { return engine_1.lintWithIar; } });
|
|
18
|
+
Object.defineProperty(exports, "loadItems", { enumerable: true, get: function () { return engine_1.loadItems; } });
|
|
19
|
+
var config_1 = require("./config");
|
|
20
|
+
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_1.loadConfig; } });
|
|
21
|
+
Object.defineProperty(exports, "findConfig", { enumerable: true, get: function () { return config_1.findConfig; } });
|
|
22
|
+
Object.defineProperty(exports, "normaliseSeverity", { enumerable: true, get: function () { return config_1.normaliseSeverity; } });
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Re-export shareable config presets
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
var recommended_1 = require("./configs/recommended");
|
|
27
|
+
Object.defineProperty(exports, "recommended", { enumerable: true, get: function () { return recommended_1.recommended; } });
|
|
28
|
+
var strict_1 = require("./configs/strict");
|
|
29
|
+
Object.defineProperty(exports, "strict", { enumerable: true, get: function () { return strict_1.strict; } });
|
|
30
|
+
var all_1 = require("./configs/all");
|
|
31
|
+
Object.defineProperty(exports, "all", { enumerable: true, get: function () { return all_1.all; } });
|
|
32
|
+
const node_path_1 = require("node:path");
|
|
33
|
+
const node_fs_1 = require("node:fs");
|
|
34
|
+
const config_2 = require("./config");
|
|
35
|
+
/**
|
|
36
|
+
* Run the Sitecore linter programmatically and return all diagnostics.
|
|
37
|
+
*
|
|
38
|
+
* Combines config loading, engine invocation, and — when `sitecoreJson` is
|
|
39
|
+
* provided — zero-config mode via `lintFromSitecoreJson`.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { lintAsync } from 'sitecore-lint/api';
|
|
43
|
+
*
|
|
44
|
+
* const diagnostics = await lintAsync({ sitecoreJson: './sitecore.json' });
|
|
45
|
+
* const errors = diagnostics.filter(d => d.severity === 'error');
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
async function lintAsync(options = {}) {
|
|
49
|
+
// Lazy-load the native engine to keep the top-level import non-throwing when
|
|
50
|
+
// the addon is not yet built (e.g. during type-checking only).
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
52
|
+
const engine = require('@sitecore-lint/engine');
|
|
53
|
+
const cwd = options.cwd ?? process.cwd();
|
|
54
|
+
// ── Zero-config mode ──
|
|
55
|
+
if (options.sitecoreJson) {
|
|
56
|
+
const sitecoreJsonPath = (0, node_path_1.resolve)(cwd, options.sitecoreJson);
|
|
57
|
+
if (!(0, node_fs_1.existsSync)(sitecoreJsonPath)) {
|
|
58
|
+
throw new Error(`sitecore-lint: sitecore.json not found: ${sitecoreJsonPath}`);
|
|
59
|
+
}
|
|
60
|
+
const disabledRules = buildDisabledRules(options.rules);
|
|
61
|
+
return engine.lintFromSitecoreJson(sitecoreJsonPath, disabledRules.length ? disabledRules : undefined);
|
|
62
|
+
}
|
|
63
|
+
// ── Config-file mode ──
|
|
64
|
+
let configPath;
|
|
65
|
+
if (options.config) {
|
|
66
|
+
configPath = (0, node_path_1.resolve)(cwd, options.config);
|
|
67
|
+
if (!(0, node_fs_1.existsSync)(configPath)) {
|
|
68
|
+
throw new Error(`sitecore-lint: config file not found: ${configPath}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const discovered = (0, config_2.findConfig)(cwd);
|
|
73
|
+
if (!discovered) {
|
|
74
|
+
throw new Error('sitecore-lint: no config file found. Create .sitecore-lint.json/.yml/.yaml/.js or pass the config option.');
|
|
75
|
+
}
|
|
76
|
+
configPath = discovered;
|
|
77
|
+
}
|
|
78
|
+
const config = (0, config_2.loadConfig)(configPath);
|
|
79
|
+
const configDir = (0, node_path_1.dirname)(configPath);
|
|
80
|
+
// Merge per-rule overrides from options into config rules.
|
|
81
|
+
const mergedRules = {
|
|
82
|
+
...(config.rules ?? {}),
|
|
83
|
+
...(options.rules ?? {}),
|
|
84
|
+
};
|
|
85
|
+
// Build disabled rules list.
|
|
86
|
+
const disabledRules = buildDisabledRules(mergedRules);
|
|
87
|
+
// Resolve source globs.
|
|
88
|
+
const sourcePaths = options.paths ?? config.sources ?? [];
|
|
89
|
+
if (sourcePaths.length === 0 && !config.sitecoreJson) {
|
|
90
|
+
throw new Error('sitecore-lint: no sources configured. Provide "paths" or add "sources" to your config.');
|
|
91
|
+
}
|
|
92
|
+
if (config.sitecoreJson) {
|
|
93
|
+
const sitecoreJsonPath = (0, node_path_1.resolve)(configDir, config.sitecoreJson);
|
|
94
|
+
return engine.lintFromSitecoreJson(sitecoreJsonPath, disabledRules.length ? disabledRules : undefined);
|
|
95
|
+
}
|
|
96
|
+
const resolvedGlobs = sourcePaths.map((g) => (0, node_path_1.join)(configDir, g));
|
|
97
|
+
const resolvedModuleGlobs = (config.modules ?? []).map((g) => (0, node_path_1.join)(configDir, g));
|
|
98
|
+
const resolvedIarGlobs = (config.iar ?? []).map((g) => (0, node_path_1.join)(configDir, g));
|
|
99
|
+
if (resolvedIarGlobs.length > 0) {
|
|
100
|
+
return engine.lintWithIar(resolvedGlobs, resolvedIarGlobs, resolvedModuleGlobs.length ? resolvedModuleGlobs : undefined, disabledRules.length ? disabledRules : undefined);
|
|
101
|
+
}
|
|
102
|
+
return engine.lint(resolvedGlobs, resolvedModuleGlobs.length ? resolvedModuleGlobs : undefined, disabledRules.length ? disabledRules : undefined);
|
|
103
|
+
}
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Internal helpers
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
function buildDisabledRules(rules) {
|
|
108
|
+
if (!rules)
|
|
109
|
+
return [];
|
|
110
|
+
return Object.entries(rules)
|
|
111
|
+
.filter(([, cfg]) => (0, config_2.normaliseSeverity)(cfg) === 'off')
|
|
112
|
+
.map(([name]) => name);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAgFH,8BA6FC;AAtKD,gDAA2F;AAAlF,8FAAA,IAAI,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,qGAAA,WAAW,OAAA;AAA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,IAAA,0BAAiB,EAAC,GAA8C,CAAC,KAAK,KAAK,CACzF;SACA,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Severity values accepted in config (REQ-003). */
|
|
2
|
+
export type Severity = 'error' | 'warning' | 'info' | 'off';
|
|
3
|
+
/**
|
|
4
|
+
* Per-rule configuration value.
|
|
5
|
+
*
|
|
6
|
+
* Accepted forms:
|
|
7
|
+
* - `"error"` | `"warning"` | `"info"` | `"off"` — string severity (REQ-003)
|
|
8
|
+
* - `[string, Record<string, unknown>]` — severity + options tuple (future use)
|
|
9
|
+
*/
|
|
10
|
+
export type RuleConfig = Severity | [Severity, Record<string, unknown>];
|
|
11
|
+
export interface Config {
|
|
12
|
+
/** Glob patterns for Sitecore serialized YAML item files. Optional when --sitecore-json is used (REQ-004). */
|
|
13
|
+
sources?: string[];
|
|
14
|
+
/** Optional path to a sitecore.json manifest (REQ-004). */
|
|
15
|
+
sitecoreJson?: string;
|
|
16
|
+
/** Optional glob patterns for Sitecore CLI `.module.json` files. When omitted, no module-aware rules run. */
|
|
17
|
+
modules?: string[];
|
|
18
|
+
/** Optional glob patterns for IAR `.dat` binary item archives. */
|
|
19
|
+
iar?: string[];
|
|
20
|
+
/** Per-rule configuration keyed by rule name, e.g. `"helix/layer-dependency"` or `"component-name"`. */
|
|
21
|
+
rules?: {
|
|
22
|
+
[name: string]: RuleConfig;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Optional list of plugin module paths (resolvable via `require()`).
|
|
26
|
+
* Each plugin must export a `rules` property that is an array of `JsRule` objects.
|
|
27
|
+
*/
|
|
28
|
+
plugins?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* List of shareable config references to extend (REQ-002).
|
|
31
|
+
* Built-in preset: `"sitecore-lint/configs/recommended"`.
|
|
32
|
+
* Processed left-to-right; later entries and user overrides win.
|
|
33
|
+
*/
|
|
34
|
+
extends?: string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalise any accepted `RuleConfig` value into a `Severity` string.
|
|
38
|
+
*
|
|
39
|
+
* - string literals pass through
|
|
40
|
+
* - tuple `[severity, options]` → `severity`
|
|
41
|
+
*/
|
|
42
|
+
export declare function normaliseSeverity(v: RuleConfig): Severity;
|
|
43
|
+
/**
|
|
44
|
+
* Walk up from `startDir` searching for the first recognised config file.
|
|
45
|
+
* Returns the absolute path when found, or `null` when the filesystem root
|
|
46
|
+
* is reached without finding one.
|
|
47
|
+
*/
|
|
48
|
+
export declare function findConfig(startDir: string): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Extract per-rule options from the config rules map.
|
|
51
|
+
*
|
|
52
|
+
* For tuple-form entries `["warning", { maxVersions: 5 }]`, the options
|
|
53
|
+
* object is collected keyed by rule name. String-severity entries are skipped
|
|
54
|
+
* (they carry no options).
|
|
55
|
+
*
|
|
56
|
+
* Returns a plain object suitable for JSON-serialisation and passing to the
|
|
57
|
+
* native Rust engine via the NAPI `rule_options` parameter.
|
|
58
|
+
*/
|
|
59
|
+
export declare function extractRuleOptions(rules: {
|
|
60
|
+
[name: string]: RuleConfig;
|
|
61
|
+
} | undefined): Record<string, Record<string, unknown>>;
|
|
62
|
+
/**
|
|
63
|
+
* Load and validate a sitecore-lint config file.
|
|
64
|
+
*
|
|
65
|
+
* Supports `.json`, `.yml`, `.yaml`, and `.js` formats (TASK-001).
|
|
66
|
+
* Resolves the `extends` chain (TASK-003).
|
|
67
|
+
* `sources` is now optional (TASK-004).
|
|
68
|
+
*
|
|
69
|
+
* @param configPath - Absolute or relative path to the config file.
|
|
70
|
+
* @throws {Error} if the file is missing, unparseable, or invalid.
|
|
71
|
+
*/
|
|
72
|
+
export declare function loadConfig(configPath: string): Config;
|
|
73
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normaliseSeverity = normaliseSeverity;
|
|
4
|
+
exports.findConfig = findConfig;
|
|
5
|
+
exports.extractRuleOptions = extractRuleOptions;
|
|
6
|
+
exports.loadConfig = loadConfig;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const js_yaml_1 = require("js-yaml");
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Severity normalisation (REQ-003)
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
/**
|
|
14
|
+
* Normalise any accepted `RuleConfig` value into a `Severity` string.
|
|
15
|
+
*
|
|
16
|
+
* - string literals pass through
|
|
17
|
+
* - tuple `[severity, options]` → `severity`
|
|
18
|
+
*/
|
|
19
|
+
function normaliseSeverity(v) {
|
|
20
|
+
if (typeof v === 'string') {
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
23
|
+
return v[0];
|
|
24
|
+
}
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Config discovery (TASK-001)
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
const CONFIG_FILE_NAMES = [
|
|
29
|
+
'.sitecore-lint.json',
|
|
30
|
+
'.sitecore-lint.yml',
|
|
31
|
+
'.sitecore-lint.yaml',
|
|
32
|
+
'.sitecore-lint.js',
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* Walk up from `startDir` searching for the first recognised config file.
|
|
36
|
+
* Returns the absolute path when found, or `null` when the filesystem root
|
|
37
|
+
* is reached without finding one.
|
|
38
|
+
*/
|
|
39
|
+
function findConfig(startDir) {
|
|
40
|
+
let dir = (0, node_path_1.resolve)(startDir);
|
|
41
|
+
while (true) {
|
|
42
|
+
for (const name of CONFIG_FILE_NAMES) {
|
|
43
|
+
const candidate = (0, node_path_1.join)(dir, name);
|
|
44
|
+
if ((0, node_fs_1.existsSync)(candidate))
|
|
45
|
+
return candidate;
|
|
46
|
+
}
|
|
47
|
+
const parent = (0, node_path_1.dirname)(dir);
|
|
48
|
+
if (parent === dir)
|
|
49
|
+
return null; // filesystem root
|
|
50
|
+
dir = parent;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Config loading helpers
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
function loadRawFromPath(absPath) {
|
|
57
|
+
if (absPath.endsWith('.json')) {
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
raw = (0, node_fs_1.readFileSync)(absPath, 'utf8');
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new Error(`Cannot read config file: ${absPath}`);
|
|
64
|
+
}
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = JSON.parse(raw);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
throw new Error(`Failed to parse config JSON at ${absPath}: ${err.message}`);
|
|
71
|
+
}
|
|
72
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
73
|
+
throw new Error(`Config file must be a JSON object: ${absPath}`);
|
|
74
|
+
}
|
|
75
|
+
return parsed;
|
|
76
|
+
}
|
|
77
|
+
if (absPath.endsWith('.yml') || absPath.endsWith('.yaml')) {
|
|
78
|
+
let raw;
|
|
79
|
+
try {
|
|
80
|
+
raw = (0, node_fs_1.readFileSync)(absPath, 'utf8');
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
throw new Error(`Cannot read config file: ${absPath}`);
|
|
84
|
+
}
|
|
85
|
+
let parsed;
|
|
86
|
+
try {
|
|
87
|
+
parsed = (0, js_yaml_1.load)(raw);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
throw new Error(`Failed to parse config YAML at ${absPath}: ${err.message}`);
|
|
91
|
+
}
|
|
92
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
93
|
+
throw new Error(`Config file must be a YAML mapping: ${absPath}`);
|
|
94
|
+
}
|
|
95
|
+
return parsed;
|
|
96
|
+
}
|
|
97
|
+
if (absPath.endsWith('.js')) {
|
|
98
|
+
let mod;
|
|
99
|
+
try {
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
101
|
+
mod = require(absPath);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
throw new Error(`Failed to load config JS at ${absPath}: ${err.message}`);
|
|
105
|
+
}
|
|
106
|
+
if (mod === null || typeof mod !== 'object' || Array.isArray(mod)) {
|
|
107
|
+
throw new Error(`Config JS file must export an object: ${absPath}`);
|
|
108
|
+
}
|
|
109
|
+
return mod;
|
|
110
|
+
}
|
|
111
|
+
throw new Error(`Unsupported config file format: ${absPath}`);
|
|
112
|
+
}
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
// Deep merge helpers (for extends chain)
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
function mergeConfigs(base, override) {
|
|
117
|
+
const mergedRules = {
|
|
118
|
+
...(base.rules ?? {}),
|
|
119
|
+
...(override.rules ?? {}),
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
sources: override.sources ?? base.sources,
|
|
123
|
+
sitecoreJson: override.sitecoreJson ?? base.sitecoreJson,
|
|
124
|
+
modules: override.modules ?? base.modules,
|
|
125
|
+
iar: override.iar ?? base.iar,
|
|
126
|
+
plugins: [...(base.plugins ?? []), ...(override.plugins ?? [])],
|
|
127
|
+
extends: override.extends ?? base.extends,
|
|
128
|
+
rules: Object.keys(mergedRules).length > 0 ? mergedRules : undefined,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Preset loader (TASK-003)
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
function loadPreset(ref, configDir) {
|
|
135
|
+
if (ref === 'sitecore-lint/configs/recommended') {
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
137
|
+
const preset = require('./configs/recommended');
|
|
138
|
+
const cfg = preset.recommended ??
|
|
139
|
+
preset.default ??
|
|
140
|
+
preset;
|
|
141
|
+
return cfg;
|
|
142
|
+
}
|
|
143
|
+
if (ref === 'sitecore-lint/configs/strict') {
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
145
|
+
const preset = require('./configs/strict');
|
|
146
|
+
const cfg = preset.strict ??
|
|
147
|
+
preset.default ??
|
|
148
|
+
preset;
|
|
149
|
+
return cfg;
|
|
150
|
+
}
|
|
151
|
+
if (ref === 'sitecore-lint/configs/all') {
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
153
|
+
const preset = require('./configs/all');
|
|
154
|
+
const cfg = preset.all ??
|
|
155
|
+
preset.default ??
|
|
156
|
+
preset;
|
|
157
|
+
return cfg;
|
|
158
|
+
}
|
|
159
|
+
// External package reference — resolve relative paths against the config file's
|
|
160
|
+
// directory, but let bare package names resolve via Node's module resolution.
|
|
161
|
+
try {
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
163
|
+
const mod = require(ref.startsWith('.') ? (0, node_path_1.resolve)(configDir, ref) : ref);
|
|
164
|
+
return mod;
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
throw new Error(`Failed to load extends preset "${ref}": ${err.message}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
// Object → Config conversion
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
function objectToConfig(obj) {
|
|
174
|
+
const sources = [];
|
|
175
|
+
if (Array.isArray(obj['sources'])) {
|
|
176
|
+
for (const s of obj['sources']) {
|
|
177
|
+
if (typeof s === 'string')
|
|
178
|
+
sources.push(s);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const rules = {};
|
|
182
|
+
if (obj['rules'] !== undefined && obj['rules'] !== null && typeof obj['rules'] === 'object') {
|
|
183
|
+
for (const [name, val] of Object.entries(obj['rules'])) {
|
|
184
|
+
if (typeof val === 'string') {
|
|
185
|
+
rules[name] = val;
|
|
186
|
+
}
|
|
187
|
+
else if (Array.isArray(val) && val.length >= 1 && typeof val[0] === 'string') {
|
|
188
|
+
rules[name] = [val[0], val[1] ?? {}];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const modules = [];
|
|
193
|
+
if (Array.isArray(obj['modules'])) {
|
|
194
|
+
for (const m of obj['modules']) {
|
|
195
|
+
if (typeof m === 'string')
|
|
196
|
+
modules.push(m);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const iar = [];
|
|
200
|
+
if (Array.isArray(obj['iar'])) {
|
|
201
|
+
for (const m of obj['iar']) {
|
|
202
|
+
if (typeof m === 'string')
|
|
203
|
+
iar.push(m);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const plugins = [];
|
|
207
|
+
if (Array.isArray(obj['plugins'])) {
|
|
208
|
+
for (const p of obj['plugins']) {
|
|
209
|
+
if (typeof p === 'string')
|
|
210
|
+
plugins.push(p);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const extendsArr = [];
|
|
214
|
+
if (Array.isArray(obj['extends'])) {
|
|
215
|
+
for (const e of obj['extends']) {
|
|
216
|
+
if (typeof e === 'string')
|
|
217
|
+
extendsArr.push(e);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const sitecoreJson = typeof obj['sitecoreJson'] === 'string' ? obj['sitecoreJson'] : undefined;
|
|
221
|
+
return {
|
|
222
|
+
sources: sources.length > 0 ? sources : undefined,
|
|
223
|
+
sitecoreJson,
|
|
224
|
+
modules: modules.length > 0 ? modules : undefined,
|
|
225
|
+
iar: iar.length > 0 ? iar : undefined,
|
|
226
|
+
plugins: plugins.length > 0 ? plugins : undefined,
|
|
227
|
+
extends: extendsArr.length > 0 ? extendsArr : undefined,
|
|
228
|
+
rules: Object.keys(rules).length > 0 ? rules : undefined,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
// Public API
|
|
233
|
+
// ---------------------------------------------------------------------------
|
|
234
|
+
/**
|
|
235
|
+
* Extract per-rule options from the config rules map.
|
|
236
|
+
*
|
|
237
|
+
* For tuple-form entries `["warning", { maxVersions: 5 }]`, the options
|
|
238
|
+
* object is collected keyed by rule name. String-severity entries are skipped
|
|
239
|
+
* (they carry no options).
|
|
240
|
+
*
|
|
241
|
+
* Returns a plain object suitable for JSON-serialisation and passing to the
|
|
242
|
+
* native Rust engine via the NAPI `rule_options` parameter.
|
|
243
|
+
*/
|
|
244
|
+
function extractRuleOptions(rules) {
|
|
245
|
+
const result = {};
|
|
246
|
+
if (!rules)
|
|
247
|
+
return result;
|
|
248
|
+
for (const [name, cfg] of Object.entries(rules)) {
|
|
249
|
+
if (Array.isArray(cfg) && cfg.length >= 2 && cfg[1] && typeof cfg[1] === 'object') {
|
|
250
|
+
result[name] = cfg[1];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Load and validate a sitecore-lint config file.
|
|
257
|
+
*
|
|
258
|
+
* Supports `.json`, `.yml`, `.yaml`, and `.js` formats (TASK-001).
|
|
259
|
+
* Resolves the `extends` chain (TASK-003).
|
|
260
|
+
* `sources` is now optional (TASK-004).
|
|
261
|
+
*
|
|
262
|
+
* @param configPath - Absolute or relative path to the config file.
|
|
263
|
+
* @throws {Error} if the file is missing, unparseable, or invalid.
|
|
264
|
+
*/
|
|
265
|
+
function loadConfig(configPath) {
|
|
266
|
+
const absPath = (0, node_path_1.resolve)(configPath);
|
|
267
|
+
const configDir = (0, node_path_1.dirname)(absPath);
|
|
268
|
+
const obj = loadRawFromPath(absPath);
|
|
269
|
+
const userConfig = objectToConfig(obj);
|
|
270
|
+
// Resolve extends chain: earlier entries are base, later entries and user config win.
|
|
271
|
+
if (userConfig.extends && userConfig.extends.length > 0) {
|
|
272
|
+
let merged = {};
|
|
273
|
+
for (const ref of userConfig.extends) {
|
|
274
|
+
const preset = loadPreset(ref, configDir);
|
|
275
|
+
merged = mergeConfigs(merged, preset);
|
|
276
|
+
}
|
|
277
|
+
// User config (without extends key to avoid recursion) overrides the merged chain.
|
|
278
|
+
const userWithoutExtends = { ...userConfig };
|
|
279
|
+
delete userWithoutExtends.extends;
|
|
280
|
+
return mergeConfigs(merged, userWithoutExtends);
|
|
281
|
+
}
|
|
282
|
+
return userConfig;
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAsDA,8CAKC;AAkBD,gCAWC;AAgND,gDAWC;AAYD,gCAoBC;AAnVD,qCAAmD;AACnD,yCAAmD;AACnD,qCAA+B;AA0C/B,8EAA8E;AAC9E,mCAAmC;AACnC,8EAA8E;AAE9E;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,CAAa;IAC7C,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC1B,OAAO,CAAa,CAAC;IACvB,CAAC;IACD,OAAO,CAAC,CAAC,CAAC,CAAa,CAAC;AAC1B,CAAC;AAED,8EAA8E;AAC9E,8BAA8B;AAC9B,8EAA8E;AAE9E,MAAM,iBAAiB,GAAG;IACxB,qBAAqB;IACrB,oBAAoB;IACpB,qBAAqB;IACrB,mBAAmB;CACX,CAAC;AAEX;;;;GAIG;AACH,SAAgB,UAAU,CAAC,QAAgB;IACzC,IAAI,GAAG,GAAG,IAAA,mBAAO,EAAC,QAAQ,CAAC,CAAC;IAC5B,OAAO,IAAI,EAAE,CAA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AO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxD,IAAI,MAAM,GAAW,EAAE,CAAC;QACxB,KAAK,MAAM,GAAG,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACrC,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC1C,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;QACD,mFAAmF;QACnF,MAAM,kBAAkB,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC;QAC7C,OAAO,kBAAkB,CAAC,OAAO,CAAC;QAClC,OAAO,YAAY,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Config } from '../config';
|
|
2
|
+
/**
|
|
3
|
+
* Built-in `all` shareable config preset (TASK-029).
|
|
4
|
+
*
|
|
5
|
+
* Enables every built-in rule at `warning`, including SXA rules.
|
|
6
|
+
* This is a starting point for teams to customize — not recommended
|
|
7
|
+
* for production CI without further tuning.
|
|
8
|
+
*
|
|
9
|
+
* Intended to be referenced via:
|
|
10
|
+
* `"extends": ["sitecore-lint/configs/all"]`
|
|
11
|
+
*/
|
|
12
|
+
export declare const all: Config;
|
|
13
|
+
export default all;
|
|
14
|
+
//# sourceMappingURL=all.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../src/configs/all.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC;;;;;;;;;GASG;AACH,eAAO,MAAM,GAAG,EAAE,MAiDjB,CAAC;AAEF,eAAe,GAAG,CAAC"}
|