Socket
Socket
Sign inDemoInstall

eslint-plugin-react

Package Overview
Dependencies
Maintainers
2
Versions
210
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-react - npm Package Compare versions

Comparing version 7.20.2 to 7.20.3

50

lib/util/propTypes.js

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

const getKeyValue = require('./ast').getKeyValue;
const findReturnStatement = require('./ast').findReturnStatement;
const isJSX = require('./jsx').isJSX;

@@ -71,3 +73,21 @@ /**

}
return false;
}
/**
* Checks if a node is a Function and return JSXElement
*
* @param {ASTNode} node the AST node being checked.
* @returns {Boolean} True if the node is a Function and return JSXElement.
*/
function isJSXFunctionComponent(node) {
if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
const res = findReturnStatement(node);
// If function return JSXElement with return keyword.
if (res) {
return isJSX(res.argument);
}
// If function return JSXElement without return keyword;
return isJSX(node.body);
}
return false;

@@ -220,3 +240,2 @@ }

}
return annotation;

@@ -319,9 +338,19 @@ }

foundDeclaredPropertiesList.forEach((tsPropertySignature) => {
declaredPropTypes[tsPropertySignature.key.name] = {
fullName: tsPropertySignature.key.name,
name: tsPropertySignature.key.name,
node: tsPropertySignature,
isRequired: !tsPropertySignature.optional
};
foundDeclaredPropertiesList.forEach((tsInterfaceBody) => {
if (tsInterfaceBody.type === 'TSPropertySignature') {
let accessor = 'name';
if (tsInterfaceBody.key.type === 'Literal') {
if (typeof tsInterfaceBody.key.value === 'number') {
accessor = 'raw';
} else {
accessor = 'value';
}
}
declaredPropTypes[tsInterfaceBody.key[accessor]] = {
fullName: tsInterfaceBody.key[accessor],
name: tsInterfaceBody.key[accessor],
node: tsInterfaceBody,
isRequired: !tsInterfaceBody.optional
};
}
});

@@ -626,2 +655,7 @@ return false;

// Should ignore function that not return JSXElement
if (!isJSXFunctionComponent(node)) {
return;
}
const param = node.params[0];

@@ -628,0 +662,0 @@ if (param.typeAnnotation && param.typeAnnotation.typeAnnotation && param.typeAnnotation.typeAnnotation.type === 'UnionTypeAnnotation') {

73

lib/util/usedPropTypes.js

@@ -212,33 +212,2 @@ /**

/**
* Retrieve the name of a property node
* @param {ASTNode} node The AST node with the property.
* @return {string|undefined} the name of the property or undefined if not found
*/
function getPropertyName(node) {
const property = node.property;
if (property) {
switch (property.type) {
case 'Identifier':
if (node.computed) {
return '__COMPUTED_PROP__';
}
return property.name;
case 'MemberExpression':
return;
case 'Literal':
// Accept computed properties that are literal strings
if (typeof property.value === 'string') {
return property.value;
}
// falls through
default:
if (node.computed) {
return '__COMPUTED_PROP__';
}
break;
}
}
}
/**
* Checks if the node is a propTypes usage of the form `this.props.*`, `props.*`, `prevProps.*`, or `nextProps.*`.

@@ -276,2 +245,42 @@ * @param {ASTNode} node

/**
* Retrieve the name of a property node
* @param {ASTNode} node The AST node with the property.
* @param {Context} context
* @param {Object} utils
* @param {boolean} checkAsyncSafeLifeCycles
* @return {string|undefined} the name of the property or undefined if not found
*/
function getPropertyName(node, context, utils, checkAsyncSafeLifeCycles) {
const property = node.property;
if (property) {
switch (property.type) {
case 'Identifier':
if (node.computed) {
return '__COMPUTED_PROP__';
}
return property.name;
case 'MemberExpression':
return;
case 'Literal':
// Accept computed properties that are literal strings
if (typeof property.value === 'string') {
return property.value;
}
// Accept number as well but only accept props[123]
if (typeof property.value === 'number') {
if (isPropTypesUsageByMemberExpression(node, context, utils, checkAsyncSafeLifeCycles)) {
return property.raw;
}
}
// falls through
default:
if (node.computed) {
return '__COMPUTED_PROP__';
}
break;
}
}
}
module.exports = function usedPropTypesInstructions(context, components, utils) {

@@ -298,3 +307,3 @@ const checkAsyncSafeLifeCycles = versionUtil.testReactVersion(context, '16.3.0');

case 'MemberExpression':
name = getPropertyName(node);
name = getPropertyName(node, context, utils, checkAsyncSafeLifeCycles);
if (name) {

@@ -301,0 +310,0 @@ allNames = parentNames.concat(name);

{
"name": "eslint-plugin-react",
"version": "7.20.2",
"version": "7.20.3",
"author": "Yannick Croissant <yannick.croissant+npm@gmail.com>",

@@ -5,0 +5,0 @@ "description": "React specific linting rules for ESLint",

Sorry, the diff of this file is too big to display

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