Skip to content

Commit 5265126

Browse files
committed
jsx-first-pro-new-line autofix implementation
Test should ignore indent for now
1 parent b292fbf commit 5265126

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
category: 'Stylistic Issues',
1616
recommended: false
1717
},
18+
fixable: 'code',
1819

1920
schema: [{
2021
enum: ['always', 'never', 'multiline', 'multiline-multiprop']
@@ -39,7 +40,10 @@ module.exports = {
3940
if (decl.loc.start.line === node.loc.start.line) {
4041
context.report({
4142
node: decl,
42-
message: 'Property should be placed on a new line'
43+
message: 'Property should be placed on a new line',
44+
fix: function(fixer) {
45+
return fixer.insertTextAfter(node.name, '\n');
46+
}
4347
});
4448
}
4549
});
@@ -48,7 +52,10 @@ module.exports = {
4852
if (node.loc.start.line < firstNode.loc.start.line) {
4953
context.report({
5054
node: firstNode,
51-
message: 'Property should be placed on the same line as the component declaration'
55+
message: 'Property should be placed on the same line as the component declaration',
56+
fix: function(fixer) {
57+
return fixer.replaceTextRange([node.name.end, firstNode.start], ' ');
58+
}
5259
});
5360
return;
5461
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
153153
invalid: [
154154
{
155155
code: '<Foo prop="one" />',
156+
output: [
157+
'<Foo',
158+
' prop="one" />'
159+
].join('\n'),
156160
options: ['always'],
157161
errors: [{message: 'Property should be placed on a new line'}],
158162
parser: parserOptions
@@ -163,6 +167,12 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
163167
' propTwo="two"',
164168
'/>'
165169
].join('\n'),
170+
output: [
171+
'<Foo',
172+
' propOne="one"',
173+
' propTwo="two"',
174+
'/>'
175+
].join('\n'),
166176
options: ['always'],
167177
errors: [{message: 'Property should be placed on a new line'}],
168178
parser: parserOptions
@@ -174,6 +184,11 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
174184
' propTwo="two"',
175185
'/>'
176186
].join('\n'),
187+
output: [
188+
'<Foo propOne="one"',
189+
' propTwo="two"',
190+
'/>'
191+
].join('\n'),
177192
options: ['never'],
178193
errors: [{message: 'Property should be placed on the same line as the component declaration'}],
179194
parser: parserOptions

0 commit comments

Comments
 (0)