Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

What is the correct syntax for defining rules in tslint.json? #3100

Closed
BehindTheMath opened this issue Aug 7, 2017 · 8 comments
Closed

What is the correct syntax for defining rules in tslint.json? #3100

BehindTheMath opened this issue Aug 7, 2017 · 8 comments

Comments

@BehindTheMath
Copy link
Contributor

From the TSLint docs, it sounds like the only way to specify options for a rule is to set the rule as an object, and use the options property. For example:

"comment-format": {
    options: ["check-space"],
}

However, I've seen in many places, including the tslint:all configuration as well as TSLint's own tslint.json, where the rule is set as an array, and the options are in an array along with true.
For example, "comment-format": [true, "check-space"].

It appears from this commit and this comment, that the original syntax was the array syntax, and the options syntax was added later. At that time, tslint:latest and tsint:recommended were updated to follow it, but not other files. Is that correct? It looks like from the code that both are currently supported. Is the newer options syntax recommended over the legacy array syntax?

I think the documentation could be clearer about this, especially since the array syntax is so common, and there's currently no mention of it.

@adidahiya
Copy link
Contributor

Yes, the newer options syntax added in TSLint v5 is preferred over the legacy array syntax, since it makes tslint.json easier to read.

I agree that the documentation around this is sparse and could use some updating.

@BehindTheMath
Copy link
Contributor Author

And the correct syntax for setting a rule to off is "align": false?

@adidahiya
Copy link
Contributor

@BehindTheMath yep

@ChrisMBarr
Copy link
Contributor

Will this be normalized in the future to only allow one kind of syntax?

@adidahiya
Copy link
Contributor

@ChrisMBarr yeah, I think so. It's not a high priority to deprecate the legacy syntax since it doesn't require much code to maintain, but we might start adding deprecation warnings about it in the next few months and remove support for legacy syntax in a few major versions. I'm a little hesitant about it since there are lots of configuration presets out in the wild that could be relying on the old syntax.

@ajafff
Copy link
Contributor

ajafff commented Aug 13, 2017

On a side note, the option examples in the rule docs advertise the old config style.
For example: "quotemark": [true, "single", "avoid-escape", "avoid-template"]

We'd need to change this in the metadata of every rule.

@JoshuaKGoldberg
Copy link
Contributor

☠️ TSLint's time has come! ☠️

TSLint is no longer accepting most feature requests per #4534. See typescript-eslint.io for the new, shiny way to lint your TypeScript code with ESLint. ✨

It was a pleasure open sourcing with you all!

@JoshuaKGoldberg
Copy link
Contributor

🤖 Beep boop! 👉 TSLint is deprecated 👈 (#4534) and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋

@palantir palantir locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants