kitcheck 0.0.0-stage → 0.1.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1
4
+
5
+ - Added npm, CI and license badges to the README.
6
+ - Credited Raddito Agency as a contributor in the README and package.json.
7
+
8
+ ## 0.1.0
9
+
10
+ First release.
11
+
12
+ - Checks Elementor library exports, copied elements, `_elementor_data` arrays, kit folders and kit ZIP files.
13
+ - 25 rules covering JSON validity, layout structure, ids, Elementor Pro and addon dependencies, target versions, external and insecure media, staging links, scripts, template metadata and kit manifests.
14
+ - Line and column numbers for every finding.
15
+ - `pretty`, `json` and `github` output, config files, and a GitHub Action.
16
+ - No runtime dependencies.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shahporan Razu
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/README.md CHANGED
@@ -1,3 +1,186 @@
1
- # Temporary Holding Version
1
+ # KitCheck
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/kitcheck)](https://www.npmjs.com/package/kitcheck) [![CI](https://github.com/radditoagency/kitcheck/actions/workflows/ci.yml/badge.svg)](https://github.com/radditoagency/kitcheck/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
4
+
5
+ Check Elementor templates, copied sections and template kits for problems **before** you import them or ship them to buyers.
6
+
7
+ ```text
8
+ $ npx kitcheck my-kit.zip
9
+
10
+ my-kit.zip:templates/home.json
11
+ 17:13 error [image c0ffee1] The id "c0ffee1" is also used on line 12. Duplicate ids make styles and edits apply to the wrong element. ids/duplicate
12
+ 24:13 warn [form 5d6e7f8] Needs Elementor Pro: uses the "form" widget. Without Pro this part will not work. Pass --pro if the site has Pro. deps/pro
13
+ 31:13 warn "eael-fancy-text" is not an Elementor or Elementor Pro widget. It probably comes from Essential Addons for Elementor, which must be active on the site or the widget will not render. deps/addon
14
+ 21:58 warn [image c0ffee1] Media loads from demo.mytheme.com (http://demo.mytheme.com/wp-content/uploads/2026/05/team.jpg). Elementor downloads it during import, so it will be missing if that site goes offline or blocks the request. assets/external
15
+
16
+ my-kit.zip:manifest.json
17
+ 12:77 error The manifest lists "templates/contact.json", but that file is not in the kit. kit/missing-file
18
+
19
+ 2 error(s), 3 warning(s) in 4 file(s) checked.
20
+ ```
21
+
22
+ Elementor will happily import a template that needs Pro on a site without Pro, pulls images from a demo server that is about to go offline, or carries a staging link into a client's live site. You find out after the import, usually from the client. KitCheck finds it first.
23
+
24
+ - **No dependencies.** Plain Node.js, nothing to install beyond the package itself.
25
+ - **Reads everything Elementor writes:** library exports (`.json`), copied elements from the clipboard, raw `_elementor_data`, template kit folders and kit `.zip` files.
26
+ - **Built for CI.** Exit codes, JSON output and GitHub annotations, plus a ready-made GitHub Action.
27
+ - **Line numbers for every problem**, even inside minified exports.
28
+
29
+ ## Install
30
+
31
+ Needs Node.js 18.17 or newer.
32
+
33
+ ```bash
34
+ npx kitcheck path/to/template.json # run once without installing
35
+ npm install --save-dev kitcheck # add to a project
36
+ npm install --global kitcheck # use anywhere
37
+ ```
38
+
39
+ ## Use
40
+
41
+ ```bash
42
+ kitcheck home.json # one template
43
+ kitcheck templates/ # every .json and .zip in a folder
44
+ kitcheck northwind-kit.zip # a template kit
45
+ kitcheck --pro --target 3.24 kits/ # the site has Pro and runs Elementor 3.24
46
+ pbpaste | kitcheck - # a copied section on your clipboard (macOS)
47
+ ```
48
+
49
+ Copy-paste section libraries put Elementor JSON on your clipboard. To check a section before you paste it into a site, pipe the clipboard into KitCheck with `-` (`pbpaste` on macOS, `xclip -o -selection clipboard` on Linux, `Get-Clipboard | npx kitcheck -` in PowerShell).
50
+
51
+ ### Options
52
+
53
+ | Option | What it does |
54
+ | --- | --- |
55
+ | `--pro` | The site has Elementor Pro. Turns off Pro warnings. |
56
+ | `--target <version>` | Oldest Elementor version the files must work with, such as `3.24`. |
57
+ | `--allow-host <host>` | A host media may load from, such as your CDN. Repeat for more. Subdomains count. |
58
+ | `--known-widget <type>` | A widget type you know is installed. Repeat for more. |
59
+ | `--rule <id>=<severity>` | Set a rule to `off`, `info`, `warning` or `error`. |
60
+ | `--format <name>` | `pretty` (default), `json` or `github`. Inside GitHub Actions the default is `github`. |
61
+ | `--quiet` | Show errors only. |
62
+ | `--strict` | Fail on warnings too. |
63
+ | `--max-warnings <n>` | Fail when there are more than `n` warnings. |
64
+ | `--config <file>` / `--no-config` | Use a specific config file, or ignore config files. |
65
+ | `--list-rules` | Print every rule. |
66
+
67
+ Exit codes: `0` nothing failed, `1` problems found, `2` bad usage or a crash.
68
+
69
+ ## What it checks
70
+
71
+ | Rule | Default | Catches |
72
+ | --- | --- | --- |
73
+ | `json/invalid` | error | Files that are not valid JSON, with the line and column. |
74
+ | `format/unknown` | error | A file you named that is not an Elementor file. |
75
+ | `input/unreadable` | error | Missing paths and broken or encrypted ZIP files. |
76
+ | `structure/empty` | warning | Templates with no elements. |
77
+ | `structure/element` | error | Elements without an `elType`, or with `elements` that is not an array. |
78
+ | `structure/unknown-type` | warning | Element types Elementor does not use. |
79
+ | `structure/widget-type` | error | Widgets without a `widgetType`. |
80
+ | `structure/nesting` | error | Columns outside sections, sections holding anything but columns, widgets at the top level. |
81
+ | `structure/widget-children` | warning | Child elements inside a widget that cannot hold them. |
82
+ | `structure/settings` | error | `settings` that is not an object. |
83
+ | `ids/missing` | error | Elements without an id. |
84
+ | `ids/duplicate` | error | The same id used twice in one file. |
85
+ | `ids/format` | warning | Ids that do not look like Elementor ids and can break CSS selectors. |
86
+ | `deps/pro` | warning | Pro widgets, Theme Builder template types, dynamic tags, sticky and motion effects. |
87
+ | `deps/addon` | warning | Widgets from addon plugins, with a guess at which plugin. |
88
+ | `compat/target` | error | Containers or Atomic (Elementor 4) elements when `--target` is older than they need. |
89
+ | `assets/external` | warning | Images, video, fonts and Lottie files loaded from another site. |
90
+ | `assets/insecure` | warning | `http://` links and media. |
91
+ | `links/dev-host` | warning | Links to `localhost`, private IPs, `.local` and `.test` sites, and `staging.` hosts. |
92
+ | `security/script` | warning | `<script>` tags, inline event handlers and `javascript:` links in settings. |
93
+ | `meta/title` | warning | Library exports without a title. |
94
+ | `meta/type` | warning | Library exports without a template type, or with one Elementor does not know. |
95
+ | `kit/missing-file` | error | Kit manifests that list a template file the kit does not include. |
96
+ | `kit/screenshot` | warning | Kit manifests that list a missing screenshot. |
97
+ | `kit/plugins` | warning | Kit manifests that leave out Elementor Pro or addon plugins the templates need. |
98
+
99
+ More detail, with examples, is in [docs/rules.md](docs/rules.md).
100
+
101
+ ## Configuration
102
+
103
+ Put a `.kitcheckrc.json` in your project (or a `"kitcheck"` key in `package.json`). KitCheck looks in the current folder and its parents.
104
+
105
+ ```json
106
+ {
107
+ "pro": true,
108
+ "target": "3.24",
109
+ "allowHosts": ["cdn.mystudio.com"],
110
+ "knownWidgets": ["my-custom-slider"],
111
+ "knownWidgetPrefixes": ["acme-"],
112
+ "rules": {
113
+ "assets/insecure": "error",
114
+ "ids/format": "off"
115
+ }
116
+ }
117
+ ```
118
+
119
+ Command-line options override the config file.
120
+
121
+ ## GitHub Action
122
+
123
+ Fail a pull request when a template breaks, with annotations on the changed lines:
124
+
125
+ ```yaml
126
+ name: Check templates
127
+ on: [push, pull_request]
128
+
129
+ jobs:
130
+ kitcheck:
131
+ runs-on: ubuntu-latest
132
+ steps:
133
+ - uses: actions/checkout@v4
134
+ - uses: radditoagency/kitcheck@v0.1.0
135
+ with:
136
+ path: templates
137
+ pro: true
138
+ target: '3.24'
139
+ ```
140
+
141
+ | Input | Default | Meaning |
142
+ | --- | --- | --- |
143
+ | `path` | `.` | Files, folders or ZIPs to check, separated by spaces. |
144
+ | `pro` | `false` | The site has Elementor Pro. |
145
+ | `target` | | Oldest Elementor version to support. |
146
+ | `strict` | `false` | Fail on warnings too. |
147
+ | `args` | | Any other KitCheck options. |
148
+
149
+ ## Use it from code
150
+
151
+ ```js
152
+ import { lint, lintText } from 'kitcheck';
153
+
154
+ const result = await lint(['kits/northwind.zip'], { pro: true, target: '3.24' });
155
+ console.log(result.errorCount, result.warningCount);
156
+
157
+ for (const file of result.files) {
158
+ for (const finding of file.findings) {
159
+ console.log(file.file, finding.line, finding.ruleId, finding.message);
160
+ }
161
+ }
162
+
163
+ // Check a string, for example JSON an AI tool just generated
164
+ const check = lintText(generatedJson, { filename: 'generated.json' });
165
+ if (check.errorCount > 0) throw new Error('The generated layout will not import cleanly');
166
+ ```
167
+
168
+ TypeScript types are included.
169
+
170
+ ## Limits
171
+
172
+ KitCheck reads files. It does not run WordPress or Elementor, so it cannot tell whether a widget renders the way you expect, and the lists of Pro and core widgets are kept by hand. If KitCheck gets a widget wrong, [open an issue](../../issues/new/choose) or send a pull request that edits [`src/data/elementor.js`](src/data/elementor.js).
173
+
174
+ KitCheck is an independent project. It is not made by or affiliated with Elementor Ltd. Elementor is a trademark of Elementor Ltd.
175
+
176
+ ## Contributing
177
+
178
+ Bug reports, false positives and new rule ideas are all welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
179
+
180
+ ## Credits
181
+
182
+ KitCheck is built by Shahporan Razu with [Raddito Agency](https://raddito.agency) as a contributor.
183
+
184
+ ## License
185
+
186
+ [MIT](LICENSE)
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { lint, rules } from '../src/index.js';
4
+ import { findConfig, loadConfigFile, resolveOptions, UsageError } from '../src/config.js';
5
+ import { format, FORMATS } from '../src/report.js';
6
+
7
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
8
+
9
+ const HELP = `kitcheck ${pkg.version}
10
+ Check Elementor templates, copied elements and template kits before you import them.
11
+
12
+ Usage
13
+ kitcheck [options] <file.json | folder | kit.zip>...
14
+ kitcheck [options] - read JSON from standard input
15
+
16
+ Options
17
+ --pro The site has Elementor Pro (stops Pro warnings)
18
+ --target <version> Oldest Elementor version the files must work with
19
+ --allow-host <host> Host that media may load from (repeat for more)
20
+ --known-widget <type> Widget type you know is installed (repeat for more)
21
+ --rule <id>=<severity> Set a rule to off, info, warning or error
22
+ --format <name> pretty, json or github (github is the default in GitHub Actions)
23
+ --quiet Show errors only
24
+ --strict Fail on warnings as well as errors
25
+ --max-warnings <n> Fail when there are more than n warnings
26
+ --config <file> Use this config file
27
+ --no-config Ignore .kitcheckrc.json and package.json settings
28
+ --list-rules List every rule and exit
29
+ -v, --version Print the version
30
+ -h, --help Show this help
31
+
32
+ Exit codes: 0 no failures, 1 problems found, 2 bad usage or crash.
33
+ Docs: ${pkg.homepage ?? 'see README.md'}
34
+ `;
35
+
36
+ async function main(argv) {
37
+ const args = parseArgs(argv);
38
+ if (args.help) return void process.stdout.write(HELP);
39
+ if (args.version) return void process.stdout.write(`${pkg.version}\n`);
40
+ if (args.listRules) return void process.stdout.write(listRules());
41
+ if (args.inputs.length === 0) throw new UsageError('Give at least one file, folder or ZIP to check. Run kitcheck --help for usage.');
42
+
43
+ let fileConfig = null;
44
+ if (args.config) fileConfig = await loadConfigFile(args.config);
45
+ else if (args.useConfig) fileConfig = (await findConfig(process.cwd()))?.config ?? null;
46
+
47
+ const cliOptions = {
48
+ pro: args.pro || undefined,
49
+ target: args.target,
50
+ allowHosts: args.allowHosts,
51
+ knownWidgets: args.knownWidgets,
52
+ rules: args.rules,
53
+ };
54
+ const options = resolveOptions(fileConfig, cliOptions);
55
+ const result = await lint(args.inputs, { ...options, cwd: process.cwd() });
56
+
57
+ const outputFormat = args.format ?? (process.env.GITHUB_ACTIONS === 'true' ? 'github' : 'pretty');
58
+ const color = Boolean(process.stdout.isTTY) && !('NO_COLOR' in process.env);
59
+ process.stdout.write(format(result, outputFormat, { color, quiet: args.quiet }));
60
+
61
+ const tooManyWarnings =
62
+ (args.strict && result.warningCount > 0) ||
63
+ (args.maxWarnings !== null && result.warningCount > args.maxWarnings);
64
+ return result.errorCount > 0 || tooManyWarnings ? 1 : 0;
65
+ }
66
+
67
+ function parseArgs(argv) {
68
+ const args = {
69
+ inputs: [],
70
+ allowHosts: [],
71
+ knownWidgets: [],
72
+ rules: {},
73
+ pro: false,
74
+ target: undefined,
75
+ format: undefined,
76
+ quiet: false,
77
+ strict: false,
78
+ maxWarnings: null,
79
+ config: null,
80
+ useConfig: true,
81
+ listRules: false,
82
+ help: false,
83
+ version: false,
84
+ };
85
+ for (let i = 0; i < argv.length; i++) {
86
+ let arg = argv[i];
87
+ if (arg === '--') {
88
+ args.inputs.push(...argv.slice(i + 1));
89
+ break;
90
+ }
91
+ let inline = null;
92
+ if (arg.startsWith('--') && arg.includes('=')) {
93
+ [arg, inline] = [arg.slice(0, arg.indexOf('=')), arg.slice(arg.indexOf('=') + 1)];
94
+ }
95
+ const value = () => {
96
+ if (inline !== null) return inline;
97
+ const next = argv[++i];
98
+ if (next === undefined) throw new UsageError(`${arg} needs a value`);
99
+ return next;
100
+ };
101
+ switch (arg) {
102
+ case '--pro': args.pro = true; break;
103
+ case '--target': args.target = value(); break;
104
+ case '--allow-host': args.allowHosts.push(value()); break;
105
+ case '--known-widget': args.knownWidgets.push(value()); break;
106
+ case '--rule': {
107
+ const spec = value();
108
+ const at = spec.lastIndexOf('=');
109
+ if (at < 1) throw new UsageError(`--rule needs id=severity, for example --rule assets/insecure=off`);
110
+ args.rules[spec.slice(0, at)] = spec.slice(at + 1);
111
+ break;
112
+ }
113
+ case '--format': {
114
+ args.format = value();
115
+ if (!FORMATS.includes(args.format)) throw new UsageError(`--format must be one of ${FORMATS.join(', ')}`);
116
+ break;
117
+ }
118
+ case '--quiet': args.quiet = true; break;
119
+ case '--strict': args.strict = true; break;
120
+ case '--max-warnings': {
121
+ const n = Number(value());
122
+ if (!Number.isInteger(n) || n < 0) throw new UsageError('--max-warnings needs a whole number of 0 or more');
123
+ args.maxWarnings = n;
124
+ break;
125
+ }
126
+ case '--config': args.config = value(); break;
127
+ case '--no-config': args.useConfig = false; break;
128
+ case '--list-rules': args.listRules = true; break;
129
+ case '-h':
130
+ case '--help': args.help = true; break;
131
+ case '-v':
132
+ case '--version': args.version = true; break;
133
+ default:
134
+ if (arg.startsWith('-') && arg !== '-') throw new UsageError(`Unknown option ${arg}. Run kitcheck --help for usage.`);
135
+ args.inputs.push(arg);
136
+ }
137
+ }
138
+ return args;
139
+ }
140
+
141
+ function listRules() {
142
+ const width = Math.max(...rules.map((r) => r.id.length));
143
+ const lines = rules.map((r) => `${r.id.padEnd(width)} ${r.severity.padEnd(7)} ${r.description}`);
144
+ return `${lines.join('\n')}\n`;
145
+ }
146
+
147
+ main(process.argv.slice(2)).then(
148
+ (code) => {
149
+ process.exitCode = code ?? 0;
150
+ },
151
+ (err) => {
152
+ if (err instanceof UsageError) {
153
+ process.stderr.write(`kitcheck: ${err.message}\n`);
154
+ } else {
155
+ process.stderr.write(`kitcheck crashed: ${err.stack ?? err}\nPlease report this at ${pkg.bugs?.url ?? 'the project issue tracker'}.\n`);
156
+ }
157
+ process.exitCode = 2;
158
+ },
159
+ );
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "kitcheck",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Check Elementor templates, copied elements and template kits for problems before you import them.",
5
+ "keywords": [
6
+ "elementor",
7
+ "elementor-template",
8
+ "template-kit",
9
+ "wordpress",
10
+ "lint",
11
+ "linter",
12
+ "validator",
13
+ "cli",
14
+ "github-action"
15
+ ],
16
+ "license": "MIT",
17
+ "author": "Shahporan Razu",
18
+ "contributors": [
19
+ {
20
+ "name": "Raddito Agency",
21
+ "url": "https://raddito.agency"
22
+ }
23
+ ],
24
+ "homepage": "https://github.com/radditoagency/kitcheck#readme",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/radditoagency/kitcheck.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/radditoagency/kitcheck/issues"
31
+ },
32
+ "type": "module",
33
+ "main": "./src/index.js",
34
+ "types": "./src/index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./src/index.d.ts",
38
+ "default": "./src/index.js"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
42
+ "bin": {
43
+ "kitcheck": "bin/kitcheck.js"
44
+ },
45
+ "files": [
46
+ "bin",
47
+ "src",
48
+ "README.md",
49
+ "LICENSE",
50
+ "CHANGELOG.md"
51
+ ],
52
+ "engines": {
53
+ "node": ">=18.17"
54
+ },
55
+ "scripts": {
56
+ "test": "node --test",
57
+ "lint:examples": "node bin/kitcheck.js examples/"
58
+ }
59
+ }
package/src/config.js ADDED
@@ -0,0 +1,101 @@
1
+ // Loads .kitcheckrc.json (or the "kitcheck" key in package.json) and merges
2
+ // it with options passed in code or on the command line.
3
+
4
+ import { readFile } from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import { allRules } from './rules.js';
7
+ import { isVersion } from './version.js';
8
+
9
+ export const CONFIG_FILES = ['.kitcheckrc.json', '.kitcheckrc', 'kitcheck.config.json'];
10
+ const SEVERITIES = new Set(['off', 'info', 'warning', 'error']);
11
+
12
+ /**
13
+ * Look for a config file in `cwd` and its parent folders.
14
+ * @returns {Promise<{ path: string, config: object } | null>}
15
+ */
16
+ export async function findConfig(cwd) {
17
+ let dir = path.resolve(cwd);
18
+ for (;;) {
19
+ for (const name of CONFIG_FILES) {
20
+ const file = path.join(dir, name);
21
+ const text = await readFile(file, 'utf8').catch(() => null);
22
+ if (text !== null) return { path: file, config: parseConfig(text, file) };
23
+ }
24
+ const pkgText = await readFile(path.join(dir, 'package.json'), 'utf8').catch(() => null);
25
+ if (pkgText !== null) {
26
+ try {
27
+ const pkg = JSON.parse(pkgText);
28
+ if (pkg && typeof pkg.kitcheck === 'object') {
29
+ return { path: path.join(dir, 'package.json'), config: pkg.kitcheck };
30
+ }
31
+ } catch {
32
+ // Not our file to complain about.
33
+ }
34
+ }
35
+ const parent = path.dirname(dir);
36
+ if (parent === dir) return null;
37
+ dir = parent;
38
+ }
39
+ }
40
+
41
+ export async function loadConfigFile(file) {
42
+ const text = await readFile(file, 'utf8');
43
+ return parseConfig(text, file);
44
+ }
45
+
46
+ function parseConfig(text, file) {
47
+ try {
48
+ return JSON.parse(text);
49
+ } catch (err) {
50
+ throw new UsageError(`Cannot parse ${file}: ${err.message}`);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Turn user options into the shape the engine uses.
56
+ * Later sources win: defaults, then config file, then explicit options.
57
+ */
58
+ export function resolveOptions(...sources) {
59
+ const merged = { pro: false, target: null, allowHosts: [], knownWidgets: [], knownWidgetPrefixes: [], rules: {} };
60
+ for (const src of sources) {
61
+ if (!src) continue;
62
+ if (src.pro !== undefined) merged.pro = Boolean(src.pro);
63
+ if (src.target !== undefined && src.target !== null) merged.target = String(src.target);
64
+ for (const key of ['allowHosts', 'knownWidgets', 'knownWidgetPrefixes']) {
65
+ if (src[key] !== undefined) {
66
+ if (!Array.isArray(src[key])) throw new UsageError(`"${key}" must be an array of strings`);
67
+ merged[key].push(...src[key].map(String));
68
+ }
69
+ }
70
+ if (src.rules !== undefined) {
71
+ if (typeof src.rules !== 'object' || src.rules === null) throw new UsageError('"rules" must be an object');
72
+ Object.assign(merged.rules, src.rules);
73
+ }
74
+ }
75
+
76
+ if (merged.target !== null && !isVersion(merged.target)) {
77
+ throw new UsageError(`"${merged.target}" is not a version number. Use something like 3.21 or 3.21.4.`);
78
+ }
79
+
80
+ const known = new Set(allRules.map((r) => r.id));
81
+ const severities = {};
82
+ for (const [id, value] of Object.entries(merged.rules)) {
83
+ const severity = value === 'warn' ? 'warning' : value;
84
+ if (!known.has(id)) throw new UsageError(`Unknown rule "${id}". Run kitcheck --list-rules to see them all.`);
85
+ if (!SEVERITIES.has(severity)) {
86
+ throw new UsageError(`Rule "${id}" has severity "${value}". Use off, info, warning or error.`);
87
+ }
88
+ severities[id] = severity;
89
+ }
90
+
91
+ return {
92
+ pro: merged.pro,
93
+ target: merged.target,
94
+ allowHosts: new Set(merged.allowHosts.map((h) => h.toLowerCase().replace(/^\*\./, ''))),
95
+ knownWidgets: new Set(merged.knownWidgets),
96
+ knownPrefixes: merged.knownWidgetPrefixes,
97
+ severities,
98
+ };
99
+ }
100
+
101
+ export class UsageError extends Error {}