If a project uses custom rules from multiple sources, managing the tslint.json file becomes a bit of a hassle. For example we use the base TSLint rules, rules from Microsoft, rules from ESLint, and custom rules we've written. Since *.json files do not support comments, my only way to group the rule configurations for each set of rules is to use multiple line breaks to help visually distinguish that they aren't part of the base rules.
Perhaps something like this
"extends" : "tslint:recommended",
"rules" : {
"no-constructor-vars": true
},
"rulesConfiguration" : [
"tslint-eslint.json",
"tslint-microsoft.json",
"tslint-custom-rules.json"
]
"rulesDirectory" : [
"/node_modules/tslint-eslint-rules/dist/rules",
"/node_modules/tslint-microsoft-contrib",
"/tslint-custom-rules"
]
That would use the recommended rules, override base rule settings, point to 3 different custom rule directories, and point to 3 different rule configuration files.
Alternatively, perhaps something like this might make more sense, I'm not sure
"extends" : "tslint:recommended",
"rules" : {
"no-constructor-vars": true
},
"rulesDirectory" : [
["/node_modules/tslint-eslint-rules/dist/rules", "tslint-eslint.json"]
["/node_modules/tslint-microsoft-contrib", "tslint-microsoft.json"],
["/tslint-custom-rules", "tslint-custom-rules.json"]
]
Actually, TSLint strips comments out of JSON files it loads! It also can load configurations .js CJS modules that export an object which will also let you use comments.
You can also extend multiple files, so you could break your configuration up into three files, and then extend them all in the one master config file.
One of these solutions should be adequate for your use case, right? I prefer not adding more complexity to configuration syntax/options if possible
Oh neat, I did not realize either of those things! How does the extending configuration files work?
You can provide an array to the extends field with multiple configs to extend. I think they are applied first to last, that is, the last specified config would have precedence if multiple sets of options were defined for the same rule.
So would I just provide an array of file paths?
"extends" : [
"tslint:recommended",
"path/to/tslint-eslint.json",
"path/to/tslint-microsoft.json",
"path/to/tslint-custom-rules.json"
],
"rules" : {
"no-constructor-vars": true
},
"rulesDirectory" : [
"/node_modules/tslint-eslint-rules/dist/rules",
"/node_modules/tslint-microsoft-contrib",
"/tslint-custom-rules"
]
Yep! Although you'll want to start relative paths with ./ or else it does node module look up.
Works great, thanks! This really simplifies some things for me!
Sweet, going to close this issue out in that case.
Most helpful comment
Yep! Although you'll want to start relative paths with
./or else it does node module look up.