multicloud_rule_manager 1.1.11 → 1.1.12
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/package.json +1 -1
- package/utils/ruleValidator.js +16 -6
package/package.json
CHANGED
package/utils/ruleValidator.js
CHANGED
|
@@ -14,10 +14,8 @@ export function validateRule(fileName, content) {
|
|
|
14
14
|
for (let i = 0; i < lines.length; i++) {
|
|
15
15
|
const line = lines[i];
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
hasThen = true;
|
|
20
|
-
inThen = true;
|
|
17
|
+
// verifica blocco when {} then {}
|
|
18
|
+
if (!hasWhenThenBlock(content, file)) {
|
|
21
19
|
continue;
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -44,7 +42,7 @@ export function validateRule(fileName, content) {
|
|
|
44
42
|
if (char === "{") stack.push("{");
|
|
45
43
|
if (char === "}") {
|
|
46
44
|
if (stack.length === 0) {
|
|
47
|
-
return { valid: false, message: `Parentesi graffe non bilanciate in ${fileName} riga ${i+1}` };
|
|
45
|
+
return { valid: false, message: `Parentesi graffe non bilanciate in ${fileName} riga ${i + 1}` };
|
|
48
46
|
}
|
|
49
47
|
stack.pop();
|
|
50
48
|
}
|
|
@@ -54,7 +52,7 @@ export function validateRule(fileName, content) {
|
|
|
54
52
|
const singleQuotes = (line.match(/'/g) || []).length;
|
|
55
53
|
const doubleQuotes = (line.match(/"/g) || []).length;
|
|
56
54
|
if (singleQuotes % 2 !== 0 || doubleQuotes % 2 !== 0) {
|
|
57
|
-
return { valid: false, message: `Apici non bilanciati in ${fileName} riga ${i+1}` };
|
|
55
|
+
return { valid: false, message: `Apici non bilanciati in ${fileName} riga ${i + 1}` };
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
|
|
@@ -74,4 +72,16 @@ export function validateRule(fileName, content) {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
return { valid: true };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function hasWhenThenBlock(content, fileName) {
|
|
78
|
+
// regex: quando compare 'when' seguito da {, e '} then {' con eventuali spazi
|
|
79
|
+
const whenRegex = /when\s*\{/i;
|
|
80
|
+
const thenRegex = /\}\s*then\s*\{/i;
|
|
81
|
+
|
|
82
|
+
if (!whenRegex.test(content) || !thenRegex.test(content)) {
|
|
83
|
+
console.error(`❌ Il file ${fileName} deve contenere un blocco "when {} then {}"`);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
77
87
|
}
|