eslint-plugin-react
Advanced tools
Comparing version 4.2.3 to 4.3.0
@@ -6,2 +6,25 @@ # Change Log | ||
## [4.3.0] - 2016-04-07 | ||
### Added | ||
* Add `require-render-return` rule ([#482][] @shmuga) | ||
* Add auto fix for `jsx-equals-spacing` ([#506][] @peet) | ||
* Add auto fix for `jsx-closing-bracket-location` ([#511][] @KevinGrandon) | ||
### Fixed | ||
* Fix `prefer-stateless-function` for conditional JSX ([#516][]) | ||
* Fix `jsx-pascal-case` to support single letter component names ([#505][] @dthielman) | ||
### Changed | ||
* Update dependencies | ||
* Documentation improvements ([#509][] @coryhouse, [#526][] @ahoym) | ||
[4.3.0]: https://github.com/yannickcr/eslint-plugin-react/compare/v4.2.3...v4.3.0 | ||
[#482]: https://github.com/yannickcr/eslint-plugin-react/issues/482 | ||
[#506]: https://github.com/yannickcr/eslint-plugin-react/pull/506 | ||
[#511]: https://github.com/yannickcr/eslint-plugin-react/pull/511 | ||
[#516]: https://github.com/yannickcr/eslint-plugin-react/issues/516 | ||
[#505]: https://github.com/yannickcr/eslint-plugin-react/issues/505 | ||
[#509]: https://github.com/yannickcr/eslint-plugin-react/pull/509 | ||
[#526]: https://github.com/yannickcr/eslint-plugin-react/pull/526 | ||
## [4.2.3] - 2016-03-15 | ||
@@ -8,0 +31,0 @@ ### Fixed |
@@ -44,3 +44,4 @@ 'use strict'; | ||
'no-string-refs': require('./lib/rules/no-string-refs'), | ||
'prefer-stateless-function': require('./lib/rules/prefer-stateless-function') | ||
'prefer-stateless-function': require('./lib/rules/prefer-stateless-function'), | ||
'require-render-return': require('./lib/rules/require-render-return') | ||
}, | ||
@@ -47,0 +48,0 @@ configs: { |
@@ -145,6 +145,21 @@ /** | ||
var lastAttributeEndPos; | ||
var lastAttributeStartPos; | ||
return { | ||
JSXOpeningElement: function(node) { | ||
JSXAttribute: function(node) { | ||
lastAttributeEndPos = node.end; | ||
lastAttributeStartPos = node.start; | ||
}, | ||
'JSXOpeningElement:exit': function(node) { | ||
var cachedLastAttributeEndPos = lastAttributeEndPos; | ||
var cachedLastAttributeStartPos = lastAttributeStartPos; | ||
var expectedNextLine; | ||
var tokens = getTokensLocations(node); | ||
var expectedLocation = getExpectedLocation(tokens); | ||
lastAttributeStartPos = null; | ||
lastAttributeEndPos = null; | ||
if (hasCorrectLocation(tokens, expectedLocation)) { | ||
@@ -158,3 +173,3 @@ return; | ||
if (correctColumn !== null) { | ||
var expectedNextLine = tokens.lastProp && | ||
expectedNextLine = tokens.lastProp && | ||
(tokens.lastProp.line === tokens.closing.line); | ||
@@ -169,3 +184,42 @@ data.details = ' (expected column ' + (correctColumn + 1) + | ||
message: MESSAGE, | ||
data: data | ||
data: data, | ||
fix: function(fixer) { | ||
var closingTag = tokens.selfClosing ? '/>' : '>'; | ||
switch (expectedLocation) { | ||
case 'after-tag': | ||
if (cachedLastAttributeEndPos) { | ||
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end], | ||
(expectedNextLine ? '\n' : '') + closingTag); | ||
} | ||
return fixer.replaceTextRange([node.name.loc.end.column + 1, node.end], | ||
(expectedNextLine ? '\n' : '') + closingTag); | ||
case 'after-props': | ||
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end], | ||
(expectedNextLine ? '\n' : '') + closingTag); | ||
case 'props-aligned': | ||
var spaces = new Array(cachedLastAttributeEndPos - cachedLastAttributeStartPos); | ||
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end], | ||
'\n' + spaces.join(' ') + closingTag); | ||
case 'tag-aligned': | ||
var tagSpaces = new Array(node.start); | ||
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end], | ||
'\n' + tagSpaces.join(' ') + closingTag); | ||
case 'line-aligned': | ||
var walkNode = node; | ||
var lineSpaces = 0; | ||
while ((walkNode = walkNode.parent)) { | ||
if (walkNode.type === 'VariableDeclaration' || | ||
walkNode.type === 'ReturnStatement' || | ||
walkNode.type === 'ExpressionStatement') { | ||
lineSpaces = walkNode.loc.start.column + 1; | ||
break; | ||
} | ||
} | ||
lineSpaces = new Array(lineSpaces); | ||
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end], | ||
'\n' + lineSpaces.join(' ') + closingTag); | ||
default: | ||
return true; | ||
} | ||
} | ||
}); | ||
@@ -172,0 +226,0 @@ } |
@@ -46,3 +46,6 @@ /** | ||
loc: equalToken.loc.start, | ||
message: 'There should be no space before \'=\'' | ||
message: 'There should be no space before \'=\'', | ||
fix: function(fixer) { | ||
return fixer.removeRange([attrNode.name.range[1], equalToken.start]); | ||
} | ||
}); | ||
@@ -54,3 +57,6 @@ } | ||
loc: equalToken.loc.start, | ||
message: 'There should be no space after \'=\'' | ||
message: 'There should be no space after \'=\'', | ||
fix: function(fixer) { | ||
return fixer.removeRange([equalToken.end, attrNode.value.range[0]]); | ||
} | ||
}); | ||
@@ -64,3 +70,6 @@ } | ||
loc: equalToken.loc.start, | ||
message: 'A space is required before \'=\'' | ||
message: 'A space is required before \'=\'', | ||
fix: function(fixer) { | ||
return fixer.insertTextBefore(equalToken, ' '); | ||
} | ||
}); | ||
@@ -72,3 +81,6 @@ } | ||
loc: equalToken.loc.start, | ||
message: 'A space is required after \'=\'' | ||
message: 'A space is required after \'=\'', | ||
fix: function(fixer) { | ||
return fixer.insertTextAfter(equalToken, ' '); | ||
} | ||
}); | ||
@@ -75,0 +87,0 @@ } |
@@ -12,3 +12,3 @@ /** | ||
var PASCAL_CASE_REGEX = /^[A-Z0-9]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*$/; | ||
var PASCAL_CASE_REGEX = /^([A-Z0-9]|[A-Z0-9]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*)$/; | ||
var COMPAT_TAG_REGEX = /^[a-z]|\-/; | ||
@@ -15,0 +15,0 @@ |
@@ -212,3 +212,3 @@ /** | ||
} | ||
if (!blockNode || !blockNode.key || blockNode.key.name !== 'render' || utils.isReturningJSX(node)) { | ||
if (!blockNode || !blockNode.key || blockNode.key.name !== 'render' || utils.isReturningJSX(node, true)) { | ||
return; | ||
@@ -215,0 +215,0 @@ } |
@@ -169,5 +169,6 @@ /** | ||
* @param {ASTNode} node The AST node being checked (can be a ReturnStatement or an ArrowFunctionExpression). | ||
* @param {Boolean} strict If true, in a ternary condition the node must return JSX in both cases | ||
* @returns {Boolean} True if the node is returning JSX, false if not | ||
*/ | ||
isReturningJSX: function(node) { | ||
isReturningJSX: function(node, strict) { | ||
var property; | ||
@@ -195,2 +196,6 @@ switch (node.type) { | ||
; | ||
var returnsConditionalJSX = | ||
strict ? (returnsConditionalJSXConsequent && returnsConditionalJSXAlternate) : | ||
(returnsConditionalJSXConsequent || returnsConditionalJSXAlternate); | ||
var returnsJSX = | ||
@@ -208,4 +213,3 @@ node[property] && | ||
return Boolean( | ||
returnsConditionalJSXConsequent || | ||
returnsConditionalJSXAlternate || | ||
returnsConditionalJSX || | ||
returnsJSX || | ||
@@ -212,0 +216,0 @@ returnsReactCreateElement |
{ | ||
"name": "eslint-plugin-react", | ||
"version": "4.2.3", | ||
"version": "4.3.0", | ||
"author": "Yannick Croissant <yannick.croissant+npm@gmail.com>", | ||
@@ -26,6 +26,6 @@ "description": "React specific linting rules for ESLint", | ||
"devDependencies": { | ||
"babel-eslint": "6.0.0-beta.6", | ||
"coveralls": "2.11.8", | ||
"eslint": "2.4.0", | ||
"istanbul": "0.4.2", | ||
"babel-eslint": "6.0.2", | ||
"coveralls": "2.11.9", | ||
"eslint": "2.7.0", | ||
"istanbul": "0.4.3", | ||
"mocha": "2.4.5" | ||
@@ -32,0 +32,0 @@ }, |
@@ -102,5 +102,5 @@ ESLint-plugin-React | ||
* [jsx-boolean-value](docs/rules/jsx-boolean-value.md): Enforce boolean attributes notation in JSX (fixable) | ||
* [jsx-closing-bracket-location](docs/rules/jsx-closing-bracket-location.md): Validate closing bracket location in JSX | ||
* [jsx-closing-bracket-location](docs/rules/jsx-closing-bracket-location.md): Validate closing bracket location in JSX (fixable) | ||
* [jsx-curly-spacing](docs/rules/jsx-curly-spacing.md): Enforce or disallow spaces inside of curly braces in JSX attributes (fixable) | ||
* [jsx-equals-spacing](docs/rules/jsx-equals-spacing.md): Enforce or disallow spaces around equal signs in JSX attributes | ||
* [jsx-equals-spacing](docs/rules/jsx-equals-spacing.md): Enforce or disallow spaces around equal signs in JSX attributes (fixable) | ||
* [jsx-handler-names](docs/rules/jsx-handler-names.md): Enforce event handler naming conventions in JSX | ||
@@ -107,0 +107,0 @@ * [jsx-indent-props](docs/rules/jsx-indent-props.md): Validate props indentation in JSX (fixable) |
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
220152
50
4977