Oleg Savickij Oleg Savickij - 1 year ago 76
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download