code-complexity-plugin icon indicating copy to clipboard operation
code-complexity-plugin copied to clipboard

feat: javascript

Open raylras opened this issue 1 year ago • 2 comments

Add support for JavaScript language and its dialects (TypeScript, etc.).

Note that the JavaScript plugin dependency does not exist in IC (IDEA Community), but in WebStorm or IU (IDEA Ultimate).

Todo List:

  • [ ] Unit Test

raylras avatar Oct 26 '24 05:10 raylras

The complexity can be displayed, but the percentages don't seem quite accurate. As a JavaScript/TypeScript newbie, I might need some help with this PR.

raylras avatar Oct 26 '24 05:10 raylras

Hi @raylras Thank you for your interest in this project and the effort to add JS support. I'm also not a JS engineer so cannot help you with the language specifics. However, in order to calculate complexity you mostly need to work with the tree of PsiElements. It involves a lot of debugging. So to continue I would suggest you :

  • first to read this article https://www.sonarsource.com/docs/CognitiveComplexity.pdf
  • At the end of the article there is a list of examples with the expected complexity. Please rewrite them in JS and put in separate file in tests like this one https://github.com/nikolaikopernik/code-complexity-plugin/blob/main/src/test/testData/kotlin/ExamplesFromTheArticleTest.kt
  • Extend BaseComplexityTest and write an JS implementation (example in KotlinComplexityCalculationTest.kt). This test will read methods from the example file, calculate the complexity per method and compare it with the annotation.

This will be a good indication of how accurate you implemented a complexity score. After that it's just a lot of debugging of PsiElements structures for JS in order to fit the expected complexity.

Also would suggest you to start with a single dialect first.

nikolaikopernik avatar Oct 27 '24 08:10 nikolaikopernik