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

eslint-plugin-jsx-control-statements

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jsx-control-statements - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

CHANGELOG.md

4

index.js

@@ -6,4 +6,6 @@ "use strict";

"jsx-if-condition": require("./lib/rules/jsx-if-condition"),
"jsx-if-single-child": require("./lib/rules/jsx-if-single-child")
"jsx-if-single-child": require("./lib/rules/jsx-if-single-child"),
"jsx-use-if-tag": require("./lib/rules/jsx-use-if-tag"),
"jsx-for-single-child": require("./lib/rules/jsx-for-single-child")
}
};

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

var utils = require("../utils");
//------------------------------------------------------------------------------

@@ -15,3 +17,3 @@ // Rule Definition

function isIfComponent(node) {
return node.name && node.name.type === "JSXIdentifier" && node.name.name === "If";
return utils.isTag("If", node);
}

@@ -38,3 +40,3 @@

context.report(node, "If tag must have a condition attribute.");
context.report(node, "'If' tag must have a 'condition' attribute.");
}

@@ -41,0 +43,0 @@ };

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

var utils = require("../utils");
//------------------------------------------------------------------------------

@@ -15,3 +17,3 @@ // Rule Definition

function isIfComponent(node) {
return node.name && node.name.type === "JSXIdentifier" && node.name.name === "If";
return utils.isTag("If", node);
}

@@ -25,17 +27,2 @@

function filterChildren(children) {
return children.filter(function(c) {
if (c.type === "JSXElement") return true;
if (c.type === "Literal") return c.value.trim() !== "";
return false;
});
}
function hasSingleChild(node) {
var children = filterChildren(node.parent.children);
return children.length && children.length === 1;
}
function hasElseCondition(node) {

@@ -50,3 +37,3 @@ var children = node.parent.children;

function hasSingleChildrenBetween(node) {
var children = filterChildren(node.parent.children);
var children = utils.filterChildren(node.parent.children);

@@ -67,6 +54,6 @@ return children.length

if (!hasElseCondition(node) && !hasSingleChild(node)) {
context.report(node, "If tag must have single child.");
if (!hasElseCondition(node) && !utils.hasSingleChild(node)) {
context.report(node, "'If' tag must have single child.");
} else if (hasElseCondition(node) && !hasSingleChildrenBetween(node)) {
context.report(node, "There must be single child between If and Else.");
context.report(node, "There must be single child between 'If' and 'Else'.");
}

@@ -73,0 +60,0 @@ }

{
"name": "eslint-plugin-jsx-control-statements",
"version": "0.1.1",
"version": "0.2.0",
"author": "Vivek Kumar Bansal <vkb0310@gmail.com>",

@@ -5,0 +5,0 @@ "description": "jsx-control-statements specific linting rules for ESLint",

@@ -22,2 +22,3 @@ # ESLint-plugin-JSX-control-statements

Add `plugins` section and specify ESLint-plugin-JSX-Control-Statements as a plugin.
Also add `If` and `For` to globals.

@@ -28,3 +29,7 @@ ```json

"jsx-control-statements"
]
],
"globals": {
"If": true,
"For": true
}
}

@@ -49,3 +54,5 @@ ```

"jsx-control-statements/jsx-if-condition": 1,
"jsx-control-statements/jsx-if-single-child": 1
"jsx-control-statements/jsx-if-single-child": 1,
"jsx-control-statements/jsx-use-if-tag": 1,
"jsx-control-statements/jsx-for-single-child": 1
}

@@ -58,3 +65,5 @@ }

* [jsx-if-condition](docs/rules/jsx-if-condition.md): Warn if `If` tag is missing `condition` attribute.
* [jsx-if-single-child](docs/rules/jsx-if-single-child.md): Warn if `If` and `Else` tags must have single children.
* [jsx-if-single-child](docs/rules/jsx-if-single-child.md): Warn if `If` and `Else` tags does not have single child.
* [jsx-use-if-tag](docs/rules/jsx-use-if-tag.md): Use `If` tag instead of ternary operator.
* [jsx-for-single-child](docs/rules/jsx-for-single-child.md): Warn if `For` tags does not have single child.

@@ -61,0 +70,0 @@ ## Credits

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