eslint-plugin-sonarjs
Advanced tools
Comparing version 0.7.1-117 to 0.8.0-125
@@ -49,2 +49,14 @@ "use strict"; | ||
let topLevelHasStructuralComplexity = false; | ||
/** Indicator if the current top level function is React functional component */ | ||
const reactFunctionalComponent = { | ||
nameStartsWithCapital: false, | ||
returnsJsx: false, | ||
isConfirmed() { | ||
return this.nameStartsWithCapital && this.returnsJsx; | ||
}, | ||
init(_node) { | ||
this.nameStartsWithCapital = nameStartsWithCapital(_node); | ||
this.returnsJsx = false; | ||
}, | ||
}; | ||
/** Own (not including nested functions) complexity of the current top function */ | ||
@@ -123,2 +135,5 @@ let topLevelOwnComplexity = []; | ||
}, | ||
ReturnStatement(node) { | ||
visitReturnStatement(node); | ||
}, | ||
}; | ||
@@ -132,2 +147,3 @@ function getThreshold() { | ||
topLevelHasStructuralComplexity = false; | ||
reactFunctionalComponent.init(node); | ||
topLevelOwnComplexity = []; | ||
@@ -151,3 +167,3 @@ secondLevelFunctions = []; | ||
// top level function | ||
if (topLevelHasStructuralComplexity) { | ||
if (topLevelHasStructuralComplexity && !reactFunctionalComponent.isConfirmed()) { | ||
let totalComplexity = topLevelOwnComplexity; | ||
@@ -227,2 +243,22 @@ secondLevelFunctions.forEach(secondLevelFunction => { | ||
} | ||
function visitReturnStatement({ argument }) { | ||
// top level function | ||
if (enclosingFunctions.length === 1 && argument && argument.type === "JSXElement") { | ||
reactFunctionalComponent.returnsJsx = true; | ||
} | ||
} | ||
function nameStartsWithCapital(node) { | ||
const checkFirstLetter = (name) => { | ||
const firstLetter = name[0]; | ||
return firstLetter === firstLetter.toUpperCase(); | ||
}; | ||
if (!nodes_1.isArrowFunctionExpression(node) && node.id) { | ||
return checkFirstLetter(node.id.name); | ||
} | ||
const parent = nodes_1.getParent(context); | ||
if (parent && parent.type === "VariableDeclarator" && parent.id.type === "Identifier") { | ||
return checkFirstLetter(parent.id.name); | ||
} | ||
return false; | ||
} | ||
function visitLogicalExpression(logicalExpression) { | ||
@@ -229,0 +265,0 @@ if (!consideredLogicalExpressions.has(logicalExpression)) { |
{ | ||
"name": "eslint-plugin-sonarjs", | ||
"version": "0.7.1-117", | ||
"version": "0.8.0-125", | ||
"description": "SonarJS rules for ESLint", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
211135
2875
0