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.2.0 to 1.0.0

lib/rules/jsx-for-require-each.js

10

CHANGELOG.md

@@ -12,2 +12,12 @@ # Changelog

## v1.0.0
### Added
- Rule `jsx-for-require-each`.
- Rule `jsx-for-require-index`.
- Rule `jsx-for-require-of`.
### Changed
- Renamed `jsx-if-condition` to `jsx-if-require-condition`.
## 0.2.0

@@ -14,0 +24,0 @@

9

index.js

@@ -5,7 +5,10 @@ "use strict";

rules: {
"jsx-if-condition": require("./lib/rules/jsx-if-condition"),
"jsx-for-require-each": require("./lib/rules/jsx-for-require-each"),
"jsx-for-require-index": require("./lib/rules/jsx-for-require-index"),
"jsx-for-require-of": require("./lib/rules/jsx-for-require-of"),
"jsx-for-single-child": require("./lib/rules/jsx-for-single-child"),
"jsx-if-require-condition": require("./lib/rules/jsx-if-require-condition"),
"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")
"jsx-use-if-tag": require("./lib/rules/jsx-use-if-tag")
}
};

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

var utils = require("../utils");
var utils = require("../utils"),
_ = require("lodash");

@@ -20,8 +21,11 @@ //------------------------------------------------------------------------------

function isElseComponent(node) {
var n = node.openingElement || node;
return n.name && n.name.type === "JSXIdentifier" && n.name.name === "Else" && n.selfClosing;
function isElseComponent(child) {
return child.type === 'JSXElement' && child.openingElement.name.name === 'Else';
}
function isNotElseComponent(child) {
return !isElseComponent(child);
}
function hasElseCondition(node) {

@@ -35,10 +39,2 @@ var children = node.parent.children;

function hasSingleChildrenBetween(node) {
var children = utils.filterChildren(node.parent.children);
return children.length
&& children.length === 3
&& isElseComponent(children[1]);
}
//--------------------------------------------------------------------------

@@ -52,8 +48,14 @@ // Public

var children = utils.filterChildren(node.parent.children),
ifBlock = _.takeWhile(children, isNotElseComponent),
elseBlock = _.takeRightWhile(children, isNotElseComponent);
if (!hasElseCondition(node) && !utils.hasSingleChild(node)) {
if (ifBlock.length !== 1) {
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'.");
}
if (hasElseCondition(node) && elseBlock.length !== 1) {
context.report(node, "There must be single child between 'Else' and ending 'If'.");
}
}

@@ -60,0 +62,0 @@ };

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

@@ -14,4 +14,3 @@ "description": "jsx-control-statements specific linting rules for ESLint",

"files": [
"LICENSE",
"README.md",
"*.md",
"index.js",

@@ -41,3 +40,6 @@ "lib"

],
"license": "MIT"
"license": "MIT",
"dependencies": {
"lodash": "^3.10.1"
}
}

@@ -51,6 +51,9 @@ # ESLint-plugin-JSX-control-statements

"rules": {
"jsx-control-statements/jsx-if-condition": 1,
"jsx-control-statements/jsx-for-require-each": 1,
"jsx-control-statements/jsx-for-require-index": 1,
"jsx-control-statements/jsx-for-require-of": 1,
"jsx-control-statements/jsx-for-single-child": 1,
"jsx-control-statements/jsx-if-require-condition": 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
"jsx-control-statements/jsx-use-if-tag": 1
}

@@ -62,6 +65,9 @@ }

* [jsx-if-condition](docs/rules/jsx-if-condition.md): Warn if `If` tag is missing `condition` attribute.
* [jsx-for-require-each](docs/rules/jsx-for-require-each.md): Warn if `For` tag is missing `each` attribute. And also marks the variable as defined.
* [jsx-for-require-index](docs/rules/jsx-for-require-index.md): Warn if `For` tag is missing `index` attribute. And also marks the variable as defined.
* [jsx-for-require-of](docs/rules/jsx-for-require-of.md): Warn if `For` tag is missing `of` attribute.
* [jsx-for-single-child](docs/rules/jsx-for-single-child.md): Warn if `For` tags does not have single child.
* [jsx-if-require-condition](docs/rules/jsx-if-require-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 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.

@@ -68,0 +74,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