Skip to content

Commit

Permalink
jsx-first-pro-new-line autofix implementation
Browse files Browse the repository at this point in the history
Test should ignore indent for now
  • Loading branch information
snowypowers committed Nov 2, 2016
1 parent b292fbf commit 5265126
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/rules/jsx-first-prop-new-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
category: 'Stylistic Issues',
recommended: false
},
fixable: 'code',

schema: [{
enum: ['always', 'never', 'multiline', 'multiline-multiprop']
Expand All @@ -39,7 +40,10 @@ module.exports = {
if (decl.loc.start.line === node.loc.start.line) {
context.report({
node: decl,
message: 'Property should be placed on a new line'
message: 'Property should be placed on a new line',
fix: function(fixer) {
return fixer.insertTextAfter(node.name, '\n');
}
});
}
});
Expand All @@ -48,7 +52,10 @@ module.exports = {
if (node.loc.start.line < firstNode.loc.start.line) {
context.report({
node: firstNode,
message: 'Property should be placed on the same line as the component declaration'
message: 'Property should be placed on the same line as the component declaration',
fix: function(fixer) {
return fixer.replaceTextRange([node.name.end, firstNode.start], ' ');
}
});
return;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/rules/jsx-first-prop-new-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
invalid: [
{
code: '<Foo prop="one" />',
output: [
'<Foo',
' prop="one" />'
].join('\n'),
options: ['always'],
errors: [{message: 'Property should be placed on a new line'}],
parser: parserOptions
Expand All @@ -163,6 +167,12 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
' 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: parserOptions
Expand All @@ -174,6 +184,11 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
' 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: parserOptions
Expand Down

0 comments on commit 5265126

Please sign in to comment.