Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zohodesk/eslint-plugin-react-performance

Package Overview
Dependencies
Maintainers
11
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zohodesk/eslint-plugin-react-performance - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

99

lib/rules/no-ref-mapstatetoprops.js

@@ -11,2 +11,15 @@ /**

function isInReturn(node) {
let n = node;
while (n && n.type !== 'ReturnStatement') {
n = n.parent;
}
if (n && n.type === 'ReturnStatement') {
return true;
} else {
return false;
}
}
module.exports = {

@@ -36,4 +49,22 @@ meta: {

function foundInitialization(node) {
// Switching the process as inside return and outside return.
if (!isInReturn(node)) {
return;
}
// For All return statement's Objects.
if (node.parent.type === 'ReturnStatement') return;
// connect(state => ({}))
if (
node.parent.type === 'ArrowFunctionExpression' &&
node.parent.parent &&
node.parent.parent.callee &&
node.parent.parent.callee.name === 'connect'
) {
return;
}
// const mapStateToProps = state => ({name: 1})
if (
node.type === 'ObjectExpression' &&

@@ -48,2 +79,4 @@ node.parent.type === 'ArrowFunctionExpression' &&

}
// If return objects function call has any array or object
if (node.parent.type === 'CallExpression') {

@@ -53,2 +86,3 @@ return;

// const { name = {} } = state || {}
if (

@@ -62,2 +96,4 @@ node.parent.type === 'LogicalExpression' &&

}
// const { name = {} } = state ? state: {}
if (

@@ -71,10 +107,2 @@ node.parent.type === 'ConditionalExpression' &&

}
if (
node.parent.type === 'ArrowFunctionExpression' &&
node.parent.parent &&
node.parent.parent.callee &&
node.parent.parent.callee.name === 'connect'
) {
return;
}

@@ -87,2 +115,49 @@ context.report({

}
const arrRefs = [
'concat',
'from',
'of',
'filter',
'flat',
'flatMap',
'keys',
'map',
'slice',
'values'
];
const objRefs = ['assign', 'create'];
function mstpFunction(node) {
if (!isInReturn(node)) {
return;
}
if (node.callee.property && arrRefs.includes(node.callee.property.name)) {
console.log('----', node.callee.property.name);
context.report({
node,
message:
'Creates new Array reference. Hence causes performance issues.'
});
}
if (node.callee.object && node.callee.object.name === 'Object') {
if (
node.callee.property &&
objRefs.includes(node.callee.property.name)
) {
context.report({
node,
message:
'Creates new Object reference. Hence causes performance issues.'
});
}
console.log(node.callee.object);
}
}
// add a function that takes a list of files it obtains mapStateToProps and count.

@@ -98,5 +173,11 @@

[`${connectCallQuery} ArrowFunctionExpression ${vulnerableQuery}`]: foundInitialization,
[`${connectCallQuery} FunctionExpression ${vulnerableQuery}`]: foundInitialization
[`${connectCallQuery} FunctionExpression ${vulnerableQuery}`]: foundInitialization,
// functions check
[`FunctionDeclaration${idNameQuery} CallExpression`]: mstpFunction,
[`VariableDeclarator${idNameQuery} ArrowFunctionExpression CallExpression`]: mstpFunction,
[`${connectCallQuery} ArrowFunctionExpression CallExpression`]: mstpFunction,
[`${connectCallQuery} FunctionExpression CallExpression`]: mstpFunction
};
}
};

4

package.json
{
"name": "@zohodesk/eslint-plugin-react-performance",
"version": "1.0.1",
"version": "1.0.2",
"description": "To improve performance in react redux applications",

@@ -27,2 +27,2 @@ "keywords": [

"license": "ISC"
}
}
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