hediet / vscode-drawio

This unofficial extension integrates Draw.io (also known as diagrams.net) into VS Code.
https://marketplace.visualstudio.com/items?itemName=hediet.vscode-drawio
GNU General Public License v3.0
9.02k stars 406 forks source link

Code Review suggestion: Refact the if block #342

Open pedrohenriquebr opened 1 year ago

pedrohenriquebr commented 1 year ago

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

hediet commented 1 year ago

Feel free to provide a PR!