Skip to content

Conversation

@simark
Copy link
Contributor

@simark simark commented Jul 17, 2018

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.

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.
@simark
Copy link
Contributor Author

simark commented Jul 17, 2018

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.

simark added 2 commits July 17, 2018 18:48
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.
@WebFreak001
Copy link
Owner

hm why no-var-keyword? Isn't var just the same as let...

@simark
Copy link
Contributor Author

simark commented Jul 18, 2018

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, let doing the thing you would expect from any other language.

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/

@WebFreak001
Copy link
Owner

var foo = 123;
if (true) {
    var foo = 456;
}
console.log(foo); // 456

wtf js...

};

let stack = [root];
const stack = [root];
Copy link
Owner

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)

Copy link
Contributor Author

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;

@simark
Copy link
Contributor Author

simark commented Jul 18, 2018

var foo = 123;
if (true) {
var foo = 456;
}
console.log(foo); // 456

wtf js...

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 (noImplicitAny and strictNullChecks in the compiler options).

@WebFreak001 WebFreak001 merged commit 57afc83 into WebFreak001:master Jul 18, 2018
@WebFreak001
Copy link
Owner

cool thanks

@simark simark deleted the tslint branch July 18, 2018 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants