Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use loc version of end, to handle parsers that don't fill name.end. #2026

Merged
merged 2 commits into from Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'
}
]
});