eslint-plugin-react
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -0,1 +1,11 @@ | ||
1.4.0 / 2015-02-24 | ||
================== | ||
* update prop-types to check props usage insead of propTypes presence ([#4][]) | ||
* add react-in-jsx-scope rule ([#5][] @glenjamin) | ||
* add jsx-uses-react rule ([#6][] @glenjamin) | ||
[#4]: https://github.com/yannickcr/eslint-plugin-react/issues/4 | ||
[#5]: https://github.com/yannickcr/eslint-plugin-react/pull/5 | ||
[#6]: https://github.com/yannickcr/eslint-plugin-react/pull/6 | ||
1.3.0 / 2015-02-24 | ||
@@ -2,0 +12,0 @@ ================== |
@@ -5,2 +5,3 @@ 'use strict'; | ||
rules: { | ||
'jsx-uses-react': require('./lib/rules/jsx-uses-react'), | ||
'no-multi-comp': require('./lib/rules/no-multi-comp'), | ||
@@ -12,5 +13,7 @@ 'prop-types': require('./lib/rules/prop-types'), | ||
'no-did-mount-set-state': require('./lib/rules/no-did-mount-set-state'), | ||
'no-did-update-set-state': require('./lib/rules/no-did-update-set-state') | ||
'no-did-update-set-state': require('./lib/rules/no-did-update-set-state'), | ||
'react-in-jsx-scope': require('./lib/rules/react-in-jsx-scope') | ||
}, | ||
rulesConfig: { | ||
'jsx-uses-react': 0, | ||
'no-multi-comp': 0, | ||
@@ -22,4 +25,5 @@ 'prop-types': 0, | ||
'no-did-mount-set-state': 0, | ||
'no-did-update-set-state': 0 | ||
'no-did-update-set-state': 0, | ||
'react-in-jsx-scope': 0 | ||
} | ||
}; |
/** | ||
* @fileoverview Prevent missing propTypes in a React component definition | ||
* @fileoverview Prevent missing props validation in a React component definition | ||
* @author Yannick Croissant | ||
@@ -13,3 +13,4 @@ */ | ||
var hasPropTypes = false; | ||
var declaredPropTypes = []; | ||
var usedPropTypes = []; | ||
@@ -33,2 +34,9 @@ function isComponentDefinition(node) { | ||
'MemberExpression': function(node) { | ||
if (node.object.type !== 'ThisExpression' || node.property.name !== 'props') { | ||
return; | ||
} | ||
usedPropTypes.push(node.parent.property.name); | ||
}, | ||
'ObjectExpression': function(node) { | ||
@@ -42,5 +50,8 @@ | ||
var keyName = property.key.name || property.key.value; | ||
if (keyName === 'propTypes') { | ||
hasPropTypes = true; | ||
if (keyName !== 'propTypes') { | ||
return; | ||
} | ||
for (var i = 0, j = property.value.properties.length; i < j; i++) { | ||
declaredPropTypes.push(property.value.properties[i].key.name); | ||
} | ||
}); | ||
@@ -55,7 +66,10 @@ }, | ||
if (!hasPropTypes) { | ||
context.report(node, 'Component definition is missing props validation'); | ||
for (var i = 0, j = usedPropTypes.length; i < j; i++) { | ||
if (declaredPropTypes.indexOf(usedPropTypes[i]) === -1) { | ||
context.report(node, '\'' + usedPropTypes[i] + '\' is missing in props validation'); | ||
} | ||
} | ||
hasPropTypes = false; | ||
declaredPropTypes.length = 0; | ||
usedPropTypes.length = 0; | ||
} | ||
@@ -62,0 +76,0 @@ }; |
{ | ||
"name": "eslint-plugin-react", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"author": "Yannick Croissant <yannick.croissant+npm@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "React specific linting rules for ESLint", |
@@ -51,3 +51,5 @@ ESLint-plugin-React | ||
"react/no-did-mount-set-state": 1, | ||
"react/no-did-update-set-state": 1 | ||
"react/no-did-update-set-state": 1, | ||
"react/jsx-uses-react": 1, | ||
"react/react-in-jsx-scope": 1 | ||
} | ||
@@ -60,3 +62,3 @@ } | ||
* [no-multi-comp](docs/rules/no-multi-comp.md): Prevent multiple component definition per file | ||
* [prop-types](docs/rules/prop-types.md): Prevent missing propTypes in a React component definition | ||
* [prop-types](docs/rules/prop-types.md): Prevent missing props validation in a React component definition | ||
* [display-name](docs/rules/display-name.md): Prevent missing displayName in a React component definition | ||
@@ -67,2 +69,4 @@ * [wrap-multilines](docs/rules/wrap-multilines.md): Prevent missing parentheses around multilines JSX | ||
* [no-did-update-set-state](docs/rules/no-did-update-set-state.md): Prevent usage of setState in componentDidUpdate | ||
* [jsx-uses-react](docs/rules/jsx-uses-react.md): Make JSX count towards use of a declared variable | ||
* [react-in-jsx-scope](docs/rules/react-in-jsx-scope.md): Prevent errors from not requiring React when using JSX | ||
@@ -69,0 +73,0 @@ ## To Do |
19784
15
357
103