From cb4935258ce9653969cf55c02fef03abc61521e9 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sat, 3 Sep 2022 23:34:19 +0100 Subject: [PATCH 1/3] style: forbid using `console` in mermaid src code Adds an eslint rule forbidding using `console` in the mermaid source code. Instead, the `src/logger` should be used instead, so that websites can disable logging. This is allowed in the `cypress/` and `demos/` folder. I've also removed the two instances on `console.log`/`console.error` that currently exist in the mermaid source code. --- .eslintrc.json | 7 +++++++ src/diagrams/git/gitGraphParserV2.spec.js | 2 -- src/diagrams/info/infoRenderer.js | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9c755a0e2..7b8091dde 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,6 +22,7 @@ ], "plugins": ["html", "jest", "jsdoc", "json", "prettier"], "rules": { + "no-console": "error", "no-prototype-builtins": "off", "no-unused-vars": "off", "jsdoc/check-indentation": "off", @@ -47,6 +48,12 @@ "rules": { "prettier/prettier": "off" } + }, + { + "files": ["./cypress/**", "./demos/**"], + "rules": { + "no-console": "off" + } } ] } diff --git a/src/diagrams/git/gitGraphParserV2.spec.js b/src/diagrams/git/gitGraphParserV2.spec.js index 9a5cc59f1..219dbb57c 100644 --- a/src/diagrams/git/gitGraphParserV2.spec.js +++ b/src/diagrams/git/gitGraphParserV2.spec.js @@ -535,8 +535,6 @@ describe('when parsing a gitGraph', function () { testBranch3Merge, ] = Object.values(commits); - console.log(Object.keys(commits)); - expect(mainCommit.branch).toBe('main'); expect(mainCommit.parents).toStrictEqual([]); diff --git a/src/diagrams/info/infoRenderer.js b/src/diagrams/info/infoRenderer.js index 8976abb75..9e81b9ffb 100644 --- a/src/diagrams/info/infoRenderer.js +++ b/src/diagrams/info/infoRenderer.js @@ -49,7 +49,6 @@ export const draw = (text, id, version, diagObj) => { svg.attr('width', 400); // svg.attr('viewBox', '0 0 300 150'); } catch (e) { - console.error(e); log.error('Error while rendering info diagram'); log.error(e.message); } From 106672bc7564a61ab99f0a3e11d792a0061517b3 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sat, 3 Sep 2022 23:57:17 +0100 Subject: [PATCH 2/3] refactor: remove `console.log` in c4Diagram.jison These aren't caught by eslint, since they're in a .jison file. --- src/diagrams/c4/parser/c4Diagram.jison | 208 ++++++++++++------------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/src/diagrams/c4/parser/c4Diagram.jison b/src/diagrams/c4/parser/c4Diagram.jison index 10783db53..03b851458 100644 --- a/src/diagrams/c4/parser/c4Diagram.jison +++ b/src/diagrams/c4/parser/c4Diagram.jison @@ -115,80 +115,80 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multiline");} "C4Dynamic" return 'C4_DYNAMIC'; "C4Deployment" return 'C4_DEPLOYMENT'; -"Person_Ext" { this.begin("person_ext"); console.log('begin person_ext'); return 'PERSON_EXT';} -"Person" { this.begin("person"); console.log('begin person'); return 'PERSON';} -"SystemQueue_Ext" { this.begin("system_ext_queue"); console.log('begin system_ext_queue'); return 'SYSTEM_EXT_QUEUE';} -"SystemDb_Ext" { this.begin("system_ext_db"); console.log('begin system_ext_db'); return 'SYSTEM_EXT_DB';} -"System_Ext" { this.begin("system_ext"); console.log('begin system_ext'); return 'SYSTEM_EXT';} -"SystemQueue" { this.begin("system_queue"); console.log('begin system_queue'); return 'SYSTEM_QUEUE';} -"SystemDb" { this.begin("system_db"); console.log('begin system_db'); return 'SYSTEM_DB';} -"System" { this.begin("system"); console.log('begin system'); return 'SYSTEM';} +"Person_Ext" { this.begin("person_ext"); return 'PERSON_EXT';} +"Person" { this.begin("person"); return 'PERSON';} +"SystemQueue_Ext" { this.begin("system_ext_queue"); return 'SYSTEM_EXT_QUEUE';} +"SystemDb_Ext" { this.begin("system_ext_db"); return 'SYSTEM_EXT_DB';} +"System_Ext" { this.begin("system_ext"); return 'SYSTEM_EXT';} +"SystemQueue" { this.begin("system_queue"); return 'SYSTEM_QUEUE';} +"SystemDb" { this.begin("system_db"); return 'SYSTEM_DB';} +"System" { this.begin("system"); return 'SYSTEM';} -"Boundary" { this.begin("boundary"); console.log('begin boundary'); return 'BOUNDARY';} -"Enterprise_Boundary" { this.begin("enterprise_boundary"); console.log('begin enterprise_boundary'); return 'ENTERPRISE_BOUNDARY';} -"System_Boundary" { this.begin("system_boundary"); console.log('begin system_boundary'); return 'SYSTEM_BOUNDARY';} +"Boundary" { this.begin("boundary"); return 'BOUNDARY';} +"Enterprise_Boundary" { this.begin("enterprise_boundary"); return 'ENTERPRISE_BOUNDARY';} +"System_Boundary" { this.begin("system_boundary"); return 'SYSTEM_BOUNDARY';} -"ContainerQueue_Ext" { this.begin("container_ext_queue"); console.log('begin container_ext_queue'); return 'CONTAINER_EXT_QUEUE';} -"ContainerDb_Ext" { this.begin("container_ext_db"); console.log('begin container_ext_db'); return 'CONTAINER_EXT_DB';} -"Container_Ext" { this.begin("container_ext"); console.log('begin container_ext'); return 'CONTAINER_EXT';} -"ContainerQueue" { this.begin("container_queue"); console.log('begin container_queue'); return 'CONTAINER_QUEUE';} -"ContainerDb" { this.begin("container_db"); console.log('begin container_db'); return 'CONTAINER_DB';} -"Container" { this.begin("container"); console.log('begin container'); return 'CONTAINER';} +"ContainerQueue_Ext" { this.begin("container_ext_queue"); return 'CONTAINER_EXT_QUEUE';} +"ContainerDb_Ext" { this.begin("container_ext_db"); return 'CONTAINER_EXT_DB';} +"Container_Ext" { this.begin("container_ext"); return 'CONTAINER_EXT';} +"ContainerQueue" { this.begin("container_queue"); return 'CONTAINER_QUEUE';} +"ContainerDb" { this.begin("container_db"); return 'CONTAINER_DB';} +"Container" { this.begin("container"); return 'CONTAINER';} -"Container_Boundary" { this.begin("container_boundary"); console.log('begin container_boundary'); return 'CONTAINER_BOUNDARY';} +"Container_Boundary" { this.begin("container_boundary"); return 'CONTAINER_BOUNDARY';} -"ComponentQueue_Ext" { this.begin("component_ext_queue"); console.log('begin component_ext_queue'); return 'COMPONENT_EXT_QUEUE';} -"ComponentDb_Ext" { this.begin("component_ext_db"); console.log('begin component_ext_db'); return 'COMPONENT_EXT_DB';} -"Component_Ext" { this.begin("component_ext"); console.log('begin component_ext'); return 'COMPONENT_EXT';} -"ComponentQueue" { this.begin("component_queue"); console.log('begin component_queue'); return 'COMPONENT_QUEUE';} -"ComponentDb" { this.begin("component_db"); console.log('begin component_db'); return 'COMPONENT_DB';} -"Component" { this.begin("component"); console.log('begin component'); return 'COMPONENT';} +"ComponentQueue_Ext" { this.begin("component_ext_queue"); return 'COMPONENT_EXT_QUEUE';} +"ComponentDb_Ext" { this.begin("component_ext_db"); return 'COMPONENT_EXT_DB';} +"Component_Ext" { this.begin("component_ext"); return 'COMPONENT_EXT';} +"ComponentQueue" { this.begin("component_queue"); return 'COMPONENT_QUEUE';} +"ComponentDb" { this.begin("component_db"); return 'COMPONENT_DB';} +"Component" { this.begin("component"); return 'COMPONENT';} -"Deployment_Node" { this.begin("node"); console.log('begin node'); return 'NODE';} -"Node" { this.begin("node"); console.log('begin node'); return 'NODE';} -"Node_L" { this.begin("node_l"); console.log('begin node_l'); return 'NODE_L';} -"Node_R" { this.begin("node_r"); console.log('begin node_r'); return 'NODE_R';} +"Deployment_Node" { this.begin("node"); return 'NODE';} +"Node" { this.begin("node"); return 'NODE';} +"Node_L" { this.begin("node_l"); return 'NODE_L';} +"Node_R" { this.begin("node_r"); return 'NODE_R';} -"Rel" { this.begin("rel"); console.log('begin rel'); return 'REL';} -"BiRel" { this.begin("birel"); console.log('begin birel'); return 'BIREL';} -"Rel_Up" { this.begin("rel_u"); console.log('begin rel_u'); return 'REL_U';} -"Rel_U" { this.begin("rel_u"); console.log('begin rel_u'); return 'REL_U';} -"Rel_Down" { this.begin("rel_d"); console.log('begin rel_d'); return 'REL_D';} -"Rel_D" { this.begin("rel_d"); console.log('begin rel_d'); return 'REL_D';} -"Rel_Left" { this.begin("rel_l"); console.log('begin rel_l'); return 'REL_L';} -"Rel_L" { this.begin("rel_l"); console.log('begin rel_l'); return 'REL_L';} -"Rel_Right" { this.begin("rel_r"); console.log('begin rel_r'); return 'REL_R';} -"Rel_R" { this.begin("rel_r"); console.log('begin rel_r'); return 'REL_R';} -"Rel_Back" { this.begin("rel_b"); console.log('begin rel_b'); return 'REL_B';} -"RelIndex" { this.begin("rel_index"); console.log('begin rel_index'); return 'REL_INDEX';} +"Rel" { this.begin("rel"); return 'REL';} +"BiRel" { this.begin("birel"); return 'BIREL';} +"Rel_Up" { this.begin("rel_u"); return 'REL_U';} +"Rel_U" { this.begin("rel_u"); return 'REL_U';} +"Rel_Down" { this.begin("rel_d"); return 'REL_D';} +"Rel_D" { this.begin("rel_d"); return 'REL_D';} +"Rel_Left" { this.begin("rel_l"); return 'REL_L';} +"Rel_L" { this.begin("rel_l"); return 'REL_L';} +"Rel_Right" { this.begin("rel_r"); return 'REL_R';} +"Rel_R" { this.begin("rel_r"); return 'REL_R';} +"Rel_Back" { this.begin("rel_b"); return 'REL_B';} +"RelIndex" { this.begin("rel_index"); return 'REL_INDEX';} -"UpdateElementStyle" { this.begin("update_el_style"); console.log('begin update_el_style'); return 'UPDATE_EL_STYLE';} -"UpdateRelStyle" { this.begin("update_rel_style"); console.log('begin update_rel_style'); return 'UPDATE_REL_STYLE';} -"UpdateLayoutConfig" { this.begin("update_layout_config"); console.log('begin update_layout_config'); return 'UPDATE_LAYOUT_CONFIG';} +"UpdateElementStyle" { this.begin("update_el_style"); return 'UPDATE_EL_STYLE';} +"UpdateRelStyle" { this.begin("update_rel_style"); return 'UPDATE_REL_STYLE';} +"UpdateLayoutConfig" { this.begin("update_layout_config"); return 'UPDATE_LAYOUT_CONFIG';} <> return "EOF_IN_STRUCT"; -[(][ ]*[,] { console.log('begin attribute with ATTRIBUTE_EMPTY'); this.begin("attribute"); return "ATTRIBUTE_EMPTY";} -[(] { console.log('begin attribute'); this.begin("attribute"); } -[)] { console.log('STOP attribute'); this.popState();console.log('STOP diagram'); this.popState();} +[(][ ]*[,] { this.begin("attribute"); return "ATTRIBUTE_EMPTY";} +[(] { this.begin("attribute"); } +[)] { this.popState();this.popState();} -",," { console.log(',,'); return 'ATTRIBUTE_EMPTY';} -"," { console.log(','); } -[ ]*["]["] { console.log('ATTRIBUTE_EMPTY'); return 'ATTRIBUTE_EMPTY';} -[ ]*["] { console.log('begin string'); this.begin("string");} -["] { console.log('STOP string'); this.popState(); } -[^"]* { console.log('STR'); return "STR";} +",," { return 'ATTRIBUTE_EMPTY';} +"," { } +[ ]*["]["] { return 'ATTRIBUTE_EMPTY';} +[ ]*["] { this.begin("string");} +["] { this.popState(); } +[^"]* { return "STR";} -[ ]*[\$] { console.log('begin string_kv'); this.begin("string_kv");} -[^=]* { console.log('STR_KEY'); this.begin("string_kv_key"); return "STR_KEY";} -[=][ ]*["] { console.log('begin string_kv_value'); this.popState(); this.begin("string_kv_value"); } -[^"]+ { console.log('STR_VALUE'); return "STR_VALUE";} -["] { console.log('STOP string_kv_value'); this.popState(); this.popState(); } +[ ]*[\$] { this.begin("string_kv");} +[^=]* { this.begin("string_kv_key"); return "STR_KEY";} +[=][ ]*["] { this.popState(); this.begin("string_kv_value"); } +[^"]+ { return "STR_VALUE";} +["] { this.popState(); this.popState(); } -[^,]+ { console.log('not STR'); return "STR";} +[^,]+ { return "STR";} -'{' { /* this.begin("lbrace"); */ console.log('begin boundary block'); return "LBRACE";} -'}' { /* this.popState(); */ console.log('STOP boundary block'); return "RBRACE";} +'{' { /* this.begin("lbrace"); */ return "LBRACE";} +'}' { /* this.popState(); */ return "RBRACE";} [\s]+ return 'SPACE'; [\n\r]+ return 'EOL'; @@ -231,7 +231,7 @@ directive ; openDirective - : open_directive { console.log("open_directive: ", $1); yy.parseDirective('%%{', 'open_directive'); } + : open_directive { yy.parseDirective('%%{', 'open_directive'); } ; typeDirective @@ -239,11 +239,11 @@ typeDirective ; argDirective - : arg_directive { $1 = $1.trim().replace(/'/g, '"'); console.log("arg_directive: ", $1); yy.parseDirective($1, 'arg_directive'); } + : arg_directive { $1 = $1.trim().replace(/'/g, '"'); yy.parseDirective($1, 'arg_directive'); } ; closeDirective - : close_directive { console.log("close_directive: ", $1); yy.parseDirective('}%%', 'close_directive', 'c4Context'); } + : close_directive { yy.parseDirective('}%%', 'close_directive', 'c4Context'); } ; graphConfig @@ -285,13 +285,13 @@ boundaryStartStatement ; boundaryStart - : ENTERPRISE_BOUNDARY attributes {console.log($1,JSON.stringify($2)); $2.splice(2, 0, 'ENTERPRISE'); yy.addPersonOrSystemBoundary(...$2); $$=$2;} - | SYSTEM_BOUNDARY attributes {console.log($1,JSON.stringify($2)); $2.splice(2, 0, 'ENTERPRISE'); yy.addPersonOrSystemBoundary(...$2); $$=$2;} - | BOUNDARY attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystemBoundary(...$2); $$=$2;} - | CONTAINER_BOUNDARY attributes {console.log($1,JSON.stringify($2)); $2.splice(2, 0, 'CONTAINER'); yy.addContainerBoundary(...$2); $$=$2;} - | NODE attributes {console.log($1,JSON.stringify($2)); yy.addDeploymentNode('node', ...$2); $$=$2;} - | NODE_L attributes {console.log($1,JSON.stringify($2)); yy.addDeploymentNode('nodeL', ...$2); $$=$2;} - | NODE_R attributes {console.log($1,JSON.stringify($2)); yy.addDeploymentNode('nodeR', ...$2); $$=$2;} + : ENTERPRISE_BOUNDARY attributes {$2.splice(2, 0, 'ENTERPRISE'); yy.addPersonOrSystemBoundary(...$2); $$=$2;} + | SYSTEM_BOUNDARY attributes {$2.splice(2, 0, 'ENTERPRISE'); yy.addPersonOrSystemBoundary(...$2); $$=$2;} + | BOUNDARY attributes {yy.addPersonOrSystemBoundary(...$2); $$=$2;} + | CONTAINER_BOUNDARY attributes {$2.splice(2, 0, 'CONTAINER'); yy.addContainerBoundary(...$2); $$=$2;} + | NODE attributes {yy.addDeploymentNode('node', ...$2); $$=$2;} + | NODE_L attributes {yy.addDeploymentNode('nodeL', ...$2); $$=$2;} + | NODE_R attributes {yy.addDeploymentNode('nodeR', ...$2); $$=$2;} ; boundaryStopStatement @@ -305,48 +305,48 @@ diagramStatements ; diagramStatement - : PERSON attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystem('person', ...$2); $$=$2;} - | PERSON_EXT attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystem('external_person', ...$2); $$=$2;} - | SYSTEM attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystem('system', ...$2); $$=$2;} - | SYSTEM_DB attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystem('system_db', ...$2); $$=$2;} - | SYSTEM_QUEUE attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystem('system_queue', ...$2); $$=$2;} - | SYSTEM_EXT attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystem('external_system', ...$2); $$=$2;} - | SYSTEM_EXT_DB attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystem('external_system_db', ...$2); $$=$2;} - | SYSTEM_EXT_QUEUE attributes {console.log($1,JSON.stringify($2)); yy.addPersonOrSystem('external_system_queue', ...$2); $$=$2;} - | CONTAINER attributes {console.log($1,JSON.stringify($2)); yy.addContainer('container', ...$2); $$=$2;} - | CONTAINER_DB attributes {console.log($1,JSON.stringify($2)); yy.addContainer('container_db', ...$2); $$=$2;} - | CONTAINER_QUEUE attributes {console.log($1,JSON.stringify($2)); yy.addContainer('container_queue', ...$2); $$=$2;} - | CONTAINER_EXT attributes {console.log($1,JSON.stringify($2)); yy.addContainer('external_container', ...$2); $$=$2;} - | CONTAINER_EXT_DB attributes {console.log($1,JSON.stringify($2)); yy.addContainer('external_container_db', ...$2); $$=$2;} - | CONTAINER_EXT_QUEUE attributes {console.log($1,JSON.stringify($2)); yy.addContainer('external_container_queue', ...$2); $$=$2;} - | COMPONENT attributes {console.log($1,JSON.stringify($2)); yy.addComponent('component', ...$2); $$=$2;} - | COMPONENT_DB attributes {console.log($1,JSON.stringify($2)); yy.addComponent('component_db', ...$2); $$=$2;} - | COMPONENT_QUEUE attributes {console.log($1,JSON.stringify($2)); yy.addComponent('component_queue', ...$2); $$=$2;} - | COMPONENT_EXT attributes {console.log($1,JSON.stringify($2)); yy.addComponent('external_component', ...$2); $$=$2;} - | COMPONENT_EXT_DB attributes {console.log($1,JSON.stringify($2)); yy.addComponent('external_component_db', ...$2); $$=$2;} - | COMPONENT_EXT_QUEUE attributes {console.log($1,JSON.stringify($2)); yy.addComponent('external_component_queue', ...$2); $$=$2;} + : PERSON attributes {yy.addPersonOrSystem('person', ...$2); $$=$2;} + | PERSON_EXT attributes {yy.addPersonOrSystem('external_person', ...$2); $$=$2;} + | SYSTEM attributes {yy.addPersonOrSystem('system', ...$2); $$=$2;} + | SYSTEM_DB attributes {yy.addPersonOrSystem('system_db', ...$2); $$=$2;} + | SYSTEM_QUEUE attributes {yy.addPersonOrSystem('system_queue', ...$2); $$=$2;} + | SYSTEM_EXT attributes {yy.addPersonOrSystem('external_system', ...$2); $$=$2;} + | SYSTEM_EXT_DB attributes {yy.addPersonOrSystem('external_system_db', ...$2); $$=$2;} + | SYSTEM_EXT_QUEUE attributes {yy.addPersonOrSystem('external_system_queue', ...$2); $$=$2;} + | CONTAINER attributes {yy.addContainer('container', ...$2); $$=$2;} + | CONTAINER_DB attributes {yy.addContainer('container_db', ...$2); $$=$2;} + | CONTAINER_QUEUE attributes {yy.addContainer('container_queue', ...$2); $$=$2;} + | CONTAINER_EXT attributes {yy.addContainer('external_container', ...$2); $$=$2;} + | CONTAINER_EXT_DB attributes {yy.addContainer('external_container_db', ...$2); $$=$2;} + | CONTAINER_EXT_QUEUE attributes {yy.addContainer('external_container_queue', ...$2); $$=$2;} + | COMPONENT attributes {yy.addComponent('component', ...$2); $$=$2;} + | COMPONENT_DB attributes {yy.addComponent('component_db', ...$2); $$=$2;} + | COMPONENT_QUEUE attributes {yy.addComponent('component_queue', ...$2); $$=$2;} + | COMPONENT_EXT attributes {yy.addComponent('external_component', ...$2); $$=$2;} + | COMPONENT_EXT_DB attributes {yy.addComponent('external_component_db', ...$2); $$=$2;} + | COMPONENT_EXT_QUEUE attributes {yy.addComponent('external_component_queue', ...$2); $$=$2;} | boundaryStatement - | REL attributes {console.log($1,JSON.stringify($2)); yy.addRel('rel', ...$2); $$=$2;} - | BIREL attributes {console.log($1,JSON.stringify($2)); yy.addRel('birel', ...$2); $$=$2;} - | REL_U attributes {console.log($1,JSON.stringify($2)); yy.addRel('rel_u', ...$2); $$=$2;} - | REL_D attributes {console.log($1,JSON.stringify($2)); yy.addRel('rel_d', ...$2); $$=$2;} - | REL_L attributes {console.log($1,JSON.stringify($2)); yy.addRel('rel_l', ...$2); $$=$2;} - | REL_R attributes {console.log($1,JSON.stringify($2)); yy.addRel('rel_r', ...$2); $$=$2;} - | REL_B attributes {console.log($1,JSON.stringify($2)); yy.addRel('rel_b', ...$2); $$=$2;} - | REL_INDEX attributes {console.log($1,JSON.stringify($2)); $2.splice(0, 1); yy.addRel('rel', ...$2); $$=$2;} - | UPDATE_EL_STYLE attributes {console.log($1,JSON.stringify($2)); yy.updateElStyle('update_el_style', ...$2); $$=$2;} - | UPDATE_REL_STYLE attributes {console.log($1,JSON.stringify($2)); yy.updateRelStyle('update_rel_style', ...$2); $$=$2;} - | UPDATE_LAYOUT_CONFIG attributes {console.log($1,JSON.stringify($2)); yy.updateLayoutConfig('update_layout_config', ...$2); $$=$2;} + | REL attributes {yy.addRel('rel', ...$2); $$=$2;} + | BIREL attributes {yy.addRel('birel', ...$2); $$=$2;} + | REL_U attributes {yy.addRel('rel_u', ...$2); $$=$2;} + | REL_D attributes {yy.addRel('rel_d', ...$2); $$=$2;} + | REL_L attributes {yy.addRel('rel_l', ...$2); $$=$2;} + | REL_R attributes {yy.addRel('rel_r', ...$2); $$=$2;} + | REL_B attributes {yy.addRel('rel_b', ...$2); $$=$2;} + | REL_INDEX attributes {$2.splice(0, 1); yy.addRel('rel', ...$2); $$=$2;} + | UPDATE_EL_STYLE attributes {yy.updateElStyle('update_el_style', ...$2); $$=$2;} + | UPDATE_REL_STYLE attributes {yy.updateRelStyle('update_rel_style', ...$2); $$=$2;} + | UPDATE_LAYOUT_CONFIG attributes {yy.updateLayoutConfig('update_layout_config', ...$2); $$=$2;} ; attributes - : attribute { console.log('PUSH ATTRIBUTE: ', $1); $$ = [$1]; } - | attribute attributes { console.log('PUSH ATTRIBUTE: ', $1); $2.unshift($1); $$=$2;} + : attribute { $$ = [$1]; } + | attribute attributes { $2.unshift($1); $$=$2;} ; attribute : STR { $$ = $1.trim(); } - | STR_KEY STR_VALUE { console.log('kv: ', $1, $2); let kv={}; kv[$1.trim()]=$2.trim(); $$=kv; } + | STR_KEY STR_VALUE { let kv={}; kv[$1.trim()]=$2.trim(); $$=kv; } | ATTRIBUTE { $$ = $1.trim(); } | ATTRIBUTE_EMPTY { $$ = ""; } ; From 22d20cc76e670ec521c191519a2ee117dde15784 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Tue, 6 Sep 2022 03:22:18 +0100 Subject: [PATCH 3/3] ci: lint .jison files for any console.log() Converts the *.jison files into .js, then lints them using just the `no-console` rule. To keep things simple, I've just made this run only on CI. If we want to do more complex linting on `*.jison` files, it might be worth making an `eslint-plugin-jison`, so that we can directly parse jison in ESLint. --- .github/workflows/lint.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 050667a8f..e538372ad 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -37,3 +37,17 @@ jobs: - name: Run Linting run: yarn lint + - name: Check no `console.log()` in .jison files + # ESLint can't parse .jison files directly + # In the future, it might be worth making a `eslint-plugin-jison`, so + # that this will be built into the `yarn lint` command. + run: | + shopt -s globstar + mkdir -p tmp/ + for jison_file in src/**/*.jison; do + outfile="tmp/$(basename -- "$jison_file" .jison)-jison.js" + echo "Converting $jison_file to $outfile" + # default module-type (CJS) always adds a console.log() + yarn jison "$jison_file" --outfile "$outfile" --module-type "amd" + done + yarn eslint --no-eslintrc --rule no-console:error --parser "@babel/eslint-parser" "./tmp/*-jison.js"