Giter Site home page Giter Site logo

tslint-language-service's Introduction

This project is now deprecated, please see the following repositories:

It was a great experiences to work with smart guys (Mircrosoft and other guys), but today I have no time to work on this project. See discussion at #88 (comment)

tslint-language-service

Build Status NPM version

TypeScript language service plugin for tslint.

To use it the plugin:

  • install the plugin with npm install tslint-language-service

  • enable the plugin in your tsconfig.json file:

{
  "compilerOptions": {
    "plugins": [
      { "name": "tslint-language-service"}
    ]
  }
}
  • If you are using TypeScript < 2.2.1, you must execute tsserver with tsserver-plugins.

Your node_modules folder should look like this:

  • node_modules
    • tslint
    • tslint-language-service
    • typescript

Notice due to an issue in the implementation of the no-unused-variable rule ([issue2469]), this rule will be disabled by the plugin. You can use the typescript compiler options noUnusedLocals and noUnusedParameters instead.

Configuration options

Notice this configuration settings allow you to configure the behaviour of the tslint-language-service plugin. To configure rules and tslint options you should use the tslint.json file.

  • configFile - the configuration file that tslint should use instead of the default tslint.json. A relative file path is resolved relative to the project root.
  • ignoreDefinitionFiles - control if TypeScript definition files should be ignored.
  • alwaysShowRuleFailuresAsWarnings - always show rule failures as warnings, ignoring the severity configuration in the tslint.json configuration.
  • disableNoUnusedVariableRule - disable no-unused-variable rule.
  • supressWhileTypeErrorsPresent - supress tslint errors from being reported while other errors are present.
  • mockTypeScriptVersion - force tslint to use the same version of TypeScript as this plugin. This will affect other plugins that require the typescript package.

Here a configuration sample:

{
  "compilerOptions": {
    "plugins": [
      { "name": "tslint-language-service",
        "alwaysShowRuleFailuresAsWarnings": false,
        "ignoreDefinitionFiles": true,
        "configFile": "../tslint.json",
        "disableNoUnusedVariableRule": false,
        "supressWhileTypeErrorsPresent": false,
        "mockTypeScriptVersion": false
      }
    ]
  }
}

Editors Support

All editors which consumes tsserver (VSCode >=1.16.1, Sublime, Eclipse, etc) can use tslint-language-service. Here a demo with Eclipse and tslint 5.0.0.

tslint demo

Eclipse

Install typescript.java and you can use the TypeScript Project wizard which configures tslint-language-service.

Visual Studio Code

If you also have the vscode-tslint extension in VS Code installed, please disable it to avoid that files are linted twice.

To use the plugin with VS Code (>=1.16.1):

  • If you are using the vscode-tslint extension disable or uninstall it.
  • Install typescript, the tslint-language-service, and tslint into your workspace using npm install typescript tslint tslint-language-service.
  • Open VS Code on the workspace
  • Switch to the Typescript version that is installed locally in the workspace using the version switcher (see below) in the bottom right of the status bar.

The most important differences between the vscode-tslint extension and the tslint-languageservice-plugin are:

  • The plugin shares the program representation with TypeScript. This is more efficient than the vscode-tslint extension which needs to reanalyze the document.
  • Since vscode-tslint lints one file a time only, it cannot support tslint rules that require the type checker. The language service plugin doesn't have this limitation.
  • vscode-tslint provides additional features, please file issue requests for the features you are missing.

ts version switcher

Demo

tslint demo VS Code

Development Setup

This section describes how to setup your environment so that you can develop and test the language server plugin.

The folder dev contains a project with a tsconfig.json that enables the tslint-languageservice plugin a tslint.json and some test files with rule violations you can use for manual testing.

VS Code

To compile the test for manual testing run npm run devtest, this script compiles the plugin and patches the tslint-language-service module inside the dev folder.

To test open VS Code on the dev folder and use the TypeScript version picker to switch to the local version of TypeScript. This version will use the patched tslint-language-service module.

To debug you use two versions of VS Code, e.g., the stable and the insider version. The idea is that one of them is configured to support attaching a debugger to the Typescript language server:

  • Use the insider version for development and open it on the tslint-language-service workspace.
  • Use the stable version for debugging opened on the dev folder of the tslint-language service.

To setup the stable version for debugging, you need to set the environment variable TSS_DEBUG to port 5859. In a command prompt/shell:

  • make sure that the stable version isn't running already
  • set TSS_DEBUG=5859
  • cd to the dev folder
  • code .

To debug the tslint-language-service plugin press F5. The dev workspace has a launch configuration that attaches through port 5859 to the language server. To set a break point open node_modules\tslint-language-service\out\src\index.js. You have to set the break point in the .js file, but you can step afterwards in the TypeScript source file.

tslint-language-service's People

Contributors

angelozerr avatar artola avatar bgever avatar egamma avatar istar-eldritch avatar krzkaczor avatar mjbvz avatar nicolashenry avatar oliverjash avatar simark avatar smasala avatar spion avatar zazzlealex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tslint-language-service's Issues

Rules silently fail in VS 2017 due to typescript version conflict

  • 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?

filterProblemsForDocument() lower-case file paths => breaks diagnostics (OSX)

This is the current code:
https://github.com/angelozerr/tslint-language-service/blob/72a02a2/src/index.ts#L99-L110

        function filterProblemsForDocument(documentPath: string, failures: tslint.RuleFailure[]): tslint.RuleFailure[] {
            let normalizedPath = path.normalize(documentPath);
            // we only show diagnostics targetting this open document, some tslint rule return diagnostics for other documents/files
            let normalizedFiles = new Map<string, string>();
            return failures.filter(each => {
                let fileName = each.getFileName();
                if (!normalizedFiles.has(fileName)) {
                    normalizedFiles.set(fileName, path.normalize(fileName));
                }
                return normalizedFiles.get(fileName) === normalizedPath;
            });
        }

The problem is that let fileName = each.getFileName(); returns lower-case file paths! For example, typically on OSX: /User/myName/etc. becomes /user/myname/etc.. No idea why.

I temporarily fixed this by adding .toLowerCase():
let normalizedPath = path.normalize(documentPath).toLowerCase();
...and just for consistency (not strictly needed):
let fileName = each.getFileName().toLowerCase();

Update when tslint.json changes

I had a rule causing me some trouble so I disabled it. I closed and open the offending file many times but vscode still warning about the disabled rule. It was fixed after I closed vscode itself.

Pass severity through to get to vscode

I have setup my tslint.json with a defaultSeverity of "warning". But when a tslint problem shows up in the compiler output and/or comes through the vscode it shows up as an error. Is this a limitation of the language service plugin or just something that isn't supported by typescript?

tslint language service must return a function of create to support TypeScript 2.2.1

Today tslint language service works only with https://github.com/angelozerr/tsserver-plugins and with TypeScript 2.2.1 directly.

It's because of the line https://github.com/Microsoft/TypeScript/blob/v2.2.1/src/server/project.ts#L906

const pluginModule = pluginModuleFactory({ typescript: ts });
this.languageService = pluginModule.create(info);

Today the tslint language service returns a create function although it should return a function (pluginModule ) which returns a create function.

Show the disable-next-line fix always.

Currently, the disable-next-line comment 'fix' shows up and works when there is another fix (eg ordered-imports) but not when there's no real fix provided (eg no-implicit-dependencies)
I suppose this is wrong, and it differs from vscode-tslint

`exclude` options

TLS is not respecting the tsconfig.exclude option.

Could be this possible fixed in TLS or is it a tslint issue?

Note: tslint CLI respects linterOptions.exclude

Some Feedback

I understand that this is work in progress, but here is some initial feedback:

  • The tslint-language-service currently has tslint as a dependency, should this be a peer dependency? This enables to update tslint independent of the tslint-language-service. This similar to tslint itself, it also has typescript as a peer dependency only.
  • I haven't seen any support for settings/options for tslint like the tslint.json file location (--configFile) or the location of additional rules (--rulesDirectory). I assume that such settings can also be done inside the tsconfig.json?
  • Support for code fixes is work in progress, but the implementation provides custom code fixes for no-var-keyword, no-trailing-whitespace the tslint rules already provide a fix for these rules and the custom code fixes should not be needed.

Create npm package

Using npm link is only a good solution during development. I would like to include this as a dev dependency in my package.json so everybody in the team uses the lint by default.

It would be nice to add the project to a CI and configure it to do automatic deployments when a new tag is added.

Update peerDependencies requirements to support TS 3

The package requires "typescript": ">= 2.3.1 < 3", then this warning is printed when running together to TS 3.

npm WARN [email protected] requires a peer of typescript@>= 2.3.1 < 3 but none is installed. You must install peer dependencies yourself.

Would be nice to update the peerDependencies to support TS 3, I did not find any problem while using it, but might be recommended check it with the tests.

Option to not report any errors while ts typecheck is failing

If typechecking the file fails, do not report any errors. Once all type (or syntax) errors in the file are fixed, start reporting.

This should reduce clutter and enable developers to "talk" with the type-checker first, fixing lint errors later.

disableNoUnusedVariableRule: false breaks import lookups

Hi

(I'm not sure if I should open this issue here or in vscode-ts-tslint.)

I recently installed vscode-ts-tslint (v0.0.7) in place of vscode-tslint, and I set "disableNoUnusedVariableRule": false in the tsconfig.json for tslint-language-service. I noticed that in this case the import lookups (including the auto-import) are broken. If I set this rule to true, or remove it from the config, lookups work again.

VSCode version: 1.24.0 (bug was the same with previous version too)

Let me know if you need further details.

UPDATE:

Apparently this happens to modules without type definition. See an example setup in this repo:
https://github.com/winston01/vscode-ts-tslint-no-unused-test

Here you can see that for example minimist (w/ a type definition) is recognized correctly, but moment (w/o type def.) is not. If you comment out "disableNoUnusedVariableRule": false in the tsconfig.json and reload the settings, you'll see that moment works too.

No linting rendered in VS Code 1.25.0

Updating to VS Code 1.25.0 has caused all linting information to no longer render. I checked the tsserver logs and the plugin is enabled successfully:

Info 22   [11:13:9.546] Enabling plugin tslint-language-service from candidate paths: /Users/anichols/code/test-tslint-plugin/node_modules/typescript/lib/tsserver.js/../../..
Info 23   [11:13:9.546] Loading tslint-language-service from /Users/anichols/code/test-tslint-plugin/node_modules/typescript/lib/tsserver.js/../../.. (resolved to /Users/anichols/code/test-tslint-plugin/node_modules/node_modules)
Info 24   [11:13:10.243] tslint-language-service loaded
Info 25   [11:13:10.243] Plugin validation succeded

I have created a simple example project to demonstrate: https://github.com/anthonynichols/test-tslint-plugin

I have included the tsserver.log file in that repo.

I can confirm that linting works in VS Code 1.24.1:

tslint-working

However, the same project does not work in VS Code 1.25.0:

tslint-not-working

Let me know if I can provide any additional information or help out debugging this in any way.

"supressWhileTypeErrorsPresent" not working.

I don't have any tslint extensions running.
I am on VSCode Stable Version 1.18.1
package.json:

{
    "devDependencies": {
        "tslint": "^5.8.0",
        "tslint-config-prettier": "^1.6.0",
        "tslint-language-service": "^0.9.6",
        "typescript": "^2.6.2",
        "worker-loader": "^1.1.0"
    }
}

[tslint] errors are still displayed even when there are [ts] errors above them.

Provide quick fix to open tslint.json and go at the rule

Provide quick fix to open tslint.json and go at the rule to give the capability to edit, remove the rule.

This codefix is hard to implement because:

* codefix update no content. In other words textChanges is empty.

{
	"description": "Open tslint.json",
	"changes": [
		{
			"fileName": "C:\\Users\\xxx\\tslint.json",
			"textChanges": []
		}
	]
}

It causes problem with VSCode which ignores codefix when textChanges is empty.

  • retrieve the location of the rule. It means that we need a JSON parser with location. I have experimented https://github.com/Microsoft/node-jsonc-parser which works well for that. But it seems TypeScript have implemented their own JSON parser (for tsconfig.json), it should be cool if TypeScript could provide an API to consume it.

  • store the location in the codefix. I have tried to store the rule location in the textChanges but tsserver try to convert location (from position to char/line) and the converstion fails because tsserver doesn't know the tslint.json.

  • store the location in the codefix with clean mean. Storing location in the textChanges is uggly. IMHO, I think codefix should be improved to support codefix which "Go at some location". CodeFix could looks like:

{
	"description": "Edit 'quotemark' rule from tslint.json",
	"definition": {
		"file": "C:\\Users\\xxx\\tslint.json",
		"start": {
			"line": 1,
			"offset": 12
		},
		"end": {
			"line": 1,
			"offset": 14
		}
	}
}

@egamma I have tried to explain challenges with Edit 'XXX' rule from tslint.json, please tell me if my explanation is not very good. We need to speak about this issue to TypeScript team, if you could do that, it should be very cool, thanks!

ter-indent rule bug inside interfaces

OS: MacOS 10.12.6
Editor: VSCode 1.15.1
Typescript: 2.4.2
tslint: 5.7.0
tslint-language-service: 0.9.6

I've encountered a bug with how tslint-language-service works with the ter-indent rule inside files with interfaces. Whenever I have an interface with multiple lines inside the definition, tslint-language-service is never happy with how the interface members are indented. For example, if I have:

interface JssContext {
  jss: Jss
  registry: SheetsRegistry
  manager: WeakMap<{}, any>
}

Then I get three errors: [tslint] Expected indentation of 4 spaces but found 2. (ter-indent)

If I change the code to:

interface JssContext {
    jss: Jss
    registry: SheetsRegistry
    manager: WeakMap<{}, any>
}

Then I get six errors:

  • [tslint] Expected indentation of 2 spaces but found 4. (ter-indent)
  • [tslint] Expected indentation of 6 spaces but found 4. (ter-indent)

(times three)

I found this relevant issue that was never solved: https://github.com/Microsoft/vscode-tslint/issues/230

Here is my tslint.json:

{
  "extends": [
    "tslint-config-standard",
    "tslint-react"
  ]
}

And my tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": "src",
    "outDir": "out",
    "module": "esnext",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "target": "esnext",
    "lib": ["esnext", "dom"],
    "jsx": "react-native",
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "experimentalDecorators": true,
    "plugins": [
      { "name": "tslint-language-service" }
    ]
  },
  "exclude": [
    "node_modules",
    "out",
    "**/*.test.ts",
    "**/*.test.js"
  ]
}

This is happening to me inside an interface. The error is NOT reported when I run tslint with:

./node_modules/.bin/tslint -p ./tsconfig.json -c ./tslint.json

However, the above command does report other rule violations from the config presets, such as unnecessary semicolons. The only place I ever get this issue is in Visual Studio Code, when using the tslint-language-service plugin in my tsconfig. I do not get this issue when using the VSCode tslint plugin without tslint-language-service.

Missing semicolon always row = 1 and col = 1

There is a problem with this particular rule, it always shows the error at [1:1], as you can see :

image

When I run manually tslint I get the correct value [4, 28] :

image

So it doesn't come from tslint. I tried with an other Language Client and I get the same result, so it's not the client fault. I think the problem is here. Any idea ?

Warning messages from tslint are lost

tslint writes warning messages like 'rule not found' to the console using console.warn(). These messages are lost. These messages should be captured and shown to the user.

Write more tests by consuming tsserver

We must really write more tests by consuming tsserver. No idea for the moment how to do that. TypeScript project contains a lot of tests which consumes tsserver API, perhaps we could do the same thing?

Incorrect no-shadow-variable failures when using mockTypeScriptVersion

With 0.9.9 released, I've finally got around to replacing my local workaround for #58 with the proper fix - turning on mockTypeScriptVersion.

Unfortunately this results in almost every variable being incorrectly flagged as failing the no-shadow-variable rule. That's ~58000 errors in the project I'm working on. This is something I didn't see when testing the original PR, so I'm not sure what's changed.

To reproduce:

  • Set up tslint-language-service in Visual Studio 2017 with TypeScript Tools for Microsoft Visual Studio installed
  • Make sure the typescript version in the project's node_modules is different to the one included in the VS TypeScript Tooling
  • Turn on the mockTypeScriptVersion option in the plugin
  • Open a TS file in VS

This should result in most variables (especially any imports or exports) being flagged as shadowing themselves.

It looks like this is caused by loading tslint twice (require then mockRequire.reRequire), though I'm not sure why this is the case.

quickFix broken in typescript 2.7.1

After updating to the version 2.7.1 of typescript, most of the times i don't have quickFix bulb and shortcut doesn't work.

As you can see in image - cursor is on the issue that can be fixed via quickFix, but there is no bulb.
image

In typescript outpul log there is an error

[Info  - 6:37:02 PM] Started TSServer
[Error  - 6:37:05 PM] 'getCodeFixes' request failed with error.
Error processing request. Debug Failure. False expression.
Error: Debug Failure. False expression.
    at getClass (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:77545:22)
    at c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:77533:46
    at Function.ChangeTracker.with (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:76425:17)
    at Object.getCodeActions (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:77532:64)
    at c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:77059:33
    at Object.forEach (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:1430:30)
    at Object.getFixes (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:77058:16)
    at c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:83206:35
    at Object.flatMap (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:1697:25)
    at Object.getCodeFixesAtPosition (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:83204:23)
    at Object.proxy.getCodeFixesAtPosition (c:\Users\s.kaptur\tslint-error\node_modules\tslint-language-service\out\src\index.js:334:31)
    at IOSession.Session.getCodeFixes (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:90228:64)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:89132:61)
    at c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:90393:88
    at IOSession.Session.executeWithRequestId (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:90384:28)
    at IOSession.Session.executeCommand (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:90393:33)
    at IOSession.Session.onMessage (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:90413:35)
    at Interface.<anonymous> (c:\Users\s.kaptur\tslint-error\node_modules\typescript\lib\tsserver.js:91614:27)
    at emitOne (events.js:96:13)
    at Interface.emit (events.js:191:7)
    at Interface._onLine (readline.js:241:10)
    at Interface._normalWrite (readline.js:384:12)
    at Socket.ondata (readline.js:101:10)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at Pipe.onread (net.js:560:20)

Repo where i reproduced it: https://github.com/arznaar/tls-error

Current versions:

  • typescript version - 2.7.1
  • tslint version - 5.9.1
  • tslint-language-service version - 0.9.8

May be helpful:

  • vscode version - 1.19.3
  • vscode typescript version - 2.6.2

UPD: I can still reproduce it after today's vscode update to versions:

  • vscode version - 1.20.0
  • vscode typescript version - 2.7.1

Dynamic import: unused expression

  • TSLint version: 5.5.0
  • TSLint language service: 0.9.6
  • TypeScript version: 2.4.1

TypeScript code being linted

if (process.env.NODE_ENV !== 'production') {
  import('my-dev-package');
}

with tslint.json configuration:

{
  "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"]
}

Actual behavior

In Visual Studio Code I get following error: [tslint] unused expression, expected an assignment or function call (no-unused-expression)

Strangely if I run tslint from the command line I don't get this error

Expected behavior

No error should be shown.

Some rules not working with VSCode? (e.g., semicolon)

Hi,

I have setup tslint-language-service properly in vscode, and I can see errors as expected but for some rules, it just doesn't seem to work…

For example, the semicolon rule is never triggered.

I'm not sure how to provide more details on this issue, if you know how I can gather more data, I can do it :)

Support TSLint warnings

It would be cool, if the language service supports both, errors and warnings.
The IDE/Editor which is using the language service could then decide how to handle them.

Contribution Guidelines

We should probably add a CONTRIBUTING.md file to the project. To explain some basic details on how new contributors can start doing stuff. This is intended to clarify doubts that new contributors may have and this way improving the chances of getting new contributors on board.

Gaps between tslint-language-service and vscode-tslint

  • Show the user tslint warnings like 'rule not found'.
    blocked - currently shown in the server log only, which is intended for plugin authors but not users, see microsoft/TypeScript#15913
  • The no-unused-variable-rule is disabled by default
    blocked - the rule has side effects and triggers an assertion failure palantir/tslint#2649. There is a fix for the side effect, that will be available in a next version. Even with the fix the rule requires to re-analyze a file for linting and it is too expensive to enable.
  • Auto fix on save
    blocked - the TypeScript language server has no notion of a pre save hook microsoft/TypeScript#15917
  • Automatically revalidate open files when the tslint.json configuration file changes.
    blocked - requires an API to trigger a revalidation of the open files microsoft/TypeScript#15914
  • Revalidate open files when the plugin settings inside the tsconfig.json changes.
    blocked - microsoft/TypeScript#15915

Settings

  • tslint.autoFixOnSave - fix auto fixable warnings when a file is saved.
    blocked see above
  • tslint.run - run the linter onSave or onType, default is onType.
    blocked - typescript always creates diagnostics as the user types

Commands contributed by vscode-tslint

from microsoft/vscode-ts-tslint#1:

  • tslint.fixAllProblems - which also enables to define a key binding, requires to send a event to a plugin.
  • tslint.createConfig - should be created using tslint --init
  • tslint.showOutputChannel - depends on TS support for channel specific logging from a plugin see above

Custom quick fixes

vscode-tslint provides some custom quick fixes. Rather than providing quick fixes the better approach is to make PRs against the tslint rules.

  • quotemark - quick fix has been added in tslint 5
  • triple-equals - no quick fix provided by tslint
  • comment-format - no quick fix provided by tslint
  • whitespace - no quick fix provided by tslint

Should be provided by tslint editor extension

  • Intellisense/validation for language service plugins contributions in the tsconfig.json
  • tslint status indicator
    the vscode typescript status indicator should show status/provide access to the status of extensions
  • tslint.json schema validation
  • support to create a default tslint.json

configFile is broken

First of all, I want to say thank you for this awesome plugin.

I noticed that configFile is broken for me because it assumes relative path to CWD which often is not a project root (you can ran vsc from terminal on different project but all windows share CWD).
You can't really use absolute paths either because they would be different for every machine.

I have already patched version running locally (man, debugging ts language services is crazy :D) it always uses a relative path from project root. PR incoming in a sec.

Make a preview of the tslint plugin available to VS Code users

This issue tracks what needs to be done before we can announce an early preview for VS Code users.

  • Document the setup for VS Code (e.g. disable vscode-tslint, npm install the plugin and the desired tslint version)
  • Plugin must work with both tslint 4 and tslint 5 (I don't think early adopters are still using tslint3 but it would better to support all versions).
  • Plugin must work with TS 2.3.1.

Blocking issues:

  • microsoft/TypeScript#15237 TSServer Protocol.d.ts Diagnostic Interface Does Not have a Category Field
    will be in 2.3.1
  • microsoft/TypeScript#15224 Support to distinguish diagnostics from TS from the diagnostics from a language server plugin
    will be in 2.3.1
  • Open tslint.json quick fix doesn't work in VS Code (works in Eclipse). removed the code action for now

VSCode not recognizing tslint-language-service

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.

vscode fixes and tips

When using the vscode tslint plugin, I am presented with a "lightbulb" icon of tips for fixing the lint issues or disabling them. When running without the tslint plugin and just the language service I do not see a tip icon. Is this something that can be added or does it require a plugin to vscode to work?

For TypeScript 2.9, TSLint service should provide the way to ignore error in JSON module

In TypeScript 2.9, external module can reference to other JSON module. TSLint language service should allow us to ignore JSON files just like TypeScript definition files. I try to exclude JSON file in tslint/typescript config. But it doesn't work.

The following code can fix this issue on VS2017.
fig.ignoreDefinitionFiles === true && fileName.endsWith('.json')) { return prior; }

Release

@Istar-Eldritch I would like to do a release. Are you OK?

Is it working for you without tsserver-plugin?

TSLint LS changes the original diagnostics array

Hi. There is a problem with the code:
https://github.com/angelozerr/tslint-language-service/blob/master/src/index.ts#L304

It uses the original diagnostics object from the parent LS (doesn't copy it).
The parent LS caches the object so every time when I call getSemanticDiagnostics (and the file wasn't changed so the parent LS can use the cache) it adds more and more tslint errors.

There is no way to reproduce the error in VSCode because it doesn't call getSemanticDiagnosticsSync.

we can fix the problem by adding this code:

if (prior === undefined) {
   prior = [];
} else {
   prior = prior.slice();
}

I guess you can also use a cache as the parent LS does it.

Unmet peerdep warning

Hi there! I was attempting to use this plugin with TS 2.3.0 but got a UNMET PEER DEPENDENCY error.

├── [email protected]
└── UNMET PEER DEPENDENCY [email protected]

npm WARN [email protected] requires a peer of [email protected] but none was installed.

Since TS 2.3.0 is out now, would it be possible to bump the peerDep for typescript?

https://github.com/angelozerr/tslint-language-service/blob/master/package.json#L26

Things still install correctly, but it would be nice to not get a warning, which could scare people off.

Either way, this plugin is great, and works perfectly with my typescript service for neovim. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.