According to the configuration document:
rules?: { [name: string]: RuleSetting }: A map of rule names to their configuration settings.
- These rules are applied to
.tsand.tsxfiles.- Each rule is associated with an object containing:
options?: any: An array of values that are specific to a rule.severity?: "default" | "error" | "warning" | "off": Severity level. Level "error" will cause exit code 2.- A boolean value may be specified instead of the above object, and is equivalent to setting no options with default severity.
- Any rules specified in this block will override those configured in any base configuration being extended.
- Check out the full rules list here.
To my understanding, the document says a rule should be associated with an object like this:
{
"options": ["option1", "option2", "option3"],
"serverity": "some value"
}
Or a boolean:
true
Or another boolean:
false
Is my understanding correct? If so, does specifying true has the same meaning as specifying false?
The document says the value of "options" is an array, for a rule like no-empty whose type is a string, should I enclose the string with an array?
Also, I saw many rule examples specifying an array with a leading true:
"indent": [true, "spaces", 4]
"interface-name": [true, "never-prefix"]
"max-classes-per-file": [true, 5, "exclude-class-expressions"]
I couldn鈥榯 find anything about this in the document. What does the leading true mean?
After reading the function that parses those rules (https://github.com/palantir/tslint/blob/master/src/configuration.ts#L392), I assume that:
{ "options": ["option1", "option2", "option3"], "severity": "some value" }"indent": [true, "spaces", 4] is considered legacy (see the comment // old style: array)"indent": [true, "spaces", 4] is strictly equivalent to "indent": { "options": ["spaces", 4] }For boolean:
if (typeof ruleConfigValue === "boolean") {
// old style: boolean
ruleArguments = [];
ruleSeverity = ruleConfigValue ? defaultRuleSeverity : "off";
}
So:
"indent": true is strictly equivalent to "indent": { "options": []}"indent": false is strictly equivalent to "indent": { "options": [], "severity": "off"}Thanks for clearing that up. Maybe the documentation should be updated to address this. It is really confusing for new users.
Most helpful comment
After reading the function that parses those rules (https://github.com/palantir/tslint/blob/master/src/configuration.ts#L392), I assume that:
{ "options": ["option1", "option2", "option3"], "severity": "some value" }"indent": [true, "spaces", 4]is considered legacy (see the comment// old style: array)"indent": [true, "spaces", 4]is strictly equivalent to"indent": { "options": ["spaces", 4] }For boolean:
So:
"indent": trueis strictly equivalent to"indent": { "options": []}"indent": falseis strictly equivalent to"indent": { "options": [], "severity": "off"}