refactor(ui): resolve var declarations and reduce cognitive complexity in pipeline.js - #173
refactor(ui): resolve var declarations and reduce cognitive complexity in pipeline.js#173bhagathkrishnacdac wants to merge 5 commits into
Conversation
…y in pipeline.js Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
There was a problem hiding this comment.
Pull request overview
This PR refactors the BESS pipeline visualization script (bessctl/static/pipeline.js) to modernize variable declarations and decompose get_edge_label() and graph_to_dot() into smaller helper functions, with the stated goal of preserving existing rendering/label behavior while reducing complexity.
Changes:
- Replaced legacy
vardeclarations withconst/let. - Split edge-label computation/formatting into helper functions (
calculate_*,format_*). - Refactored DOT generation into modular helpers for option gathering, node generation, and edge generation.
Comments suppressed due to low confidence (1)
bessctl/static/pipeline.js:203
- create_module_node() takes an
optionsparameter but never uses it, and also forwardsoptionsinto gates_to_str() even though gates_to_str only accepts (gates, gate_type). This makes the data flow harder to follow and can trigger unused-parameter linting. Remove the unused parameter and stop passing it through (and consider also dropping the extra argument at the call site).
function create_module_node(module, module_name, options) {
const desc = module.desc ? `<font point-size="9">${module.desc}</font>` : '';
// Original gates_to_str might need options
const igates = module.show_igates ? gates_to_str(module.igates, 'igate', options) : '';
const ogates = module.show_ogates ? gates_to_str(module.ogates, 'ogate', options) : '';
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
Signed-off-by: bhagathkrishnacdac <bhagath.krishna@cdac.in>
gab-arrobo
left a comment
There was a problem hiding this comment.
I see lots of warnings when applying patch using git. Please address these issues
$ git apply pr.patch
pr.patch:101: trailing whitespace.
function get_edge_label(stats, options) {
pr.patch:102: trailing whitespace.
if (!stats || stats.length === 0) {
pr.patch:103: trailing whitespace.
return format_html_label('?');
pr.patch:104: trailing whitespace.
}
pr.patch:105: trailing whitespace.
warning: squelched 175 whitespace errors
warning: 180 lines add whitespace errors.
|
|
||
| return ` "${module_name}":${out_port} -> "${gate.name}":${in_port}${label}\n`; | ||
| } | ||
|
|
There was a problem hiding this comment.
Remove extra empty line
|
I've added a "whitespace" CI job that flags whitespace-related formatting issues. To fix the issues with this PR, run "pre-commit run --all-files" locally. |
Overview
This PR improves the code quality of the pipeline visualization script (bessctl/static/pipeline.js) by modernizing variable declarations and reducing function complexity.
Key Changes
No modifications were made to the visual layout generation, data collection, or UI-bound operations. The generated Graphviz DOT files and label rounding logic match the original behavior.