Skip to content

Fix as many linter errors as possible#4008

Merged
DanielRosenwasser merged 3 commits into
microsoft:masterfrom
weswigham:fix-many-linter-errors
Aug 6, 2015
Merged

Fix as many linter errors as possible#4008
DanielRosenwasser merged 3 commits into
microsoft:masterfrom
weswigham:fix-many-linter-errors

Conversation

@weswigham
Copy link
Copy Markdown
Member

There are still a number of linter errors left due to tslint not yet supporting abstract or is. There is also an unreachable code lint error thrown on the final line of src/compiler/binder.ts - I can't find a cause for that one.

@danquirk
Copy link
Copy Markdown
Member

👍

Comment thread src/compiler/checker.ts
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was reported by a linter error? I think the original location was more appropriate.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was. It was unreachable code - if this was ever compiled to a let in the result rather than a var, the resulting TS wouldn't have run correctly. :D

let declarations after a return statement are unreachable and are therefore never scoped, unlike a var which would be hoisted with the function definition.

So you can say the linter found a bug waiting to happen here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see; nice!. Perhaps it would be better to just make it a var declaration again.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do that it'll have to be wrapped:

/* tslint:disable:no-var-keyword */
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
var _displayBuilder: SymbolDisplayBuilder;
/* tslint:enable:no-var-keyword */

Is it worth it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No one is going to want that amount of verbosity to disable things, especially one liners

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was the point? You're not supposed to disable the linter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there is an interesting push and pull in this sort of thing. You can make the syntax to disable things as gross as possible to disincentivize disabling, on the other hand you might accept that disabling things is a fact of life and it shouldn't look like an atrocity.

This is a good example of what I was mentioning to @DanielRosenwasser as far as how I only fixed the easy 80-90% cases as the rest that require non-trivial rewrites will generate some amount of discussion on whether we feel some particular situation warrants an exception.

My opinion is just make the change to satisfy the linter. While I see the argument for the 'define as close to usage as possible' it's not hard to use GoToDef occasionally vs adding gross comments.

@weswigham
Copy link
Copy Markdown
Member Author

I've run the project against the tslint config in #3995 and fixed all the style errors that exposed.

The quotes were really not actually consistent at all. We should get tslint fixed and get it running as part of the tests.

Comment thread src/compiler/binder.ts
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like the kind of place you want to mix quotes instead of using escapes (except for the hilarious inversion of ' and " on each side of the ||)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a number of places where that's true... but quote consistency is there for quote consistency, not for convenience, I suppose.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I saw a bunch more and didn't bother commenting again. I don't feel super strongly here but I always found mixing ' and " handy for cases like this but I can live without it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually been wondering this for awhile - since template strings are a thing in JS now, why don't linters have an option to prefer those? I think they're a bit more flexible and generally easier to keep consistent with. Plus, it reduces what you have as far as string literals go from quotes and backticks to just backticks. (Since you're likely using backticks for interpolation anyway!)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weswigham TSLint supports string templates for the quote rule -- it does this by simply ignoring the contents of template strings. So a "double" quote rule really means only allow double quotes or string templates.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean, why not forbid all quotes (single and double)? Template string literals can function as string literals handily, and it further unifies what string literals get used. Not really relevant here, I was just wondering why no linting tools seemed to support this option.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weswigham that's a valid suggestion. filed that feature request here: palantir/tslint#539

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still prefer to be able to mix quotes. I think it would be preferable for TSLint to support "double quotes unless the string contains a double quote."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be a problem if you used backticks for all the quotes. Until you needed to include backticks. 😄

But no really - try not to mix quotes. It makes sense not to mix quotes if you consider searching for strings in the source code. Knowing the exact quotes used lets you (plaintext) search with much higher precision - knowing you can always Ctrl-Shift-F "Joe's "Error" Message" (over 'Joe's "Error" Message') is way easier than not knowing if it's in one of many possible string formats. Generally speaking it's worth the effort of needing to toss in a \ in your string literals every so often.

@danquirk
Copy link
Copy Markdown
Member

👍

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Aug 4, 2015

@weswigham Can you refresh this PR?

@weswigham weswigham force-pushed the fix-many-linter-errors branch from 6b81883 to 5324f8b Compare August 4, 2015 20:38
@weswigham
Copy link
Copy Markdown
Member Author

Done. Also fixed a handful of new lint errors that have since been introduced. >.>

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Aug 4, 2015

👍

DanielRosenwasser added a commit that referenced this pull request Aug 6, 2015
Fix as many linter errors as possible
@DanielRosenwasser DanielRosenwasser merged commit 2b8ef5e into microsoft:master Aug 6, 2015
@DanielRosenwasser
Copy link
Copy Markdown
Member

Thanks @weswigham!

@adidahiya
Copy link
Copy Markdown
Contributor

I just published v2.5.0-dev.1 of tslint, which uses v1.6.0-dev.20150805 of the compiler, on the next dist-tag. There's still more work to be done to decouple the tslint lib from the compiler (palantir/tslint#280), but this should help you start linting the new syntax.

https://github.com/palantir/tslint#next-distribution

@weswigham weswigham deleted the fix-many-linter-errors branch August 17, 2017 23:02
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants