eslint: Key-spacing alignment problem.

I really like intelliJ Idea style object alignment. But I didn’t create a linting rule for desired alignment style. For instance the following snippet is properly formatted in My IDE.

let items = {
  item115: {
    id      : 100,
    name    : 'item1',
    itemList: [1, 2, 3]
  },
  item2  : {
    id      : 101,
    name    : 'item2',
    itemList: [1, 2, 3]
  }
};

My key-spacing rule is:

{
  "key-spacing"    : [
    "error",
    {
      "singleLine": {
        "beforeColon": false,
        "afterColon" : true
      },
      "multiLine" : {
        "beforeColon": true,
        "afterColon" : true,
        "align"      : "colon"
      }
    }
  ]
}

IMHO multiLine beforeColon option should be three stated. true, false and off. Is there a way to properly linting above code snippet?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 16 (11 by maintainers)

Most upvoted comments

@firatkucuk thanks, let’s see if we can get support from the team to accept this so you can start working.


To the team: We had an accepted proposal in #2668 that would support IntelliJ-style alignment in key-spacing, but the issue was closed when nobody was interested in working on it. @firatkucuk has volunteered to work on a PR, so I’ll copy the proposal here and see what you all think.

A new option "grouping" which has two possible values:

  • "multi-line" (default): Values spanning multiple lines end their group
  • "empty-line": Blank lines (no comments, no code, just whitespace) create new groups

I do think we should support IntelliJ-style alignment, so I’ll champion.