@iobroker/repochecker 4.2.0-alpha.3 → 4.2.0-alpha.5

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 CHANGED
@@ -33,7 +33,8 @@ npx @iobroker/repochecker https://github.com/ioBroker/ioBroker.javascript --loca
33
33
  -->
34
34
 
35
35
  ## Changelog
36
- ### 4.2.0-alpha.3 (2025-09-15)
36
+ ### 4.2.0-alpha.5 (2025-09-15)
37
+ - (copilot) Added io-package.json schema validation against official schema (W205, W207, W208) [#503].
37
38
  - (copilot) Added check for deprecated adapter methods (createState/createChannel/createDevice/deleteState/deleteChannel/deleteDevice) (W533) [#182].
38
39
  - (copilot) Added check for outdated lib/tools.js file usage (W532) [#432].
39
40
  - (copilot) Added VS Code schema definitions checker for .vscode/settings.json - validates json.schemas for io-package.json and jsonConfig files [#336].
@@ -9,8 +9,10 @@
9
9
 
10
10
  const compareVersions = require('compare-versions');
11
11
  const sizeOf = require('image-size');
12
+ const Ajv = require('ajv');
12
13
 
13
14
  const common = require('./common.js');
15
+ const config = require('./config.js');
14
16
 
15
17
  async function getIOPackageJson(context) {
16
18
  console.log('[init] getting io-package.json');
@@ -96,6 +98,69 @@ const blacklistIOPackageJson = {
96
98
  },
97
99
  };
98
100
 
101
+ async function validateIOPackageSchema(context) {
102
+ common.debug('[schema] validating io-package.json against schema');
103
+
104
+ try {
105
+ // Download the schema
106
+ const schemaUrl = config.schemaUrls['io-package'];
107
+ common.debug(`Downloading schema from ${schemaUrl}`);
108
+
109
+ const schemaData = await common.downloadURL(schemaUrl, false);
110
+ if (!schemaData) {
111
+ context.warnings.push('[W207] Could not download ${schemaUrl} for validation of io-package.json');
112
+ return context;
113
+ }
114
+
115
+ const schema = JSON.parse(schemaData);
116
+
117
+ // Initialize AJV validator
118
+ // @ts-expect-error not constructable - but working
119
+ const ajv = new Ajv({ allErrors: true, verbose: true });
120
+ const validate = ajv.compile(schema);
121
+
122
+ // Validate io-package.json against schema
123
+ const valid = validate(context.ioPackageJson);
124
+
125
+ if (valid) {
126
+ context.checks.push('io-package.json validates against schema');
127
+ } else {
128
+ // Log individual validation errors
129
+ if (validate.errors) {
130
+ for (const error of validate.errors) {
131
+ common.debug(`Schema validation error block:\n ${JSON.stringify(error)}`);
132
+
133
+ const path = error.instancePath || 'root';
134
+ const message = error.message;
135
+
136
+ // Create a concise, developer-friendly error message
137
+ let errorMsg;
138
+ if (error.keyword === 'required') {
139
+ errorMsg = `Missing required property "${error.params.missingProperty}" in ${path || 'io-package.json'}`;
140
+ } else if (error.keyword === 'additionalProperties') {
141
+ errorMsg = `Unknown property "${error.params.additionalProperty}" in ${path}`;
142
+ } else if (error.keyword === 'type') {
143
+ errorMsg = `Property "${path}" should be ${error.params.type}`;
144
+ } else if (error.keyword === 'enum') {
145
+ errorMsg = `Property "${path}" should be one of: ${error.params.allowedValues?.join(', ')}`;
146
+ } else {
147
+ errorMsg = `Property "${path}" ${message}`;
148
+ }
149
+
150
+ context.warnings.push(`[W205] io-package.json schema validation error: ${errorMsg}`);
151
+ }
152
+ } else {
153
+ context.warnings.push('[W205] io-package.json does not validate against schema');
154
+ }
155
+ }
156
+ } catch (error) {
157
+ common.debug(`Schema validation error: ${error.message}`);
158
+ context.warnings.push(`[W208] io-package.json schema validation failed: ${error.message}`);
159
+ }
160
+
161
+ return context;
162
+ }
163
+
99
164
  async function checkIOPackageJson(context) {
100
165
  console.log('\n[E100 - E249] checking io-package.json');
101
166
 
@@ -222,6 +287,9 @@ async function checkIOPackageJson(context) {
222
287
  }
223
288
  context.checks.push('"common" found in io-package.json');
224
289
 
290
+ // Validate io-package.json against its schema
291
+ await validateIOPackageSchema(context);
292
+
225
293
  if (!context.ioPackageJson.common.name || context.ioPackageJson.common.name !== context.adapterName.toLowerCase()) {
226
294
  context.errors.push(
227
295
  `[E103] "common.name" in io-package.json must be equal to "${context.adapterName.toLowerCase()}'". Now is ${context.ioPackageJson.common.name}`,
@@ -1219,3 +1287,6 @@ exports.checkIOPackageJson = checkIOPackageJson;
1219
1287
  // [202] Consider adding 'vis-2' to "common.restartAdapters" as 'vis' is already listed in io-package.json
1220
1288
  // [203] Encryption of array elements "${key}" is not yet available
1221
1289
  // [204] allowInit is only used with scheduled adapters and should be removed
1290
+ // [205] Schema validation: ${errorMsg}
1291
+ // [207] Could not download io-package.json schema for validation
1292
+ // [208] Schema validation failed: ${error.message}
package/lib/M500_Code.js CHANGED
@@ -536,7 +536,9 @@ async function checkCode(context) {
536
536
  if (
537
537
  content.includes('lib/tools') ||
538
538
  content.includes('./lib/tools') ||
539
- content.includes('../lib/tools')
539
+ content.includes('../lib/tools') ||
540
+ content.includes('./tools') ||
541
+ content.includes('../tools')
540
542
  ) {
541
543
  isUsed = true;
542
544
  break;
@@ -19,7 +19,7 @@ const issuesToWatchAsError = [
19
19
  const issuesToWatchAsWarning = [
20
20
  'Migration to ESLint 9 and @iobroker/eslint-config',
21
21
  'Translations update from ioBroker Translation System',
22
- ];
22
+ ];
23
23
 
24
24
  // disable axios caching
25
25
  axios.defaults.headers.common = {
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
- "version": "4.2.0-alpha.3",
2
+ "version": "4.2.0-alpha.5",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
+ "ajv": "^8.17.1",
5
6
  "axios": "^1.11.0",
6
7
  "compare-versions": "^6.1.1",
7
8
  "image-size": "^1.2.0",