New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-sonarjs

Package Overview
Dependencies
Maintainers
6
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-sonarjs - npm Package Compare versions

Comparing version 0.7.1-117 to 0.8.0-125

38

lib/rules/cognitive-complexity.js

@@ -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)) {

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc