Skip to content
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

Rules silently fail in VS 2017 due to typescript version conflict #58

Closed
andyrooger opened this issue Jan 11, 2018 · 4 comments
Closed

Comments

@andyrooger
Copy link

  • typescript: 2.6.2
  • tslint: 5.9.1
  • tslint-language-service: 0.9.8

Short version

Rules either don't work or work badly when the version of typescript differs between tslint and VS. It is hard to notice when this has happened, and it's hard to stop it happening.

Long version

I am trying to get the language service set up in Vs 2017 and noticed certain rules (mainly semicolon) weren't producing linter errors. I tracked it down the issue to a difference in version between the typescript used by VS (and hence tslint-language-service) and the typescript used by tslint. The SyntaxKind enum has changed between 2.6.1 and 2.6.2, and the source file for tslint comes from the VS typescript version, but is walked using the tslint version.

I can confirm that downgrading my tslint version of typescript (in package.json) to 2.6.1 to match VS fixes things, however:

  • It seems to be very difficult to figure out the version of typescript that VS is running - the typescript tools version numbers match VS versions rather than typescript versions
  • Other members on my team will likely be running different versions of typescript tools and I don't want this to silently fail for them

I'm happy to have a go at fixing this but I'm not sure where to start:

  • Is this the right place for the bug, or should it be against tslint or typescript themselves?
  • Is Visual Studio (not Code) actually supported, since it's not on the examples?
  • Would it be reasonable to load source files with the typescript from package.json rather than with the Program passed back from the language service?
@andyrooger
Copy link
Author

To add a little to that - I can change a project's TypeScript tools version to a specific major and minor version, e.g. 2.6, but I can't choose 2.6.1 or 2.6.2 so it's hard to keep package.json and the language service in sync.

I've also realised I can figure out what specific version I'll be using on my own machine by digging through the folders installed in C:\Program Files (x86)\Microsoft SDKs\TypeScript.

@angelozerr
Copy link
Owner

tslint-language-service is just a simple TypeScript plugin. I don't know which fixes you wish to do?

@andyrooger
Copy link
Author

I was hoping either you might be able to tell me I'm doing it wrong, or that you would know where to start looking for a fix.

The reason I've raised an issue here is that on its own tslint works fine for me, it's just an issue when it is passed source files from Visual Studio. It's a really useful plugin, but this makes it hard for me to use it on a shared project in VS.

Two approaches I guess might work and are possible from the plugin are

  • Reload the source files using require('typescript') rather than the DI version
  • Force tslint to load up the DI version of typescript with something like mock-require

I'm happy to try writing both since it's easy for me to repro the problem, but do you think either of these approaches are reasonable?

andyrooger pushed a commit to andyrooger/tslint-language-service that referenced this issue Jan 11, 2018
andyrooger pushed a commit to andyrooger/tslint-language-service that referenced this issue Jan 11, 2018
andyrooger pushed a commit to andyrooger/tslint-language-service that referenced this issue Jan 11, 2018
andyrooger pushed a commit to andyrooger/tslint-language-service that referenced this issue Jan 11, 2018
@andyrooger
Copy link
Author

For now I have used the code from the PR to create a second plugin locally that loads before tslint-language-service that looks like this

// testing/tslint-language-service-versioner/index.js

"use strict";

function init(modules) {
    // Force tslint to load with the language service's version of typescript. Must be loaded before tslint-language-service
    require("mock-require")('typescript', modules.typescript);

    function create(info) {
        info.project.projectService.logger.info("tslint-language-service-versioner loaded");

        return info.languageService;
    }
    return { create };
}

module.exports = init;

and added it to tsconfig plugins as { "name": "../testing/tslint-language-service-versioner" }

This seems to work around the problem until an official fix makes it into npm.

andyrooger pushed a commit to andyrooger/tslint-language-service that referenced this issue Jan 15, 2018
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

No branches or pull requests

2 participants