Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.

jsx-first-pro-new-line autofix implementation #2

Merged
merged 7 commits into from
Oct 4, 2016
Merged

jsx-first-pro-new-line autofix implementation #2

merged 7 commits into from
Oct 4, 2016

Conversation

snowypowers
Copy link

First submission of autofix

  • Add fixable to rules file
  • Add fixers for each of the 2 cases
  • Add output code for each invalid test case

@@ -120,6 +120,10 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
invalid: [
{
code: '<Foo prop="one" />',
output: [
'<Foo',
' prop="one" />'
Copy link

@yangshun yangshun Oct 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation looks off (cross ref line 101 and line 111).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I have been looking at this problem. To solve this, I would have to change the schema to intake the indent size. Would this be ok?

On a side note, jsx-indent-props solves this properly but would need a second run.

- Adjust old cases to use default 2 indents
- Add new case to use optional rule for 4 indents
Utilised getNodeIndent helper from jsx-indent-props as base-code
@snowypowers
Copy link
Author

Indentation has been fixed. A new test case has been added to showcase ability to specify indentation style.

@@ -120,6 +120,10 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
invalid: [
{
code: '<Foo prop="one" />',
output: [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add test cases for tabs too. Thanks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just added.

Copy link

@shioju shioju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify getNodeIndent further.

},

create: function (context) {
var configuration = context.options[0];
var extraColumnStart = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always zero. Can delete.

byLastLine = byLastLine || false;
excludeCommas = excludeCommas || false;

var src = sourceCode.getText(node, node.loc.start.column + extraColumnStart);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraColumnStart is always zero.

message: 'Property should be placed on a new line'
message: 'Property should be placed on a new line',
fix: function(fixer) {
var nodeIndent = getNodeIndent(node, false, false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNodeIndent's 2nd and 3rd arguments are default to false, can remove here.

}

function getNodeIndent(node, byLastLine, excludeCommas) {
byLastLine = byLastLine || false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNodeIndent is only called in one place, and called with byLastLine and excludeCommas set to false. Can just remove these 2 variables and short circuit their values into this function to make it simpler.

cut out unused vars based on feedback
@snowypowers
Copy link
Author

function amended as requested.

@shioju shioju merged commit 0771c11 into GovTechSG:master Oct 4, 2016
@shioju
Copy link

shioju commented Oct 4, 2016

We will contact you via email for payment matters. Pls submit a PR upstream as well, for the benefit of everyone else. Thanks. :-)

@shioju
Copy link

shioju commented Oct 4, 2016

Forgot to mention that you should also update README.md to add (fixable) next to this rule, and also update jsx-first-prop-new-line.md with the identation options. Can refer to jsx-indent-props.md.

@revisionfour
Copy link

revisionfour commented Nov 1, 2016

Are you guys still working on this?
jsx-eslint#886

There are some teams across the globe that could really benefit from a --fix command for this eslint rule. Let me know if you need help. @snowypowers @shioju @yangshun @gyng @lawliet89

@shioju
Copy link

shioju commented Nov 1, 2016

yes @revisionfour, but right now it can't handle the case where the first line has more than one prop. gonna fix that then push. thanks for asking.

shioju pushed a commit that referenced this pull request Nov 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants