eslint-plugin-react
Advanced tools
Comparing version 3.12.0 to 3.13.0
@@ -6,2 +6,24 @@ # Change Log | ||
## [3.13.0] - 2015-12-24 | ||
### Added | ||
* Add `no-string-refs` rule ([#341][] @Intellicode) | ||
* Add support for propTypes assigned via a variable in `prop-types` ([#355][]) | ||
### Fixed | ||
* Fix `never` option in `prefer-es6-class` | ||
* Fix `jsx-key` false-positives ([#320][] @silvenon) | ||
### Changed | ||
* Documentation improvements ([#368][] @lencioni, [#370][] @tmcw, [#371][]) | ||
* Update dependencies | ||
[3.13.0]: https://github.com/yannickcr/eslint-plugin-react/compare/v3.12.0...v3.13.0 | ||
[#341]: https://github.com/yannickcr/eslint-plugin-react/issues/341 | ||
[#355]: https://github.com/yannickcr/eslint-plugin-react/issues/355 | ||
[#320]: https://github.com/yannickcr/eslint-plugin-react/issues/320 | ||
[#368]: https://github.com/yannickcr/eslint-plugin-react/pull/368 | ||
[#370]: https://github.com/yannickcr/eslint-plugin-react/pull/370 | ||
[#371]: https://github.com/yannickcr/eslint-plugin-react/issues/371 | ||
## [3.12.0] - 2015-12-20 | ||
@@ -8,0 +30,0 @@ ### Added |
@@ -39,3 +39,4 @@ 'use strict'; | ||
'prefer-es6-class': require('./lib/rules/prefer-es6-class'), | ||
'jsx-key': require('./lib/rules/jsx-key') | ||
'jsx-key': require('./lib/rules/jsx-key'), | ||
'no-string-refs': require('./lib/rules/no-string-refs') | ||
}, | ||
@@ -77,4 +78,5 @@ rulesConfig: { | ||
'prefer-es6-class': 0, | ||
'jsx-key': 0 | ||
'jsx-key': 0, | ||
'no-string-refs': 0 | ||
} | ||
}; |
@@ -7,2 +7,4 @@ /** | ||
// var Components = require('../util/Components'); | ||
// ------------------------------------------------------------------------------ | ||
@@ -14,13 +16,27 @@ // Rule Definition | ||
function isKeyProp(decl) { | ||
if (decl.type === 'JSXSpreadAttribute') { | ||
return false; | ||
function hasKeyProp(node) { | ||
return node.openingElement.attributes.some(function(decl) { | ||
if (decl.type === 'JSXSpreadAttribute') { | ||
return false; | ||
} | ||
return (decl.name.name === 'key'); | ||
}); | ||
} | ||
function checkIteratorElement(node) { | ||
if (node.type === 'JSXElement' && !hasKeyProp(node)) { | ||
context.report(node, 'Missing "key" prop for element in iterator'); | ||
} | ||
return (decl.name.name === 'key'); | ||
} | ||
function getReturnStatement(body) { | ||
return body.filter(function(item) { | ||
return item.type === 'ReturnStatement'; | ||
})[0]; | ||
} | ||
return { | ||
JSXElement: function(node) { | ||
if (node.openingElement.attributes.some(isKeyProp)) { | ||
return; // has key prop | ||
if (hasKeyProp(node)) { | ||
return; | ||
} | ||
@@ -31,8 +47,29 @@ | ||
} | ||
}, | ||
if (node.parent.type === 'ArrowFunctionExpression') { | ||
context.report(node, 'Missing "key" prop for element in iterator'); | ||
// Array.prototype.map | ||
CallExpression: function (node) { | ||
if (node.callee.property.name !== 'map') { | ||
return; | ||
} | ||
var fn = node.arguments[0]; | ||
var isFn = fn.type === 'FunctionExpression'; | ||
var isArrFn = fn.type === 'ArrowFunctionExpression'; | ||
if (isArrFn && fn.body.type === 'JSXElement') { | ||
checkIteratorElement(fn.body); | ||
} | ||
if (isFn || isArrFn) { | ||
if (fn.body.type === 'BlockStatement') { | ||
checkIteratorElement( | ||
getReturnStatement(fn.body.body).argument | ||
); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
module.exports.schema = []; |
/** | ||
* @fileoverview Prefer es6 class instead of createClass for React Component | ||
* @fileoverview Enforce ES5 or ES6 class for React Components | ||
* @author Dan Hamilton | ||
@@ -20,3 +20,6 @@ */ | ||
context.report(node, 'Component should use es6 class instead of createClass'); | ||
} else if (utils.isES6Component(node) && configuration === 'never') { | ||
} | ||
}, | ||
ClassDeclaration: function(node) { | ||
if (utils.isES6Component(node) && configuration === 'never') { | ||
context.report(node, 'Component should use createClass instead of es6 class'); | ||
@@ -28,2 +31,4 @@ } | ||
module.exports.schema = []; | ||
module.exports.schema = [{ | ||
enum: ['always', 'never'] | ||
}]; |
@@ -11,2 +11,3 @@ /** | ||
var Components = require('../util/Components'); | ||
var variable = require('../util/variable'); | ||
@@ -522,2 +523,14 @@ // ------------------------------------------------------------------------------ | ||
break; | ||
case 'Identifier': | ||
var variablesInScope = variable.variablesInScope(context); | ||
for (var i = 0, j = variablesInScope.length; i < j; i++) { | ||
if (variablesInScope[i].name !== propTypes.name) { | ||
continue; | ||
} | ||
var defInScope = variablesInScope[i].defs[variablesInScope[i].defs.length - 1]; | ||
markPropTypesAsDeclared(node, defInScope.node && defInScope.node.init); | ||
return; | ||
} | ||
ignorePropsValidation = true; | ||
break; | ||
case null: | ||
@@ -524,0 +537,0 @@ break; |
{ | ||
"name": "eslint-plugin-react", | ||
"version": "3.12.0", | ||
"version": "3.13.0", | ||
"author": "Yannick Croissant <yannick.croissant+npm@gmail.com>", | ||
@@ -28,3 +28,3 @@ "description": "React specific linting rules for ESLint", | ||
"coveralls": "2.11.6", | ||
"eslint": "2.0.0-alpha-1", | ||
"eslint": "2.0.0-alpha-2", | ||
"istanbul": "0.4.1", | ||
@@ -31,0 +31,0 @@ "mocha": "2.3.4" |
@@ -74,3 +74,2 @@ ESLint-plugin-React | ||
"react/jsx-no-duplicate-props": 1, | ||
"react/jsx-no-is-mounted": 1, | ||
"react/jsx-no-literals": 1, | ||
@@ -89,4 +88,6 @@ "react/jsx-no-undef": 1, | ||
"react/no-direct-mutation-state": 1, | ||
"react/no-is-mounted": 1, | ||
"react/no-multi-comp": 1, | ||
"react/no-set-state": 1, | ||
"react/no-string-refs": 1, | ||
"react/no-unknown-property": 1, | ||
@@ -133,4 +134,5 @@ "react/prefer-es6-class": 1, | ||
* [no-set-state](docs/rules/no-set-state.md): Prevent usage of `setState` | ||
* [no-string-refs](docs/rules/no-string-refs.md): Prevent using string references in `ref` attribute. | ||
* [no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property | ||
* [prefer-es6-class](docs/rules/prefer-es6-class.md): Prefer es6 class instead of createClass for React Components | ||
* [prefer-es6-class](docs/rules/prefer-es6-class.md): Enforce ES5 or ES6 class for React Components | ||
* [prop-types](docs/rules/prop-types.md): Prevent missing props validation in a React component definition | ||
@@ -137,0 +139,0 @@ * [react-in-jsx-scope](docs/rules/react-in-jsx-scope.md): Prevent missing `React` when using JSX |
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
167644
43
3839
168