Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Add simple lint on save support (closes #21) #68

Merged
merged 1 commit into from
Aug 20, 2016

Conversation

thomasboyt
Copy link
Contributor

I found constant linting updates really distracting while writing code, so I went ahead and implemented this. It uses the same setting format that the built-in PHP linter extension uses:

  // Whether the linter is run on save (onSave) or on type (onType)
  "tslint.run": "onType",

My first pass at this actually removed the 200ms delay on validation when in onSave mode, but I ran into a couple annoying problems:

  • onDidChangeContent is fired after onDidOpen and would clear the validation state on open
  • onDidChangeContent and onDidSave would be fired around the same time if I quickly saved after making a chance, and this lead to a common race condition where the state would get cleared after a save.

I couldn't think of a better way to avoid these issues without tracking a lot of extra state, and figured the 200ms delay is long enough that I don't think you'd ever see a race condition but short enough that it isn't painful.

@thomasboyt
Copy link
Contributor Author

thomasboyt commented Aug 4, 2016

Fwiw, I've been using this PR for the last few days, and have one major UX tweak I'd like to make. Hiding lint state until save is fine unless you're trying to fix a bunch of linting errors at once, and then it becomes annoying to have to re-save every time you change something.

I think a good tweak to this feature might be to enable lint-on-type if you have the Problems pane open, since if you're actively looking at errors, you probably don't want them to disappear as you edit. I don't know if other VSCode linters have done anything like this, would be neat to standardize on a UX going forward.

(otoh, while this is an issue, I still think this feature is pretty great as-is, as someone who finds linting-while-editing distracting enough that I would have completely opted out of in-editor linting without it!)

@egamma
Copy link
Member

egamma commented Aug 5, 2016

Thanks, I'll look into this PR as soon as I'm back from vacation.

@egamma egamma merged commit fdc7748 into microsoft:master Aug 20, 2016
@egamma
Copy link
Member

egamma commented Aug 20, 2016

Regarding clearing the diagnostics on content change. While the idea is good. Other language services like Php or Go that do validate on save do not clear the diagnostics on content change so I think tslint should be consistent and I'll remove this behaviour we can consider surfacing this behaviour behind a setting.

egamma added a commit that referenced this pull request Aug 22, 2016
@egamma
Copy link
Member

egamma commented Aug 22, 2016

I've published a new version of the tslint extension. Thanks again for the PR 🌹

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.

2 participants