eslint-plugin-react
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -6,2 +6,27 @@ # Change Log | ||
## [4.2.0] - 2016-03-05 | ||
### Added | ||
* Add support for Flow annotations on stateless components ([#467][]) | ||
* Add `prefer-stateless-function` rule ([#214][]) | ||
* Add auto fix for `jsx-indent-props` ([#483][] @shioju) | ||
### Fixed | ||
* Fix `jsx-no-undef` crash on objects ([#469][]) | ||
* Fix propTypes detection when declared before the component ([#472][]) | ||
### Changed | ||
* Update dependencies | ||
* Documentation improvements ([#464][] @alex-tan, [#466][] @awong-dev, [#470][] @Gpx; [#462][] @thaggie) | ||
[4.2.0]: https://github.com/yannickcr/eslint-plugin-react/compare/v4.1.0...v4.2.0 | ||
[#467]: https://github.com/yannickcr/eslint-plugin-react/issues/467 | ||
[#214]: https://github.com/yannickcr/eslint-plugin-react/issues/214 | ||
[#483]: https://github.com/yannickcr/eslint-plugin-react/pull/483 | ||
[#469]: https://github.com/yannickcr/eslint-plugin-react/issues/469 | ||
[#472]: https://github.com/yannickcr/eslint-plugin-react/issues/472 | ||
[#464]: https://github.com/yannickcr/eslint-plugin-react/pull/464 | ||
[#466]: https://github.com/yannickcr/eslint-plugin-react/pull/466 | ||
[#470]: https://github.com/yannickcr/eslint-plugin-react/pull/470 | ||
[#462]: https://github.com/yannickcr/eslint-plugin-react/pull/462 | ||
## [4.1.0] - 2016-02-23 | ||
@@ -8,0 +33,0 @@ ### Added |
@@ -43,3 +43,4 @@ 'use strict'; | ||
'jsx-key': require('./lib/rules/jsx-key'), | ||
'no-string-refs': require('./lib/rules/no-string-refs') | ||
'no-string-refs': require('./lib/rules/no-string-refs'), | ||
'prefer-stateless-function': require('./lib/rules/prefer-stateless-function') | ||
}, | ||
@@ -46,0 +47,0 @@ configs: { |
@@ -81,3 +81,7 @@ /** | ||
message: MESSAGE, | ||
data: msgContext | ||
data: msgContext, | ||
fix: function(fixer) { | ||
return fixer.replaceTextRange([node.start - node.loc.start.column, node.start], | ||
Array(needed + 1).join(indentType === 'space' ? ' ' : '\t')); | ||
} | ||
}); | ||
@@ -84,0 +88,0 @@ } |
@@ -69,3 +69,6 @@ /** | ||
case 'JSXMemberExpression': | ||
node = node.name.object; | ||
node = node.name; | ||
do { | ||
node = node.object; | ||
} while (node && node.type !== 'JSXIdentifier'); | ||
break; | ||
@@ -72,0 +75,0 @@ case 'JSXNamespacedName': |
@@ -64,3 +64,3 @@ /** | ||
*/ | ||
function isAnnotatedPropsDeclaration(node) { | ||
function isAnnotatedClassPropsDeclaration(node) { | ||
if (node && node.type === 'ClassProperty') { | ||
@@ -80,2 +80,22 @@ var tokens = context.getFirstTokens(node, 2); | ||
/** | ||
* Checks if we are declaring a `props` argument with a flow type annotation. | ||
* @param {ASTNode} node The AST node being checked. | ||
* @returns {Boolean} True if the node is a type annotated props declaration, false if not. | ||
*/ | ||
function isAnnotatedFunctionPropsDeclaration(node) { | ||
if (node && node.params && node.params.length) { | ||
var tokens = context.getFirstTokens(node.params[0], 2); | ||
if ( | ||
node.params[0].typeAnnotation && ( | ||
tokens[0].value === 'props' || | ||
(tokens[1] && tokens[1].value === 'props') | ||
) | ||
) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
@@ -724,2 +744,22 @@ * Checks if we are declaring a prop | ||
/** | ||
* @param {ASTNode} node We expect either an ArrowFunctionExpression, | ||
* FunctionDeclaration, or FunctionExpression | ||
*/ | ||
function markAnnotatedFunctionArgumentsAsDeclared(node) { | ||
if (!node.params || !node.params.length || !isAnnotatedFunctionPropsDeclaration(node)) { | ||
return; | ||
} | ||
markPropTypesAsDeclared(node, resolveTypeAnnotation(node.params[0])); | ||
} | ||
/** | ||
* @param {ASTNode} node We expect either an ArrowFunctionExpression, | ||
* FunctionDeclaration, or FunctionExpression | ||
*/ | ||
function handleStatelessComponent(node) { | ||
markDestructuredFunctionArgumentsAsUsed(node); | ||
markAnnotatedFunctionArgumentsAsDeclared(node); | ||
} | ||
// -------------------------------------------------------------------------- | ||
@@ -731,3 +771,3 @@ // Public | ||
ClassProperty: function(node) { | ||
if (isAnnotatedPropsDeclaration(node)) { | ||
if (isAnnotatedClassPropsDeclaration(node)) { | ||
markPropTypesAsDeclared(node, resolveTypeAnnotation(node)); | ||
@@ -752,7 +792,7 @@ } else if (isPropTypesDeclaration(node)) { | ||
FunctionDeclaration: markDestructuredFunctionArgumentsAsUsed, | ||
FunctionDeclaration: handleStatelessComponent, | ||
ArrowFunctionExpression: markDestructuredFunctionArgumentsAsUsed, | ||
ArrowFunctionExpression: handleStatelessComponent, | ||
FunctionExpression: markDestructuredFunctionArgumentsAsUsed, | ||
FunctionExpression: handleStatelessComponent, | ||
@@ -759,0 +799,0 @@ MemberExpression: function(node) { |
@@ -27,2 +27,3 @@ /** | ||
* @param {Number} confidence Confidence in the component detection (0=banned, 1=maybe, 2=yes) | ||
* @returns {Object} Added component object | ||
*/ | ||
@@ -37,3 +38,3 @@ Components.prototype.add = function(node, confidence) { | ||
} | ||
return; | ||
return this._list[id]; | ||
} | ||
@@ -44,2 +45,3 @@ this._list[id] = { | ||
}; | ||
return this._list[id]; | ||
}; | ||
@@ -339,3 +341,3 @@ | ||
// Return the component | ||
return components.get(node); | ||
return components.add(node, 1); | ||
} | ||
@@ -342,0 +344,0 @@ }; |
{ | ||
"name": "eslint-plugin-react", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"author": "Yannick Croissant <yannick.croissant+npm@gmail.com>", | ||
@@ -26,4 +26,4 @@ "description": "React specific linting rules for ESLint", | ||
"devDependencies": { | ||
"babel-eslint": "5.0.0", | ||
"coveralls": "2.11.6", | ||
"babel-eslint": "6.0.0-beta.1", | ||
"coveralls": "2.11.8", | ||
"eslint": "2.2.0", | ||
@@ -30,0 +30,0 @@ "istanbul": "0.4.2", |
@@ -72,2 +72,4 @@ ESLint-plugin-React | ||
The plugin has a [recommended configuration](#user-content-recommended-configuration) that enforces React good practices. | ||
# List of supported rules | ||
@@ -88,2 +90,3 @@ | ||
* [prefer-es6-class](docs/rules/prefer-es6-class.md): Enforce ES5 or ES6 class for React Components | ||
* [prefer-stateless-function](docs/rules/prefer-stateless-function.md): Enforce stateless React Components to be written as a pure function | ||
* [prop-types](docs/rules/prop-types.md): Prevent missing props validation in a React component definition | ||
@@ -104,3 +107,3 @@ * [react-in-jsx-scope](docs/rules/react-in-jsx-scope.md): Prevent missing `React` when using JSX | ||
* [jsx-handler-names](docs/rules/jsx-handler-names.md): Enforce event handler naming conventions in JSX | ||
* [jsx-indent-props](docs/rules/jsx-indent-props.md): Validate props indentation in JSX | ||
* [jsx-indent-props](docs/rules/jsx-indent-props.md): Validate props indentation in JSX (fixable) | ||
* [jsx-indent](docs/rules/jsx-indent.md): Validate JSX indentation | ||
@@ -125,3 +128,3 @@ * [jsx-key](docs/rules/jsx-key.md): Validate JSX has key prop when in array or iterator | ||
This plugin export a `recommended` configuration that enforce React good practices. | ||
This plugin exports a `recommended` configuration that enforce React good practices. | ||
@@ -135,3 +138,3 @@ To enable this configuration use the `extends` property in your `.eslintrc` config file: | ||
], | ||
"extends": "plugin:react/recommended" | ||
"extends": ["eslint:recommended", "plugin:react/recommended"] | ||
} | ||
@@ -138,0 +141,0 @@ ``` |
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
206949
48
4729
184