Closed bencoveney closed 7 years ago
Yeah, I don't think it should consider case when sorting
Should be pretty easy to change the behavior to be case-insensitive. Change this line to:
const key = keyNode.text.toLowerCase();
... but this would unfortunately be a breaking change. Best thing would be to add this as a "ignore-case"
rule option and change the default in v5.0
Bug (Suggestion?) Report
4.2.0
2.0.7
TypeScript code being linted
with
tslint.json
configuration:Actual behavior
The following ordering is asserted by the rule:
Expected behavior
For context I have an object literal that I am using as a data store where the keys are CSGO team names. The code above is a sample but the real object is about 100 entries. Storing data in literals like this is not a great idea admittedly but the implication is that the keys can contain pretty much any character (for example capital letters) anywhere in the string.
The actual code sample is the order specified by TSLint. It looks like the rule compares strings by just doing
>
and JavaScript sorts capitals first IIRC which is what is giving the "almost" alphabetical result.Another simpler example would be:
The result is kind of logical but unexpected. If I were going through the code above and sorting my literals I would do it alphabetically and the fact that the rule told me otherwise would be confusing, it almost reduces you to trial and error unless you understand the comparison logic being used.
So my question is
Also thinking now about the iffy sample I've given, would it be good to subject object literal keys to the same kind of checks performed on identifiers? That is probably a different issue though.