multicloud_rule_manager 1.1.8 → 1.1.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multicloud_rule_manager",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "CLI interna per retrieve/upload con token",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -13,62 +13,89 @@ export function validateRule(fileName, content) {
13
13
  let inThen = false;
14
14
 
15
15
  for (let i = 0; i < lines.length; i++) {
16
- const line = lines[i];
17
-
18
- // controllo blocchi when/then
19
- if (line.includes("when {")) hasWhen = true;
20
- if (line.includes("}then {")) {
21
- hasThen = true;
22
- inThen = true;
23
- continue; // skip linea "}then {"
24
- }
16
+ const lines = content.split("\n");
17
+
18
+ let stack = [];
19
+ let hasWhen = false;
20
+ let hasThen = false;
21
+ let thenCode = "";
22
+ let inThen = false;
23
+ let thenStack = []; // stack per parentesi dentro then
24
+
25
+ for (let i = 0; i < lines.length; i++) {
26
+ const line = lines[i];
25
27
 
26
- if (inThen) {
27
- if (line.includes("}")) {
28
- inThen = false;
29
- } else {
30
- thenCode += line + "\n"; // raccogli solo il codice JS nel then
28
+ // controllo blocchi when/then
29
+ if (line.includes("when {")) hasWhen = true;
30
+ if (line.includes("}then {")) {
31
+ hasThen = true;
32
+ inThen = true;
33
+ continue; // skip linea "}then {"
34
+ }
35
+
36
+ // dentro then {}
37
+ if (inThen) {
38
+ // aggiungi linea al codice then
39
+ thenCode += line + "\n";
40
+
41
+ // aggiorna stack interno per bilanciamento
42
+ for (const char of line) {
43
+ if (char === "{") thenStack.push("{");
44
+ if (char === "}") {
45
+ if (thenStack.length === 0) {
46
+ inThen = false; // chiuso il then
47
+ } else {
48
+ thenStack.pop();
49
+ }
50
+ }
51
+ }
52
+
53
+ // esci dal then se stack vuoto
54
+ if (thenStack.length === 0 && line.includes("}")) {
55
+ inThen = false;
56
+ }
57
+
58
+ continue; // passa al prossimo
31
59
  }
32
- }
33
60
 
34
- // check parentesi graffe
35
- for (const char of line) {
36
- if (char === "{") stack.push("{");
37
- if (char === "}") {
38
- if (stack.length === 0) {
39
- console.error(`❌ Parentesi graffe non bilanciate in ${fileName} riga ${i+1}`);
40
- return false;
61
+ // check parentesi graffe globali
62
+ for (const char of line) {
63
+ if (char === "{") stack.push("{");
64
+ if (char === "}") {
65
+ if (stack.length === 0) {
66
+ console.error(`❌ Parentesi graffe non bilanciate in ${fileName} riga ${i + 1}`);
67
+ return false;
68
+ }
69
+ stack.pop();
41
70
  }
42
- stack.pop();
43
71
  }
72
+
73
+ // check apici
74
+ const singleQuotes = (line.match(/'/g) || []).length;
75
+ const doubleQuotes = (line.match(/"/g) || []).length;
76
+ if (singleQuotes % 2 !== 0 || doubleQuotes % 2 !== 0) {
77
+ console.error(`❌ Apici non bilanciati in ${fileName} riga ${i + 1}`);
78
+ return false;
79
+ }
80
+ }
81
+
82
+ if (!hasWhen || !hasThen) {
83
+ console.error(`❌ Il file ${fileName} deve contenere un blocco "when {} then {}"`);
84
+ return false;
44
85
  }
45
86
 
46
- // check apici
47
- const singleQuotes = (line.match(/'/g) || []).length;
48
- const doubleQuotes = (line.match(/"/g) || []).length;
49
- if (singleQuotes % 2 !== 0 || doubleQuotes % 2 !== 0) {
50
- console.error(`❌ Apici non bilanciati in ${fileName} riga ${i+1}`);
87
+ if (stack.length > 0) {
88
+ console.error(`❌ Parentesi graffe aperte non chiuse in ${fileName}`);
51
89
  return false;
52
90
  }
53
- }
54
-
55
- if (!hasWhen || !hasThen) {
56
- console.error(`❌ Il file ${fileName} deve contenere un blocco "when {} then {}"`);
57
- return false;
58
- }
59
-
60
- if (stack.length > 0) {
61
- console.error(`❌ Parentesi graffe aperte non chiuse in ${fileName}`);
62
- return false;
63
- }
64
-
65
- // check sintassi JS del codice dentro then {}
66
- try {
67
- if (thenCode.trim()) esprima.parseScript(thenCode, { tolerant: true });
68
- } catch (err) {
69
- console.error(`❌ Errore sintassi JS in ${fileName}: ${err.message}`);
70
- return false;
71
- }
72
-
73
- return true;
74
- }
91
+
92
+ // check sintassi JS dentro then {}
93
+ try {
94
+ if (thenCode.trim()) esprima.parseScript(thenCode, { tolerant: true });
95
+ } catch (err) {
96
+ console.error(`❌ Errore sintassi JS in ${fileName}: ${err.message}`);
97
+ return false;
98
+ }
99
+
100
+ return true;
101
+ }