Tslint: Implement smart tabs for indent rule

Created on 17 Oct 2017  路  7Comments  路  Source: palantir/tslint

Smart tabs allows the use of tabs for indentation, spaces for alignment. This is a crucial feature that there is basically no alternative to, if you're using tabs for indentation. Please implement this. I used it with ESLint and didn't come across any issues.

Declined

Most helpful comment

@ajafff With all due respect I don't think adding "tabs then spaces is allowed" is a particularly high maintenance cost.

All 7 comments

See #1306 for similar discussion (dup?). My team ended up just writing it ourselves. If the resolution: declined is changed, I'd be happy to send a PR.

Erm, OK, that discussion is pretty silly. TSLint needs to reconsider this.

Firstly, it's obviously not that bad a practice or ESLint wouldn't have it as an option.

Secondly, it is a perfectly reasonable policy to use: tabs for indentation, spaces for alignment. This is a common thing to do, see this for example. We're not talking about mixing tabs and spaces willy nilly, we're talking about a situation where there is some code or a comment you want to align with other characters above or below it. You need to use tabs to indent it, but you can't use tabs to align the comment or it would move left or right with respect to the text it is supposed to align with if you change tab width. This is basically why "smart tabs" exists in ESLint. Come on, TSLint should have this too.

@jez9999 Every feature comes with a maintenance cost. Lately we try to reduce the effort spent on formatting related rules. There are good tools to manage your formatting (tsfmt, prettier, ...).
People complain about the indent rule very often. They want it to be smarter, automatically infer and fix the indent level, and so on. Meanwhile we want to keep the rule as basic as possible.

If a rule is not accepted in TSLint core for being too specific, you can still modify the existing rules for your needs and also publish it as a plugin.

@JoshuaKGoldberg maybe you can publish your custom rule as a package for others to use?

@ajafff With all due respect I don't think adding "tabs then spaces is allowed" is a particularly high maintenance cost.

I agree with @ajafff here, I think it's out of scope for the core indent rule and I'd like to reduce TSLint's responsibilities in the area of code formatting. It's easy enough to develop a custom rule and publish it to the community if you find value in this feature. We even highlight some custom rule sets in our README so that others can discover them.

@JoshuaKGoldberg, did your team ever publish your custom rule?

Oh, thanks for the reminder!

No, we didn't, because as ajafff mentioned this area of formatting is better left up to Prettier and we'd rather not take on the maintenance cost or encourage going against that.

Was this page helpful?
0 / 5 - 0 ratings