Socket
Socket
Sign inDemoInstall

eslint-plugin-react

Package Overview
Dependencies
Maintainers
1
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 3.7.1 to 3.8.0

16

CHANGELOG.md

@@ -6,2 +6,18 @@ # Change Log

## [3.8.0] - 2015-11-07
### Added
* Add ignoreStateless option to `no-multi-comp` ([#290][])
### Fixed
* Fix classes with properties to always be marked as components ([#291][])
* Fix ES5 class detection when using `createClass` by itself ([#297][])
* Fix direct props detection ([#298][])
* Ignore functions containing the keyword `this` during component detection
[3.8.0]: https://github.com/yannickcr/eslint-plugin-react/compare/v3.7.1...v3.8.0
[#290]: https://github.com/yannickcr/eslint-plugin-react/issues/290
[#291]: https://github.com/yannickcr/eslint-plugin-react/issues/291
[#297]: https://github.com/yannickcr/eslint-plugin-react/issues/297
[#298]: https://github.com/yannickcr/eslint-plugin-react/issues/298
## [3.7.1] - 2015-11-05

@@ -8,0 +24,0 @@ ### Fixed

25

lib/rules/no-multi-comp.js

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

var configuration = context.options[0] || {};
var ignoreStateless = configuration.ignoreStateless || false;
var MULTI_COMP_MESSAGE = 'Declare only one React component per file';
/**
* Checks if the component is ignored
* @param {Object} component The component being checked.
* @returns {Boolean} True if the component is ignored, false if not.
*/
function isIgnored(component) {
return ignoreStateless === true && /Function/.test(component.node.type);
}
// --------------------------------------------------------------------------

@@ -32,3 +44,3 @@ // Public

for (var component in list) {
if (!list.hasOwnProperty(component) || ++i === 1) {
if (!list.hasOwnProperty(component) || isIgnored(list[component]) || ++i === 1) {
continue;

@@ -42,2 +54,11 @@ }

module.exports.schema = [];
module.exports.schema = [{
type: 'object',
properties: {
ignoreStateless: {
default: false,
type: 'boolean'
}
},
additionalProperties: false
}];

4

lib/rules/prop-types.js

@@ -330,3 +330,3 @@ /**

function getPropertyName(node) {
var isDirectProp = /^props\./.test(context.getSource(node));
var isDirectProp = /^props(\.|\[)/.test(context.getSource(node));
var isInClassComponent = context.react.getParentES6Component() || context.react.getParentES5Component();

@@ -422,3 +422,3 @@ var isNotInConstructor = !inConstructor(node);

var isDirectProp = /^props\./.test(context.getSource(node));
var isDirectProp = /^props(\.|\[)/.test(context.getSource(node));

@@ -425,0 +425,0 @@ usedPropTypes.push({

@@ -24,12 +24,18 @@ /**

* @param {ASTNode} node The AST node being added.
* @param {Object} props Additional properties to add to the component.
* @param {Number} confidence Confidence in the component detection (0=banned, 1=maybe, 2=yes)
*/
Components.prototype.add = function(node, props) {
Components.prototype.add = function(node, confidence) {
var id = this._getId(node);
if (this._list[id]) {
this._list[id] = util._extend(this._list[id], props);
if (confidence === 0 || this._list[id].confidence === 0) {
this._list[id].confidence = 0;
} else {
this._list[id].confidence = Math.max(this._list[id].confidence, confidence);
}
return;
}
props.node = node;
this._list[id] = props;
this._list[id] = {
node: node,
confidence: confidence
};
};

@@ -74,3 +80,3 @@

for (var i in this._list) {
if (!this._list.hasOwnProperty(i) || !this._list[i].confident) {
if (!this._list.hasOwnProperty(i) || this._list[i].confidence < 2) {
continue;

@@ -92,3 +98,3 @@ }

for (var i in this._list) {
if (!this._list.hasOwnProperty(i) || !this._list[i].confident) {
if (!this._list.hasOwnProperty(i) || this._list[i].confidence < 2) {
continue;

@@ -116,3 +122,6 @@ }

isES5Component: function(node) {
return node.parent && sourceCode.getText(node.parent.callee) === 'React.createClass';
if (!node.parent) {
return false;
}
return /^(React\.)?createClass$/.test(sourceCode.getText(node.parent.callee));
},

@@ -207,3 +216,3 @@

var node = scope && scope.block;
if (!node || !node.superClass) {
if (!node || !context.react.isES6Component(node)) {
return null;

@@ -317,3 +326,3 @@ }

}
components.add(node, {confident: true});
components.add(node, 2);
},

@@ -326,3 +335,3 @@

}
components.add(node, {confident: true});
components.add(node, 2);
},

@@ -334,3 +343,3 @@

}
components.add(node, {confident: true});
components.add(node, 2);
},

@@ -343,4 +352,3 @@

}
var component = components.get(node);
components.add(node, {confident: component && component.confident || false});
components.add(node, 1);
},

@@ -353,4 +361,3 @@

}
var component = components.get(node);
components.add(node, {confident: component && component.confident || false});
components.add(node, 1);
},

@@ -364,9 +371,17 @@

if (node.expression && context.react.isReturningJSX(node)) {
components.add(node, {confident: true});
components.add(node, 2);
} else {
var component = components.get(node);
components.add(node, {confident: component && component.confident || false});
components.add(node, 1);
}
},
ThisExpression: function(node) {
node = context.react.getParentComponent();
if (!node || !/Function/.test(node.type)) {
return;
}
// Ban functions with a ThisExpression
components.add(node, 0);
},
ReturnStatement: function(node) {

@@ -380,3 +395,3 @@ if (!context.react.isReturningJSX(node)) {

}
components.add(node, {confident: true});
components.add(node, 2);
}

@@ -383,0 +398,0 @@ };

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

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

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