Skip to content

Commit

Permalink
Merge pull request #2026 from HauptmannEck/master
Browse files Browse the repository at this point in the history
Use `loc` version of `end`, to handle parsers that don't fill `name.end`.
  • Loading branch information
ljharb committed Oct 24, 2018
2 parents 24044e0 + a7cbf40 commit a92a0fb
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/rules/jsx-first-prop-new-line.js
Expand Up @@ -45,7 +45,7 @@ module.exports = {
node: decl,
message: 'Property should be placed on a new line',
fix: function(fixer) {
return fixer.replaceTextRange([node.name.end, decl.range[0]], '\n');
return fixer.replaceTextRange([node.name.range[1], decl.range[0]], '\n');
}
});
}
Expand All @@ -58,7 +58,7 @@ module.exports = {
node: firstNode,
message: 'Property should be placed on the same line as the component declaration',
fix: function(fixer) {
return fixer.replaceTextRange([node.name.end, firstNode.range[0]], ' ');
return fixer.replaceTextRange([node.name.range[1], firstNode.range[0]], ' ');
}
});
return;
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -37,7 +37,9 @@
"coveralls": "^3.0.1",
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0",
"istanbul": "^0.4.5",
"mocha": "^5.2.0"
"mocha": "^5.2.0",
"typescript": "^3.1.3",
"typescript-eslint-parser": "^20.0.0"
},
"peerDependencies": {
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0"
Expand Down
81 changes: 81 additions & 0 deletions tests/lib/rules/jsx-first-prop-new-line.js
Expand Up @@ -129,6 +129,17 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
options: ['multiline-multiprop'],
parser: 'babel-eslint'
},
{
code: [
'<Foo ',
' foo={{',
' }}',
' bar',
'/>'
].join('\n'),
options: ['multiline-multiprop'],
parser: 'typescript-eslint-parser'
},
{
code: '<Foo />',
options: ['always'],
Expand Down Expand Up @@ -167,6 +178,16 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
errors: [{message: 'Property should be placed on a new line'}],
parser: 'babel-eslint'
},
{
code: '<Foo propOne="one" propTwo="two" />',
output: [
'<Foo',
'propOne="one" propTwo="two" />'
].join('\n'),
options: ['always'],
errors: [{message: 'Property should be placed on a new line'}],
parser: 'typescript-eslint-parser'
},
{
code: [
'<Foo propOne="one"',
Expand All @@ -183,6 +204,22 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
errors: [{message: 'Property should be placed on a new line'}],
parser: 'babel-eslint'
},
{
code: [
'<Foo propOne="one"',
' propTwo="two"',
'/>'
].join('\n'),
output: [
'<Foo',
'propOne="one"',
' propTwo="two"',
'/>'
].join('\n'),
options: ['always'],
errors: [{message: 'Property should be placed on a new line'}],
parser: 'typescript-eslint-parser'
},
{
code: [
'<Foo',
Expand All @@ -199,6 +236,22 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
errors: [{message: 'Property should be placed on the same line as the component declaration'}],
parser: 'babel-eslint'
},
{
code: [
'<Foo',
' propOne="one"',
' propTwo="two"',
'/>'
].join('\n'),
output: [
'<Foo propOne="one"',
' propTwo="two"',
'/>'
].join('\n'),
options: ['never'],
errors: [{message: 'Property should be placed on the same line as the component declaration'}],
parser: 'typescript-eslint-parser'
},
{
code: [
'<Foo prop={{',
Expand All @@ -213,6 +266,20 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
errors: [{message: 'Property should be placed on a new line'}],
parser: 'babel-eslint'
},
{
code: [
'<Foo prop={{',
'}} />'
].join('\n'),
output: [
'<Foo',
'prop={{',
'}} />'
].join('\n'),
options: ['multiline'],
errors: [{message: 'Property should be placed on a new line'}],
parser: 'typescript-eslint-parser'
},
{
code: [
'<Foo bar={{',
Expand All @@ -226,6 +293,20 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
options: ['multiline-multiprop'],
errors: [{message: 'Property should be placed on a new line'}],
parser: 'babel-eslint'
},
{
code: [
'<Foo bar={{',
'}} baz />'
].join('\n'),
output: [
'<Foo',
'bar={{',
'}} baz />'
].join('\n'),
options: ['multiline-multiprop'],
errors: [{message: 'Property should be placed on a new line'}],
parser: 'typescript-eslint-parser'
}
]
});

0 comments on commit a92a0fb

Please sign in to comment.