eslint-plugin-react
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -0,1 +1,12 @@ | ||
2.0.2 / 2015-03-31 | ||
================== | ||
* fix ignore rest spread when destructuring props ([#46][]) | ||
* fix component detection in prop-types and display-name ([#45][]) | ||
* fix spread handling in jsx-sort-props ([#42][] @zertosh) | ||
[#46]: https://github.com/yannickcr/eslint-plugin-react/issues/46 | ||
[#45]: https://github.com/yannickcr/eslint-plugin-react/issues/45 | ||
[#42]: https://github.com/yannickcr/eslint-plugin-react/pull/42 | ||
2.0.1 / 2015-03-30 | ||
@@ -2,0 +13,0 @@ ================== |
@@ -22,2 +22,15 @@ /** | ||
/** | ||
* Checks if the component must be validated | ||
* @param {Object} component The component to process | ||
* @returns {Boolean} True if the component must be validated, false if not. | ||
*/ | ||
function mustBeValidated(component) { | ||
return ( | ||
component && | ||
component.isReactComponent && | ||
!component.hasDisplayName | ||
); | ||
} | ||
/** | ||
* Checks if we are declaring a display name | ||
@@ -49,5 +62,2 @@ * @param {ASTNode} node The AST node being checked. | ||
function reportMissingDisplayName(component) { | ||
if (!component || component.hasDisplayName === true) { | ||
return; | ||
} | ||
context.report( | ||
@@ -92,3 +102,3 @@ component.node, | ||
for (var component in list) { | ||
if (!list.hasOwnProperty(component)) { | ||
if (!list.hasOwnProperty(component) || !mustBeValidated(list[component])) { | ||
continue; | ||
@@ -104,3 +114,5 @@ } | ||
} | ||
componentList.set(context, node); | ||
componentList.set(context, node, { | ||
isReactComponent: true | ||
}); | ||
} | ||
@@ -107,0 +119,0 @@ }; |
@@ -18,3 +18,7 @@ /** | ||
JSXOpeningElement: function(node) { | ||
node.attributes.reduce(function(memo, decl) { | ||
var attributes = node.attributes.filter(function(decl) { | ||
return decl.type === 'JSXAttribute'; | ||
}); | ||
attributes.reduce(function(memo, decl) { | ||
var lastPropName = memo.name.name; | ||
@@ -34,5 +38,5 @@ var currenPropName = decl.name.name; | ||
return decl; | ||
}, node.attributes[0]); | ||
}, attributes[0]); | ||
} | ||
}; | ||
}; |
@@ -58,2 +58,16 @@ /** | ||
/** | ||
* Checks if the component must be validated | ||
* @param {Object} component The component to process | ||
* @returns {Boolean} True if the component must be validated, false if not. | ||
*/ | ||
function mustBeValidated(component) { | ||
return ( | ||
component && | ||
component.isReactComponent && | ||
component.usedPropTypes && | ||
!component.ignorePropsValidation | ||
); | ||
} | ||
/** | ||
* Checks if the prop is declared | ||
@@ -72,2 +86,13 @@ * @param {String} name Name of the prop to check. | ||
/** | ||
* Checks if the prop is declared | ||
* @param {String} name Name of the prop to check. | ||
* @param {Object} component The component to process | ||
* @returns {Boolean} True if the prop is declared, false if not. | ||
*/ | ||
function hasSpreadOperator(node) { | ||
var tokens = context.getTokens(node); | ||
return tokens.length && tokens[0].value === '...'; | ||
} | ||
/** | ||
* Mark a prop type as used | ||
@@ -98,5 +123,9 @@ * @param {ASTNode} node The AST node being marked. | ||
case 'destructuring': | ||
for (var i = 0, j = node.parent.parent.declarations[0].id.properties.length; i < j; i++) { | ||
var properties = node.parent.parent.declarations[0].id.properties; | ||
for (var i = 0, j = properties.length; i < j; i++) { | ||
if (hasSpreadOperator(properties[i])) { | ||
continue; | ||
} | ||
usedPropTypes.push({ | ||
name: node.parent.parent.declarations[0].id.properties[i].key.name, | ||
name: properties[i].key.name, | ||
node: node | ||
@@ -151,5 +180,2 @@ }); | ||
function reportUndeclaredPropTypes(component) { | ||
if (!component || !component.usedPropTypes || component.ignorePropsValidation === true) { | ||
return; | ||
} | ||
var name; | ||
@@ -215,3 +241,3 @@ for (var i = 0, j = component.usedPropTypes.length; i < j; i++) { | ||
for (var component in list) { | ||
if (!list.hasOwnProperty(component)) { | ||
if (!list.hasOwnProperty(component) || !mustBeValidated(list[component])) { | ||
continue; | ||
@@ -227,3 +253,5 @@ } | ||
} | ||
componentList.set(context, node); | ||
componentList.set(context, node, { | ||
isReactComponent: true | ||
}); | ||
} | ||
@@ -230,0 +258,0 @@ }; |
{ | ||
"name": "eslint-plugin-react", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"author": "Yannick Croissant <yannick.croissant+npm@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "React specific linting rules for ESLint", |
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
45102
1033