3.14.01.8.10"extends" config parameter should allow an _array_ of "base" configurations to be passed.
There are custom rule sets created by the community. Some of them are fairly large (like tslint-microsoft-contrib) and contain a pretty big number of custom rules. It might get difficult to keep up with all of them, and even track which rule is taken from which set. Plus, such a mechanism will allow rule-providers to write their own "*:latest" and
"*:recommended" rule sets.
{
"extends": [
"tslint:latest",
"tslint-microsoft-contrib:latest (not that it's supported, but it could be)",
"some-npm-module-with-main",
"./my-custom-overrides.json"
]
}
If there are multiple values for the same rule in different sources, the latest will be taken (the "./my-custom-overrides.json" in the above example). The "rules" section in the tslint.json file itself will still override whatever is set in the "extends".
I think this already works -- did you try it @DethAriel?
In particular, this code manages merging of sources in the extends config
I tried it one more time - and I can't get it work with codelyzer rules in a separate file. I'll take a look tomorrow and provide an update
@adidahiya , that doesn't look to work afterall.
test.tsexport { thing: "my-stuff" };
tslint.json{
"extends": ["tslint:latest", "./mytslint.json"],
"rules": {}
}
mytslint.json{
"quotemark": [ true, "single" ]
}
tsconfig.json{
"compilerOptions": {
"target": "es5",
"module": "commonjs"
},
"files": ["./test.ts"]
}
tslint --project ./tsconfig.json
test.ts[1, 17]: " should be 'Everything works as expected if the tslint.json file looks like this:
{
"extends": ["tslint:latest", "./mytslint.json"],
"rules": {
"quotemark": [ true, "single" ]
}
}
@DethAriel mytslint.json is malformed. you need to include the "rules" key:
{
"rules": {
"quotemark": [ true, "single" ]
}
}
@adidahiya here's a unit test that proves it's not working
@DethAriel, the issue here, I believe, is that the "extends" configurations are applied in reverse order to what you are expecting. The last config you list in the extends array is actually the "base" config, and then each preceding configuration is applied on top of it.
In your case, "extends": ["./mytslint.json", "tslint:latest"], should work
@JKillian yes, thanks, that's what I thought too when browsing the sources. Yet this looks a bit counter-intuitive. But it might be that I don't see some trivial concept behind this.
Since this appears to be working after all, maybe it would make sense to add arrayish "extends" to the documentation along with the reasoning on why does the "inheritance" work this way instead of the other. Thoughts, @adidahiya ?
@DethAriel yep, definitely, better docs around this would definitely be accepted as contributions
@DethAriel Yes, I may have made the wrong choice on the order. Your way does seem a little more intuitive, although I'm worried about changing things now...
@JKillian I see your point, that would be a breaking change. Since there's little left to do on the initial issue, I'll open a different one with more context
Most helpful comment
@DethAriel, the issue here, I believe, is that the "extends" configurations are applied in reverse order to what you are expecting. The last config you list in the
extendsarray is actually the "base" config, and then each preceding configuration is applied on top of it.In your case,
"extends": ["./mytslint.json", "tslint:latest"],should work