angelozerr / tslint-language-service

TypeScript 2.2.1 plugin for tslint
MIT License
188 stars 22 forks source link

VSCode not recognizing tslint-language-service #40

Open jnarwold opened 7 years ago

jnarwold commented 7 years ago

I'm not sure if I've configured something incorrectly or if vscode is just struggling but I can't manage to get vscode to lint properly through the tslint-language-service.

tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "allowSyntheticDefaultImports": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "module": "commonjs",
    "types": ["mocha"],
    "target": "es2015",
    "jsx": "preserve",
    "experimentalDecorators": true,
    "plugins": [
      { "name": "tslint-language-service" }
    ]
  },
  "files": [
      "./src/abstractions/index.d.ts",
      "./node_modules/@types/webpack-env/index.d.ts",
      "./src/index.tsx"
  ],
  "exclude": [
      "node_modules"
  ],
  "include": [
    "."
  ]
}

tslint.json

{
    "rules": {
        "no-unused-expression": true,
        "no-duplicate-variable": true,
        "no-duplicate-key": true,
        "no-unnecessary-qualifier": true,
        "class-name": true,
        "interface-name": [true, "always-prefix"],
        "no-unnecessary-callback-wrapper": true,
        "object-literal-key-quotes": [true, "as-needed"],
        "object-literal-shorthand": true,
        "quotemark": [true, "single"],
        "semicolon": [true, "always"],
        "arrow-parens": [true, "ban-single-arg-parens"],
        "prefer-const": [true, {"destructuring": "any"}],
        "prefer-method-signature": true,
        "indent": [true, "spaces"],
        "use-isnan": true,
        "switch-default": true,
        "restrict-plus-operands": true,
        "radix": true,
        "no-var-keyword": true,
        "no-use-before-declare": true,
        "no-empty": true,
        "no-duplicate-super": true,
        "no-debugger": true,
        "no-default-export": true,
        "no-construct": true,
        "no-conditional-assignment": true,
        "no-string-throw": true,
        "promise-function-async": true,
        "prefer-for-of": true,
        "adjacent-overload-signatures": true,
        "typeof-compare": true,
        "triple-equals": [true, "allow-null-check"]
    }
}

server.ts (file I'm intentionally trying to break to catch errors)

var x = 2;

export function CreateThings(id){
  x = '2'; 
  var y = 2;  
  console.log("hello"); 
  console.log('hello');  
}

This should trip on multiple levels: no vars, single quotes, etc. Running TypeScript 2.3.3 Note: I can run tslint via the command line and it picks up on errors as expected.

angelozerr commented 7 years ago

Your tslint-language-service is installed in the same folder than typescript?

In other words have you that:

jnarwold commented 7 years ago

Yep - our web project (contains all the js/ts/etc. code) is a subdirectory of our core project. The structure of that web project looks like this with tslint & tsconfig being at the same level of the node_modules folder:

---> web project folder ------> node_modules ---------> typescript ---------> tslint-language-service ---------> tslint ------> tslint.json ------> tsconfig.json

angelozerr commented 7 years ago

Please share a little project which causes your pb, thanks

jnarwold commented 7 years ago

This is a drop of the codebase we're having issues with - due to size I had to delete everything from the node_modules so you'll want to run an npm install for that. server.ts has some random code that should be throwing 5-6 linter errors.

I've been futzing with it today and it appears the issue might stem from namespacing. If I copy the contents from a folder with . to one without, vscode picks up the errors as expected.

GMR.FMS.Web.zip

victornoel commented 7 years ago

@jnarwold have you also forced the use of the project's typescript install in vscode (by clicking on the version of typescript on the bottom right of the screen, next to the smiley and then selecting "use workspace version").

@angelozerr I've noticed that if you don't set "typescript.tsdk": "./node_modules/typescript/lib" in the workspace settings of vscode, it does not propose to use it…

angelozerr commented 7 years ago

@angelozerr I've noticed that if you don't set "typescript.tsdk": "./node_modules/typescript/lib" in the workspace settings of vscode, it does not propose to use it…

Yes you need that tslint-language-service is hosted inside the same folder than TypeScript, it's because of this declaration https://github.com/angelozerr/tslint-language-service/blob/master/src/index.ts#L1:

import * as ts_module from "../node_modules/typescript/lib/tsserverlibrary";

I have done like sample, but I'm not sure that's it's a good idea, see https://github.com/RyanCavanaugh/sample-ts-plugin/issues/2

TypeScript 2.4 will provide the capabilty to register a plugin "globally" so I think @egamma will use this feature inside VSCode to avoid installing at hand the tslint-language-service.

egamma commented 7 years ago

@victornoel I suggest you also try the vscode-tslint(vnext) extension. It bundles the tslint-language-service https://marketplace.visualstudio.com/items?itemName=eg2.ts-tslint

victornoel commented 7 years ago

@egamma so ultimately (when it is released), we should not use at all the tslint-language-service in our projects but simply add the extension, right?

egamma commented 7 years ago

@victornoel the goal for vscode users is that the user can just install a VS Code extension. The extension then has the typescript language server plugin bundled, so that the user doesn't have to install both an extension and the plugin.

If you want to use a different version of typescript using the tsdk setting, then you are on you need to use and configure the tslint-language-service directly.

victornoel commented 7 years ago

@egamma ok, I got it, thanks for the explanation :)

jnarwold commented 7 years ago

@victornoel - Yep! I'm using TypeScript 2.3.3 on VSCode through the vscode typescript install.

I don't believe this is a versioning issue, though. As I mentioned earlier, it seems to be directly linked to folder structure namespacing.

jnarwold commented 7 years ago

@angelozerr Any ideas on what might be causing the namespacing issue (if that is indeed the root of my problems)?

angelozerr commented 7 years ago

@jnarwold waiting for answer of https://github.com/RyanCavanaugh/sample-ts-plugin/issues/2

matheo commented 7 years ago

@egamma How do I confirm that vscode-tslint(vnext) extension is running?

I've followed the steps and so far, I don't see an option to check the log for the project or some command to run the linter and get the output. Do we get a friendly output to fix the problems with links to the files with errors?

Thanks a lot for the amazing work.

egamma commented 7 years ago

@matheo you can enable logging and you should see that the tslint language service trace messages. You can enable logging like: set TSS_LOG=-level verbose -file c:\tmp\tsserver.log

The message would look something like: Info 13 Loading tslint-language-service from C:\Users\egamma\.vscode-insiders\extensions\eg2.vscode-ts-tslint-0.0.1 (resolved to C:/Users/egamma/.vscode-insiders/extensions/eg2.vscode-ts-tslint-0.0.1/node_modules)

matheo commented 6 years ago

@egamma I'm trying with VSCode 1.22.2 and I had to select VSCode typescript version to be able to detect the plugin inside the extension ~/.vscode/extensions/eg2.ts-tslint-0.0.4/node_modules (Ubuntu 17.10)

But when I try to pick custom versions adding them to my local node_modules, it couldn't load it with typescript < 2.6:

Info 10   [11:48:56.877] Config file name: /my/tsconfig.json
Info 11   [11:48:57.100] Enabling plugin tslint-language-service from candidate paths: /media/work/git/selvera/provider/node_modules/typescript/lib/tsserver.js/../../..
Info 12   [11:48:57.100] Loading tslint-language-service from /my/node_modules/typescript/lib/tsserver.js/../../.. (resolved /my/node_modules/node_modules)
Info 13   [11:48:58.843] tslint-language-service loaded
Info 14   [11:48:58.844] Plugin activation failed: TypeError: info.project.getCurrentDirectory is not a function

With typescript ¬2.6 it finally worked:

Info 30   [11:52:23.321] Plugin validation succeded

and now I see this plugin is developed "typescript": "^2.7.2" which is far beyond my Angular 4, which supports <= 2.4.x. Will see if I have troubles with this typescript version. Thanks