vscode-drawio icon indicating copy to clipboard operation
vscode-drawio copied to clipboard

Code Review suggestion: Refact the if block

Open pedrohenriquebr opened this issue 1 year ago • 1 comments

In the code

https://github.com/hediet/vscode-drawio/blob/fe9426343bdd75bf981b7e5f7f731c2c46543194/drawio-custom-plugins/src/linkSelectedNodeWithData.ts#L24-L35

my suggestion is to negate the condition and return. This way we can improve readability.


if (cell == null)
    return;

const data = getLinkedData(cell); 
const label = getLabelTextOfCell(cell); 

if (!data && !label.match(/#([a-zA-Z0-9_]+)/)) {
  return;
} 

sendEvent({ event: "nodeSelected", label, linkedData: data }); 
evt.consume(); 
}); 

https://github.com/hediet/vscode-drawio/issues/342#tasklist-block-f58d4eed-5010-4184-aaf4-9eba6531b67a

pedrohenriquebr avatar Oct 24 '22 16:10 pedrohenriquebr

Feel free to provide a PR!

hediet avatar Oct 25 '22 13:10 hediet