-
Notifications
You must be signed in to change notification settings - Fork 122
Enable tslint with basic rules #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add tslint as a plugin to tsc, so that they will show up in vscode or whatever editor people use. I only enabled two basic rules that I think are very useful, prefer-const and no-var-keyword. Violations of these rules were fixed with "tslint -p . --fix". There was one unused variable (in the isExpandable) function that I removed by hand.
|
Context: We are looking into adding C/C++ debug support using GDB in the Theia project. We are already planning on using the Debug Adapter Protocol for other debuggers. Instead of starting from scratch for C/C++, I am considering using code-debug (and therefore probably contributing to it). Since I really appreciate what tslint does when writing code for Theia, I thought I would test the water by contributing this simple patch. |
I find this rule quite useful so that we use undefined all the time. The rationale on the rule's documentation page is quite clear: https://palantir.github.io/tslint/rules/no-null-keyword/
Rather than take a whitelist approach to the rules, I think it would be better to start with some goal (for example, the tslint:recommended set of rules) and disable those that we don't follow. This way, it's easy to see which ones we could potentially enable. This doesn't mean that we have to follow all of them. If there are rules that we don't want, we can move them to a "Rules from tslint:recommended that we don't want" section.
|
hm why no-var-keyword? Isn't var just the same as let... |
No, var is there only for compatibility with Javascript (so that Javascript code is also valid Typescript code). But the behavior is different regarding to scopes, See this for example: https://basarat.gitbooks.io/typescript/content/docs/let.html The tslint rule pages also have very good explanations of the rationales: https://palantir.github.io/tslint/rules/no-var-keyword/ |
var foo = 123;
if (true) {
var foo = 456;
}
console.log(foo); // 456wtf js... |
| }; | ||
|
|
||
| let stack = [root]; | ||
| const stack = [root]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh this variable gets changed (in line 65)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const prevents of the variable from being reassigned, not the object they "point" to from being modified. In C++, it would be equivalent to this:
const Object *stack;
and not:
const Object * const stack;
Indeed. And in my opinion, Typescript is really good at making you follow good practices if you use it properly. A next step would be to have stronger type checking ( |
|
cool thanks |
Add tslint as a plugin to tsc, so that they will show up in vscode or
whatever editor people use. I only enabled two basic rules that I think
are very useful, prefer-const and no-var-keyword. Violations of these
rules were fixed with "tslint -p . --fix". There was one unused
variable (in the isExpandable) function that I removed by hand.