adrianlee44 / atom-aligner

Easily align multi-line with support for different operators and custom configurations
https://atom.io/packages/aligner
MIT License
78 stars 3 forks source link

Alignment issue with Babel ES6 Javascript #41

Closed radnor closed 8 years ago

radnor commented 8 years ago

How can I make it so that aligner treats the Babel ES6 Javascript language from language-babel correctly?

Here's my original object.

var initialState = {
  a: [],
  bbb: null,
  ccccc: null,
  ddd: 11,
  eeeeeeee: [],
  fff: 0,
  gggg: {},
  hhh: null,
  iiii: null
};

If I'm set to Babel ES6 JavaScript from language-babel I get this alignment.

var initialState = {
  a: []       , 
  bbb: null   , 
  ccccc: null , 
  ddd: 11     , 
  eeeeeeee: [], 
  fff: 0      , 
  gggg: {}    , 
  hhh: null   , 
  iiii: null
};

If I set the language to JavaScript I get this (proper) alignment.

var initialState = {
  a:        [],
  bbb:      null,
  ccccc:    null,
  ddd:      11,
  eeeeeeee: [],
  fff:      0,
  gggg:     {},
  hhh:      null,
  iiii:     null
};
adrianlee44 commented 8 years ago

So the bug has to do with the language grammar. In language-javascript, : has an operator scope which allows aligner to determine how to align these characters.

If you can get me the scope of : in language-bable, that would be great!

radnor commented 8 years ago

According to Babel Language.json this is how : is treated. There are a few other instances in the file as well... hope this helps! :smile:

"literal-regexp": {
      "patterns": [
        {
          "name": "string.regexp.js",
          "begin": "(?<=\\.|\\(|,|{|}|\\[|;|,|<|>|<=|>=|==|!=|===|!==|\\+|-|\\*|%|\\+\\+|--|<<|>>|>>>|&|\\||\\^|!|~|&&|\\|\\||\\?|:|=|\\+=|-=|\\*=|%=|<<=|>>=|>>>=|&=|\\|=|\\^=|/|/=|\\Wnew|\\Wdelete|\\Wvoid|\\Wtypeof|\\Winstanceof|\\Win|\\Wdo|\\Wreturn|\\Wcase|\\Wthrow|^new|^delete|^void|^typeof|^instanceof|^in|^do|^return|^case|^throw|^)\\s*(/)(?!/|\\*|$)",
          "end": "(/)([gimy]*)",
          "beginCaptures": {
            "1": { "name": "punctuation.definition.string.begin.js" }
          },
          "endCaptures": {
            "1": { "name": "punctuation.definition.string.end.js" },
            "2": { "name": "keyword.other.js" }
          },
          "patterns": [
            { "include": "source.regexp.babel" }
          ]
        }
      ]
    },
adrianlee44 commented 8 years ago

There seems to be multiple definitions for : depending on the type of the value but they are all separator.key-value.

I have updated aligner but there are some testing issues at the moment. I'll be releasing the new version once those are resolved.