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

New line indentation #1

Closed
asiniy opened this issue Mar 25, 2016 · 13 comments
Closed

New line indentation #1

asiniy opened this issue Mar 25, 2016 · 13 comments

Comments

@asiniy
Copy link

asiniy commented Mar 25, 2016

Huge thanks for you for this plugin!

I found just one drawback. Plugin pose all JSX tags just in one line. How can I avoid it?

@flying-sheep
Copy link
Owner

Huge thanks for you for this plugin!

i’m glad it’s useful for you!

I found just one drawback. Plugin pose all JSX tags just in one line. How can I avoid it?

i don’t know, but maybe we can find out together.

do you know how babel/ESTree represents whitespace?

@asiniy
Copy link
Author

asiniy commented Mar 25, 2016

Unfortunately, nope.

@flying-sheep
Copy link
Owner

so you say

<ol>
    <li>a</li>
    <li>b</li>
</ol>

gets converted to

<ol><li>a</li><li>b</li></ol>

or what?

@asiniy
Copy link
Author

asiniy commented Mar 27, 2016

I mean

React.createElement("ul", React.createElement("li"))

converts to

<ul><li></li></ul>

not

<ul>
  <li></li>
</ul>

@flying-sheep
Copy link
Owner

well, that’s correct, no?

React.createElement("ul",
    React.createElement("li")
)

should convert to

<ul>
  <li></li>
</ul>

or similar.

@foxyblocks
Copy link
Contributor

It's not just JSX. I noticed that it did this for simple arrays also. I tried with a simple example:

Before:

let my_list = [
  "one",
  "two",
  "three",
  "four"
];

after:

let my_list = ["one", "two", "three", "four"];

@flying-sheep
Copy link
Owner

huh? that’s really weird, as i only replace nodes that pass all the checks (i.e. are React.createElement calls, etc.)

is what you observe inside of such an expression or will a file containing only what you showed me be transformed like that?

@foxyblocks
Copy link
Contributor

foxyblocks commented Aug 26, 2016

Only what I showed you. It's a file containing only an array

@foxyblocks
Copy link
Contributor

Adding the following to the test file will reproduce this:

it('should ignore regular javascript arrays', () => {
    let source = `
      let list = [
        "one",
        "two",
        "three",
      ]
    `
  expect(source).to.convertTo(source)
})

results in:

  1) createElement-to-JSX should ignore regular javascript arrays:

      Code “
      let list = [
        "one",
        "two",
        "three",
      ]
    ” converts wrongly
      + expected - actual


      -let list = ["one", "two", "three"];
      +      let list = [
      +        "one",
      +        "two",
      +        "three",
      +      ]
      +

      at Assertion.<anonymous> (test/chai-convert-to.js:62:41)
      at Assertion.ctx.(anonymous function) [as convertTo] (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
      at Context.<anonymous> (test/index.js:72:21)

I'll try to debug further, to see if I can't get to the bottom of it.

@foxyblocks
Copy link
Contributor

Further investigation shows that this is a problem with babel itself. I can reproduce it by running babel without any plugin options. Using the babel --retain-lines flag can mostly mitigate it, but not perfectly:

before

let foo = [
  'one',
  'two',
  'three'
];

after

let foo = [
'one',
'two',
'three'];

@flying-sheep
Copy link
Owner

OK, so it’s not actually a bug and i can close it, right?

@foxyblocks
Copy link
Contributor

I should think so

@flying-sheep
Copy link
Owner

OK, thanks for investigating!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants