-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into curly-spacing-for-children
- Loading branch information
Showing
27 changed files
with
1,306 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"env": { | ||
"node": true | ||
"es6": true, | ||
"node": true | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Validate closing tag location in JSX (react/jsx-closing-tag-location) | ||
|
||
Enforce the closing tag location for multiline JSX elements. | ||
|
||
**Fixable:** This rule is automatically fixable using the `--fix` flag on the command line. | ||
|
||
## Rule Details | ||
|
||
This rule checks all JSX multiline elements with children (non-self-closing) and verifies the location of the closing tag. The expectation is that the closing tag is aligned with the opening tag on its own line. | ||
|
||
The following patterns are considered warnings: | ||
|
||
```jsx | ||
<Hello> | ||
marklar | ||
</Hello> | ||
``` | ||
|
||
```jsx | ||
<Hello> | ||
marklar</Hello> | ||
``` | ||
|
||
The following are not considered warnings: | ||
|
||
```jsx | ||
<Hello> | ||
marklar | ||
</Hello> | ||
``` | ||
|
||
```jsx | ||
<Hello>marklar</Hello> | ||
``` | ||
|
||
## When not to use | ||
|
||
If you do not care about closing tag JSX alignment then you can disable this rule. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Prevent usage of shouldComponentUpdate when extending React.PureComponent (react/no-redundant-should-component-update) | ||
|
||
Warns if you have `shouldComponentUpdate` defined when defining a component that extends React.PureComponent. | ||
While having `shouldComponentUpdate` will still work, it becomes pointless to extend PureComponent. | ||
|
||
## Rule Details | ||
|
||
The following patterns are considered warnings: | ||
|
||
```jsx | ||
class Foo extends React.PureComponent { | ||
shouldComponentUpdate() { | ||
// do check | ||
} | ||
|
||
render() { | ||
return <div>Radical!</div> | ||
} | ||
} | ||
|
||
function Bar() { | ||
return class Baz extends React.PureComponent { | ||
shouldComponentUpdate() { | ||
// do check | ||
} | ||
|
||
render() { | ||
return <div>Groovy!</div> | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The following patterns are not considered warnings: | ||
|
||
```jsx | ||
class Foo extends React.Component { | ||
shouldComponentUpdate() { | ||
// do check | ||
} | ||
|
||
render() { | ||
return <div>Radical!</div> | ||
} | ||
} | ||
|
||
function Bar() { | ||
return class Baz extends React.Component { | ||
shouldComponentUpdate() { | ||
// do check | ||
} | ||
|
||
render() { | ||
return <div>Groovy!</div> | ||
} | ||
} | ||
} | ||
|
||
class Qux extends React.PureComponent { | ||
render() { | ||
return <div>Tubular!</div> | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* @fileoverview Validate closing tag location in JSX | ||
* @author Ross Solomon | ||
*/ | ||
'use strict'; | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
// ------------------------------------------------------------------------------ | ||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'Validate closing tag location for multiline JSX', | ||
category: 'Stylistic Issues', | ||
recommended: false | ||
}, | ||
fixable: 'whitespace' | ||
}, | ||
|
||
create: function(context) { | ||
var sourceCode = context.getSourceCode(); | ||
|
||
/** | ||
* Checks if the node is the first in its line, excluding whitespace. | ||
* @param {ASTNode} node The node to check | ||
* @return {Boolean} true if its the first node in its line | ||
*/ | ||
function isNodeFirstInLine(node) { | ||
let token = node; | ||
let lines; | ||
do { | ||
token = sourceCode.getTokenBefore(token); | ||
lines = token.type === 'JSXText' | ||
? token.value.split('\n') | ||
: null; | ||
} while ( | ||
token.type === 'JSXText' && | ||
/^\s*$/.test(lines[lines.length - 1]) | ||
); | ||
|
||
var startLine = node.loc.start.line; | ||
var endLine = token ? token.loc.end.line : -1; | ||
return startLine !== endLine; | ||
} | ||
|
||
return { | ||
JSXClosingElement: function(node) { | ||
if (!node.parent) { | ||
return; | ||
} | ||
|
||
const opening = node.parent.openingElement; | ||
if (opening.loc.start.line === node.loc.start.line) { | ||
return; | ||
} | ||
|
||
if (opening.loc.start.column === node.loc.start.column) { | ||
return; | ||
} | ||
|
||
let message; | ||
if (!isNodeFirstInLine(node)) { | ||
message = 'Closing tag of a multiline JSX expression must be on its own line.'; | ||
} else { | ||
message = 'Expected closing tag to match indentation of opening.'; | ||
} | ||
|
||
context.report({ | ||
node: node, | ||
loc: node.loc, | ||
message, | ||
fix: function(fixer) { | ||
const indent = Array(opening.loc.start.column + 1).join(' '); | ||
if (isNodeFirstInLine(node)) { | ||
return fixer.replaceTextRange( | ||
[node.start - node.loc.start.column, node.start], | ||
indent | ||
); | ||
} | ||
|
||
return fixer.insertTextBefore(node, `\n${indent}`); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.