kisstkondoros / codemetrics

VSCode extension which shows the complexity information for TypeScript class members
Other
404 stars 20 forks source link

I find "complexity" measures and levels rather confusing #87

Closed albcl closed 1 year ago

albcl commented 3 years ago

I see the potential of this extension and how useful it can be. However, maybe it's me, but I find it confusing when it basically complains about pretty much everything... Or maybe that's what I'm having.

I have taken the following sample from this issue just added a ReactNode return and undefined as type (to avoid possible complains regarding those) It returns Complexity is 8 It's time to do something... and complains about pretty much every line.

function tagNameToType(tagname: string): ReactNode {
  let type: string | undefined;
  switch (tagname) {
    case 'div':
      type = 'element';
    case 'paper-input':
    case 'input':
      type = 'input';
    default:
      type = undefined;
  }
  return <p>{type}</p>;
}
Screenshot 2021-02-06 at 17 16 30

I appreciate the code lens pointing out what bits should be reconsidered but there is not really an explanation so in some cases it gets difficult to really understand what's the problem and what could be the solution. For example, just telling me JSX Element <p>{type}</p> in the image above doesn't really help me understand the problem I'm facing.

Neither I get to understand why Function declaration or Arrow function are problematic with a 1 on complexity.

I know I can change the extension's config to remove the complexity on those cases where I don't think we should get a 1 but that's not exactly my question/issue here.

I just think the explanations should be a bit richer and clearer. For example if I happen to have more than one return it could say Return statement (single-entry single-exit principle): return <p>{type}</p>.

I hope it makes sense 😅

kisstkondoros commented 3 years ago

Thanks for reaching out!

Yes the default settings might be too strict, I admit that and like you also said, they can be fine tuned for personal / team taste so I have spent no time on doing that myself (although I should have, considering how much people get angry about it).

I like the idea, but I see some issues:

I think the idea to show some hint inline is great, and I might get back to this in the future.

As always PR's are more than welcome! :smile:

kisstkondoros commented 1 year ago

I have no plans about this, closing.