Socket
Socket
Sign inDemoInstall

eslint-plugin-jsx-expressions

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jsx-expressions - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

42

dist/rules/strict-logical-expressions.js

@@ -64,7 +64,3 @@ "use strict";

if (!options.allowString && hasPotentiallyFalseyString) {
context.report({
node,
messageId: "conditionErrorFalseyString",
fix: (fixer) => fixer.insertTextBefore(node, "!!"),
});
return "conditionErrorFalseyString";
}

@@ -74,6 +70,13 @@ const hasPotentiallyFalseyNumber = types.some((type) => tsutils.isTypeFlagSet(type, ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike) &&

if (!options.allowNumber && hasPotentiallyFalseyNumber) {
return "conditionErrorFalseyNumber";
}
return;
}
function checkAndReportIdentifier(node, fixNode) {
const errorId = checkIdentifier(node);
if (errorId) {
context.report({
node,
messageId: "conditionErrorFalseyNumber",
fix: (fixer) => fixer.insertTextBefore(node, "!!"),
messageId: errorId,
fix: (fixer) => fixer.insertTextBefore(fixNode, "!!"),
});

@@ -83,12 +86,23 @@ }

function checkLogicalExpression(expressionNode, checkRightNode) {
if (expressionNode.left.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.LogicalExpression) {
checkLogicalExpression(expressionNode.left, true);
let leftNode = expressionNode.left;
if (leftNode.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.MemberExpression &&
leftNode.property.type !== experimental_utils_1.TSESTree.AST_NODE_TYPES.PrivateIdentifier) {
leftNode = leftNode.property;
}
else if (expressionNode.left.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.Identifier) {
checkIdentifier(expressionNode.left);
if (leftNode.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.LogicalExpression) {
checkLogicalExpression(leftNode, true);
}
if (checkRightNode &&
expressionNode.right.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.Identifier) {
checkIdentifier(expressionNode.right);
else if (leftNode.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.Identifier) {
checkAndReportIdentifier(leftNode, expressionNode.left);
}
if (checkRightNode) {
let rightNode = expressionNode.right;
if (rightNode.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.MemberExpression &&
rightNode.property.type !== experimental_utils_1.TSESTree.AST_NODE_TYPES.PrivateIdentifier) {
rightNode = rightNode.property;
}
if (rightNode.type === experimental_utils_1.TSESTree.AST_NODE_TYPES.Identifier) {
checkAndReportIdentifier(rightNode, expressionNode.right);
}
}
}

@@ -95,0 +109,0 @@ function checkJSXExpression(node) {

{
"name": "eslint-plugin-jsx-expressions",
"version": "1.2.0",
"version": "1.3.0",
"description": "Rules for safe logical expressions in JSX",

@@ -15,3 +15,3 @@ "keywords": [

"url": "https://github.com/hpersson/eslint-plugin-jsx-expressions.git"
},
},
"scripts": {

@@ -28,3 +28,3 @@ "build": "tsc -b tsconfig.build.json",

"dependencies": {
"@typescript-eslint/experimental-utils": "^5.0.0",
"@typescript-eslint/experimental-utils": "^5.5.0",
"tsutils": "^3.21.0"

@@ -36,8 +36,8 @@ },

"@types/requireindex": "^1.2.0",
"@typescript-eslint/parser": "^4.0.0",
"eslint": "^7.1.0",
"eslint-plugin-eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^5.5.0",
"eslint": "^8.3.0",
"eslint-plugin-eslint-plugin": "^4.0.2",
"jest": "^27.2.5",
"ts-jest": "^27.0.7",
"typescript": "^4.4.4"
"typescript": "^4.5.2"
},

@@ -48,4 +48,4 @@ "engines": {

"peerDependencies": {
"@typescript-eslint/parser": "^4.0.0",
"eslint": "^5.0.0 || ^6.0.0 || ^7.0.0"
"@typescript-eslint/parser": "^4.0.0 || ^5.0.0",
"eslint": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
},

@@ -52,0 +52,0 @@ "peerDependenciesMeta": {

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