Tslint: Vertical align by colon

Created on 5 Sep 2018  路  4Comments  路  Source: palantir/tslint

ESLint has key-spacing rule with options to converts this object

var obj = {
    foobar:42,
    bat: (2 * 2),
    abc :   'value'
}

to this

/*eslint key-spacing: [2, { "align":"colon", "beforeColon":true, "afterColon":true }]*/

var obj = {
    foobar : 42,
    bat    : (2 * 2),
    abc    : 'value'
}

Is it possible in TSLint?

Declined

All 4 comments

This is not possible in tslint right now. Currently the whitespace rule (I believe) has an option to force the colons to have no prefixed spaces (see example below). I think this tends to be the preferred method of formatting for js/ts and as such a rule to align by colon would probably not have a place in the tslint core rule set (we try to avoid heavily conflicting rules). That said, you can always write a custom rule yourself, and include it in your tslint config.

var obj = {
    foobar: 42,
    bat: (2 * 2),
    abc: 'value'
}

Add this code to your rules .eslint

key-spacing: ["error", { "align": "colon" }]

For more informations all here Docs

@uulgie you're giving example for ESLint, but this is TSLint repo ;)

@igor-sky Did you figure out how to do this?

I'm from .NET and it's common to do something similar so things look less noisy. I want to do this:

javascript var obj = { foobar: 42, bat: (2 * 2), abc: 'value' }
and
javascript const foo = "foo"; let bar = 10;

Was this page helpful?
0 / 5 - 0 ratings