interface IStuff {
b: string;
a: string;
c: string;
}
const stuff: IStuff = {
a: "123",
b: "12345",
c: "foobar"
};
with tslint.json configuration:
{
"defaultSeverity": "error",
"extends": ["tslint:recommended"],
"jsRules": {},
"rules": {
"arrow-parens": false,
"forin": false,
"interface-name": {
"options": ["always-prefix"]
},
"max-line-length": [true, 120],
"no-shadowed-variable": false,
"no-string-literal": false,
"no-trailing-whitespace": false,
"no-var-requires": false,
"object-literal-sort-keys": [true, "match-declaration-order"],
"only-arrow-functions": false,
"ordered-imports": false,
"space-before-function-paren": false,
"trailing-comma": false,
"variable-name": {
"options": ["allow-leading-underscore"]
}
},
"rulesDirectory": []
}
The stuff object is not initialized with the property order used in IStuff. So, according to my config, I expect tslint to complain about that.
TSLint does not complain at all. Even when I change the order in the literal, so it neither matches alphabetical order, nor interface order.
Am I getting something wrong or is this a bug?
I have the same issue in VSCode as well. In my tslint output (select "tslint" from the dropdown in the output panel the output panel) I get this message for every file:
The 'object-literal-sort-keys' rule threw an error in 'c:/PATH_TO_PROJECT/TYPESCRIPT_FILE.ts':
Error: object-literal-sort-keys needs type info to use "match-declaration-order".
at Rule.apply (c:\PATH_TO_PROJECT\PATH_TO_NODEMODULES\node_modules\tslint\lib\rules\objectLiteralSortKeysRule.js:45:19)
Are you getting the same message?
Here is where the error is being thrown. I might just be missing something, but it looks like that option is broken and it just always throws an error if it is specified.
https://github.com/palantir/tslint/blob/29fbace7bd67195c7e7f1f115a3170e092f4e78c/src/rules/objectLiteralSortKeysRule.ts#L85-L91
The rule requires type information, and so is not supported in VSCode. If run with type info (--project) the code run is https://github.com/palantir/tslint/blob/29fbace7bd67195c7e7f1f115a3170e092f4e78c/src/rules/objectLiteralSortKeysRule.ts#L93-L101 so the rule is actually used.
Feel free to reopen if the issue occurs outside of VSCode too.
@johnwiseheart What is "type info", and why does VSCode not support it? 馃槃
When you run tslint with Type Information, it means that it loads all of the files into memory so that it can compare the types between files. This is not possible by just linting individual files. See https://github.com/Microsoft/vscode-tslint/issues/70 for more information about why VSCode doesn't support it.
Most helpful comment
When you run
tslintwith Type Information, it means that it loads all of the files into memory so that it can compare the types between files. This is not possible by just linting individual files. See https://github.com/Microsoft/vscode-tslint/issues/70 for more information about why VSCode doesn't support it.