Skip to content

Commit a92a0fb

Browse files
authored
Merge pull request #2026 from HauptmannEck/master
Use `loc` version of `end`, to handle parsers that don't fill `name.end`.
2 parents 24044e0 + a7cbf40 commit a92a0fb

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

lib/rules/jsx-first-prop-new-line.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545
node: decl,
4646
message: 'Property should be placed on a new line',
4747
fix: function(fixer) {
48-
return fixer.replaceTextRange([node.name.end, decl.range[0]], '\n');
48+
return fixer.replaceTextRange([node.name.range[1], decl.range[0]], '\n');
4949
}
5050
});
5151
}
@@ -58,7 +58,7 @@ module.exports = {
5858
node: firstNode,
5959
message: 'Property should be placed on the same line as the component declaration',
6060
fix: function(fixer) {
61-
return fixer.replaceTextRange([node.name.end, firstNode.range[0]], ' ');
61+
return fixer.replaceTextRange([node.name.range[1], firstNode.range[0]], ' ');
6262
}
6363
});
6464
return;

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"coveralls": "^3.0.1",
3838
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0",
3939
"istanbul": "^0.4.5",
40-
"mocha": "^5.2.0"
40+
"mocha": "^5.2.0",
41+
"typescript": "^3.1.3",
42+
"typescript-eslint-parser": "^20.0.0"
4143
},
4244
"peerDependencies": {
4345
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0"

tests/lib/rules/jsx-first-prop-new-line.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
129129
options: ['multiline-multiprop'],
130130
parser: 'babel-eslint'
131131
},
132+
{
133+
code: [
134+
'<Foo ',
135+
' foo={{',
136+
' }}',
137+
' bar',
138+
'/>'
139+
].join('\n'),
140+
options: ['multiline-multiprop'],
141+
parser: 'typescript-eslint-parser'
142+
},
132143
{
133144
code: '<Foo />',
134145
options: ['always'],
@@ -167,6 +178,16 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
167178
errors: [{message: 'Property should be placed on a new line'}],
168179
parser: 'babel-eslint'
169180
},
181+
{
182+
code: '<Foo propOne="one" propTwo="two" />',
183+
output: [
184+
'<Foo',
185+
'propOne="one" propTwo="two" />'
186+
].join('\n'),
187+
options: ['always'],
188+
errors: [{message: 'Property should be placed on a new line'}],
189+
parser: 'typescript-eslint-parser'
190+
},
170191
{
171192
code: [
172193
'<Foo propOne="one"',
@@ -183,6 +204,22 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
183204
errors: [{message: 'Property should be placed on a new line'}],
184205
parser: 'babel-eslint'
185206
},
207+
{
208+
code: [
209+
'<Foo propOne="one"',
210+
' propTwo="two"',
211+
'/>'
212+
].join('\n'),
213+
output: [
214+
'<Foo',
215+
'propOne="one"',
216+
' propTwo="two"',
217+
'/>'
218+
].join('\n'),
219+
options: ['always'],
220+
errors: [{message: 'Property should be placed on a new line'}],
221+
parser: 'typescript-eslint-parser'
222+
},
186223
{
187224
code: [
188225
'<Foo',
@@ -199,6 +236,22 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
199236
errors: [{message: 'Property should be placed on the same line as the component declaration'}],
200237
parser: 'babel-eslint'
201238
},
239+
{
240+
code: [
241+
'<Foo',
242+
' propOne="one"',
243+
' propTwo="two"',
244+
'/>'
245+
].join('\n'),
246+
output: [
247+
'<Foo propOne="one"',
248+
' propTwo="two"',
249+
'/>'
250+
].join('\n'),
251+
options: ['never'],
252+
errors: [{message: 'Property should be placed on the same line as the component declaration'}],
253+
parser: 'typescript-eslint-parser'
254+
},
202255
{
203256
code: [
204257
'<Foo prop={{',
@@ -213,6 +266,20 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
213266
errors: [{message: 'Property should be placed on a new line'}],
214267
parser: 'babel-eslint'
215268
},
269+
{
270+
code: [
271+
'<Foo prop={{',
272+
'}} />'
273+
].join('\n'),
274+
output: [
275+
'<Foo',
276+
'prop={{',
277+
'}} />'
278+
].join('\n'),
279+
options: ['multiline'],
280+
errors: [{message: 'Property should be placed on a new line'}],
281+
parser: 'typescript-eslint-parser'
282+
},
216283
{
217284
code: [
218285
'<Foo bar={{',
@@ -226,6 +293,20 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
226293
options: ['multiline-multiprop'],
227294
errors: [{message: 'Property should be placed on a new line'}],
228295
parser: 'babel-eslint'
296+
},
297+
{
298+
code: [
299+
'<Foo bar={{',
300+
'}} baz />'
301+
].join('\n'),
302+
output: [
303+
'<Foo',
304+
'bar={{',
305+
'}} baz />'
306+
].join('\n'),
307+
options: ['multiline-multiprop'],
308+
errors: [{message: 'Property should be placed on a new line'}],
309+
parser: 'typescript-eslint-parser'
229310
}
230311
]
231312
});

0 commit comments

Comments
 (0)