eslint-plugin-sonarjs
Advanced tools
Comparing version 0.4.0 to 0.5.0-internal
@@ -31,3 +31,3 @@ "use strict"; | ||
// internal parameter | ||
enum: ["sonar-runtime"], | ||
enum: ["sonar-runtime", "metric"], | ||
}, | ||
@@ -38,2 +38,5 @@ ], | ||
var threshold = context.options[0] !== undefined ? context.options[0] : DEFAULT_THRESHOLD; | ||
var isFileComplexity = context.options.includes("metric"); | ||
/** Complexity of the file */ | ||
var fileComplexity = 0; | ||
/** Complexity of the current function if it is *not* considered nested to the first level function */ | ||
@@ -74,2 +77,12 @@ var complexityIfNotNested = []; | ||
}, | ||
Program: function () { | ||
fileComplexity = 0; | ||
}, | ||
"Program:exit": function (node) { | ||
if (isFileComplexity) { | ||
// as issues are the only communication channel of a rule | ||
// we pass data as serialized json as an issue message | ||
context.report({ node: node, message: fileComplexity.toString() }); | ||
} | ||
}, | ||
IfStatement: function (node) { | ||
@@ -234,3 +247,7 @@ visitIfStatement(node); | ||
var complexityPoint = { complexity: added, location: location }; | ||
if (enclosingFunctions.length === 1) { | ||
if (enclosingFunctions.length === 0) { | ||
// top level scope | ||
fileComplexity += added; | ||
} | ||
else if (enclosingFunctions.length === 1) { | ||
// top level function | ||
@@ -248,3 +265,7 @@ topLevelHasStructuralComplexity = true; | ||
var complexityPoint = { complexity: 1, location: location }; | ||
if (enclosingFunctions.length === 1) { | ||
if (enclosingFunctions.length === 0) { | ||
// top level scope | ||
fileComplexity += 1; | ||
} | ||
else if (enclosingFunctions.length === 1) { | ||
// top level function | ||
@@ -262,2 +283,6 @@ topLevelOwnComplexity.push(complexityPoint); | ||
var complexityAmount = complexity.reduce(function (acc, cur) { return acc + cur.complexity; }, 0); | ||
fileComplexity += complexityAmount; | ||
if (isFileComplexity) { | ||
return; | ||
} | ||
if (complexityAmount > threshold) { | ||
@@ -264,0 +289,0 @@ var secondaryLocations = complexity.map(function (complexityPoint) { |
{ | ||
"name": "eslint-plugin-sonarjs", | ||
"version": "0.4.0", | ||
"version": "0.5.0-internal", | ||
"description": "SonarJS rules for ESLint", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
176707
2333