eslint-plugin-jsx-expressions
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15756
153
+ Added@eslint-community/regexpp@4.11.1(transitive)
+ Added@eslint/eslintrc@2.1.4(transitive)
+ Added@eslint/js@8.57.1(transitive)
+ Added@humanwhocodes/config-array@0.13.0(transitive)
+ Added@humanwhocodes/module-importer@1.0.1(transitive)
+ Added@humanwhocodes/object-schema@2.0.3(transitive)
+ Added@typescript-eslint/parser@5.62.0(transitive)
+ Added@ungap/structured-clone@1.2.0(transitive)
+ Addedacorn@8.13.0(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedeslint@8.57.1(transitive)
+ Addedeslint-scope@7.2.2(transitive)
+ Addedespree@9.6.1(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedglob-parent@6.0.2(transitive)
+ Addedgraphemer@1.4.0(transitive)
+ Addedis-path-inside@3.0.3(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removed@babel/code-frame@7.12.11(transitive)
- Removed@babel/helper-validator-identifier@7.25.7(transitive)
- Removed@babel/highlight@7.25.7(transitive)
- Removed@eslint/eslintrc@0.4.3(transitive)
- Removed@humanwhocodes/config-array@0.5.0(transitive)
- Removed@humanwhocodes/object-schema@1.2.1(transitive)
- Removed@typescript-eslint/parser@4.33.0(transitive)
- Removed@typescript-eslint/scope-manager@4.33.0(transitive)
- Removed@typescript-eslint/types@4.33.0(transitive)
- Removed@typescript-eslint/typescript-estree@4.33.0(transitive)
- Removed@typescript-eslint/visitor-keys@4.33.0(transitive)
- Removedacorn@7.4.1(transitive)
- Removedajv@8.17.1(transitive)
- Removedansi-colors@4.1.3(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedargparse@1.0.10(transitive)
- Removedastral-regex@2.0.0(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedenquirer@2.4.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedeslint@7.32.0(transitive)
- Removedeslint-utils@2.1.0(transitive)
- Removedeslint-visitor-keys@1.3.02.1.0(transitive)
- Removedespree@7.3.1(transitive)
- Removedesprima@4.0.1(transitive)
- Removedfast-uri@3.0.3(transitive)
- Removedfunctional-red-black-tree@1.0.1(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedignore@4.0.6(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedjson-schema-traverse@1.0.0(transitive)
- Removedlodash.truncate@4.4.2(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedprogress@2.0.3(transitive)
- Removedregexpp@3.2.0(transitive)
- Removedrequire-from-string@2.0.2(transitive)
- Removedslice-ansi@4.0.0(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedtable@6.8.2(transitive)
- Removedv8-compile-cache@2.4.0(transitive)