kisstkondoros / codemetrics

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

Feature request: Skip/Suppress mechanic #21

Closed Tsarev closed 7 years ago

Tsarev commented 7 years ago

It would be nice to have a certain way to ignore/suppress specific functions checks. I would like the code metric algorithm to skip certain functions by passing an ignore tag or something similar like eslint would be nice: http://eslint.org/docs/user-guide/configuring.html#configuring-rules

For an instance:

/* @cm ignore-next-function */
this.fucntionName = new Funciton()
{
 ...
}

Developing under ES3 sometimes requires larger constructs which I would manually like to ignore or skip in some way.

kisstkondoros commented 7 years ago

I'm personally against such annotations, because I think they do harm at the long run. One can get used to it and include it where complexity is high, and later everything just stay like that. IMO it does not really matter if it is ES3, ES5, ES6, TS or whatever.

But I would like to help you with your problem. Perhaps we could figure out a configuration which would suite you better.

Could you please provide a code sample which you have problems with?

Tsarev commented 7 years ago

The problem is quite common. Take the jQuery-Migrate source for an instance: https://code.jquery.com/jquery-migrate-3.0.0.js

image

The type of structure enforces a function evaluation and thus results in an complexity outbreak which always surpasses the normal expectations (e.g. Complexity 157).

I agree that in general if supplied with means to skip an evaluation could result in not fulfilling the true intent of your plugin, but if you try to process almost any jQuery-Plugin with it, you will notice the same pattern of behavior on the main/first functional encapsulation.

kisstkondoros commented 7 years ago

Ok, now I see what the problem is 😄

I had a quick look what other JS complexity analyzer tools provide to suppress such stuff, with no luck. If I would invent a comment / annotation to suppress complexity calculation that would further decrease readability of the code. Also now you are using my tool (maybe not any more 😄 ), tomorrow / next week / next year you'll use something else, leaving behind such comments / annotations in the code base...

I've also had an idea to suppress complexity information where an IIFE is used, but that would also be a mistake.

To be honest I feel that having 157 on jQuery.migrate's code is actually correct. One just have to have a look at that mess...

I'm sorry but I'll close this feature request, because: