Oleg Savickij Oleg Savickij - 5 months ago 28
Javascript Question

How procced cyclomatic complexity in such javascript code?

i have some problems with complexity in my javascript. It looks like:

function mainFunction(scope, element) {
var eventHandlerMap = {
'firstEvent': firstEventHandler,
'secondEvent': secondEventHandler,

function firstEventHandler(element) {
if (element) {
//some code
} else {
//some code
function secondEventHandler(element) {
//some code
//and other EventHandler functions

Now mainFunction has complexity of 41, but my sonar allows no more than 10. I dont good at javascript and dont have ideas how fix it.


The way complexity is computed should be changed by next plugin version (see https://jira.sonarsource.com/browse/SONARJS-729).