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

Indentation in nested arrays/objects with comma-first style #85

Open
jfmatt-zz opened this issue Jul 24, 2013 · 2 comments
Open

Indentation in nested arrays/objects with comma-first style #85

jfmatt-zz opened this issue Jul 24, 2013 · 2 comments
Labels

Comments

@jfmatt-zz
Copy link

Hello. I've run across an issue with indenting a particular piece of code that features an array of object literals when using comma-first style.

The result I'm getting is the following:

var x = [
  {
    a: 123
  , b: 456
  }
, {
  a: 789
, b: 012
}
, {
  a: 'abc'
, b: 'xyz'
}
]

Note the contents and closing braces of the 2nd and 3rd objects, which are all one indentation level too far to the left. The same thing happens whether using tab-mode or spaces, and with all four combinations of the inner and nested values being objects or arrays.

By contrast, with comma-last notation, everything works perfectly/as expected:

var x = [
  {
    a: 123
  , b: 456
  },
  {
    a: 789
  , b: 012
  },
  {
    a: 'abc'
  , b: 'xyz'
  }
]

I'm using all default indentation options. Turning lazy-commas on drags the offending objects (all but the first) even farther to the left, so that the leading commas and closing braces are on the left baseline.

@jfmatt-zz jfmatt-zz reopened this Jul 24, 2013
@tamzinblake
Copy link
Owner

Interesting. Normally I use this sort of style:

var x = [ { a: 123
          , b: 456
          }
        , { a: 789
          , b: 012
          }
        , { a: 'abc'
          , b: 'xyz'
          }
        ]

There's clearly a semantic issue on line 7 of your first example - it should be indenting from the brace, not from the start of the line. I'll have to look into that.

@tamzinblake
Copy link
Owner

Ah yes, since a is not preceded by an operator, it's falling back to standard continued expression indentation, which just looks at the previous line's indentation, and thus indents from the comma.

Going to have to fester on this one.

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

No branches or pull requests

2 participants