codemetrics icon indicating copy to clipboard operation
codemetrics copied to clipboard

I find "complexity" measures and levels rather confusing

Open albcl opened this issue 4 years ago • 1 comments

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 😅

albcl avatar Feb 06 '21 17:02 albcl

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:

  • the current analysis could maybe be tuned to highlight some of the simple problems (more than 1 return statement, switch-case hell etc), but all that has serious performance cost. (I think even for "simple" cases, it might be non trivial to do it)
  • It's great if the hint fits in ~20 characters, remember the space is limited, what / where should be shown if there is no space left?
  • Are there some better tools for this purpose?
  • I think the purpose of this extension never was to really teach design patterns and principles. I think it should be enough to point out that there is a problem, people should take the extra steps to investigate and understand it and make the best out of it.

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 avatar Feb 11 '21 22:02 kisstkondoros

I have no plans about this, closing.

kisstkondoros avatar Dec 28 '22 13:12 kisstkondoros