Skip to content

Commit 6257e9b

Browse files
committed
clean-up tslint.json used in the project
1 parent 48f6599 commit 6257e9b

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

tslint-server/src/server.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as fs from 'fs';
1010
import * as path from 'path';
1111
import * as semver from 'semver';
1212
import Uri from 'vscode-uri';
13+
import * as util from 'util';
1314

1415
import * as tslint from 'tslint'; // this is a dev dependency only
1516

@@ -25,15 +26,16 @@ interface Settings {
2526
ignoreDefinitionFiles: boolean;
2627
exclude: string | string[];
2728
validateWithDefaultConfig: boolean;
28-
nodePath: string | undefined,
29+
nodePath: string | undefined;
2930
run: 'onSave' | 'onType';
30-
alwaysShowRuleFailuresAsWarnings: boolean,
31-
autoFixOnSave: boolean | string[]
31+
alwaysShowRuleFailuresAsWarnings: boolean;
32+
autoFixOnSave: boolean | string[];
33+
trace: any;
3234
}
3335

3436
interface Configuration {
35-
linterConfiguration: any;
36-
isDefaultLinterConfig: boolean
37+
linterConfiguration: tslint.Configuration.IConfigurationFile | undefined;
38+
isDefaultLinterConfig: boolean;
3739
}
3840

3941
class ConfigCache {
@@ -47,7 +49,7 @@ class ConfigCache {
4749

4850
set(path: string, configuration:Configuration) {
4951
this.filePath = path;
50-
this.configuration = configuration
52+
this.configuration = configuration;
5153
}
5254

5355
get(forPath:string): Configuration | undefined {
@@ -61,7 +63,7 @@ class ConfigCache {
6163
if (this.configuration) {
6264
return this.configuration.isDefaultLinterConfig;
6365
}
64-
return false
66+
return false;
6567
}
6668

6769
flush() {
@@ -76,7 +78,7 @@ class SettingsCache {
7678

7779
constructor() {
7880
this.uri = undefined;
79-
this.settings = undefined
81+
this.settings = undefined;
8082
}
8183

8284
async get(uri:string): Promise<Settings | undefined> {
@@ -87,6 +89,7 @@ class SettingsCache {
8789
let configRequestParam = { items: [{ scopeUri: uri, section: 'tslint' }] };
8890
let settings = await connection.sendRequest(ConfigurationRequest.type, configRequestParam);
8991
this.settings = settings[0];
92+
this.uri = uri;
9093
return this.settings;
9194
}
9295
return globalSettings;
@@ -253,7 +256,7 @@ async function getConfiguration(uri: string, filePath: string, library: any, con
253256
}
254257

255258
let isDefaultConfig = false;
256-
let linterConfiguration: any;
259+
let linterConfiguration: tslint.Configuration.IConfigurationFile | undefined;
257260

258261
let linter = getLinterFromLibrary(library);
259262
if (isTsLintVersion4(library)) {
@@ -273,13 +276,13 @@ async function getConfiguration(uri: string, filePath: string, library: any, con
273276
if (linter.findConfigurationPath) {
274277
isDefaultConfig = linter.findConfigurationPath(configFileName, filePath) === undefined;
275278
}
276-
linterConfiguration = linter.findConfiguration(configFileName, filePath);
279+
linterConfiguration = <tslint.Configuration.IConfigurationFile>linter.findConfiguration(configFileName, filePath);
277280
}
278281

279282
let configuration: Configuration = {
280283
isDefaultLinterConfig: isDefaultConfig,
281-
linterConfiguration: linterConfiguration
282-
}
284+
linterConfiguration: linterConfiguration,
285+
};
283286

284287
configCache.set(filePath, configuration);
285288
return configCache.configuration;
@@ -326,7 +329,7 @@ function getLinterFromLibrary(library): typeof tslint.Linter {
326329
if (!isTsLint4) {
327330
linter = library;
328331
} else {
329-
linter = library.Linter
332+
linter = library.Linter;
330333
}
331334
return linter;
332335
}
@@ -489,6 +492,10 @@ async function doValidate(conn: server.IConnection, library: any, document: serv
489492
formattersDirectory: undefined
490493
};
491494

495+
if (settings.trace && settings.trace.server === 'verbose') {
496+
traceConfigurationFile(configuration.linterConfiguration);
497+
}
498+
492499
try { // protect against tslint crashes
493500
let linter = getLinterFromLibrary(library);
494501
if (isTsLintVersion4(library)) {
@@ -923,4 +930,12 @@ function concatenateEdits(fixes: AutoFix[]): server.TextEdit[] {
923930
return textEdits;
924931
}
925932

933+
function traceConfigurationFile(configuration: tslint.Configuration.IConfigurationFile | undefined) {
934+
if (!configuration) {
935+
trace("no tslint configuration");
936+
return;
937+
}
938+
trace("tslint configuration:", util.inspect(configuration, undefined, 4));
939+
}
940+
926941
connection.listen();

tslint-tests/.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// ],
77
"tslint.autoFixOnSave": false,
88
// "tslint.nodePath": "c:\\tmp",
9-
"tslint.jsEnable": true
9+
"tslint.jsEnable": true,
1010
//"tslint.enable": true
11-
// "tslint.trace.server": "verbose"
11+
"tslint.trace.server": "verbose"
1212
// "tslint.alwaysShowRuleFailuresAsWarnings": false
1313
}

tslint.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"rules": {
33
"no-unused-expression": true,
44
"no-duplicate-variable": true,
5-
"no-duplicate-key": true,
65
"no-unused-variable": true,
76
"curly": true,
87
"class-name": true,
9-
"semicolon": ["always"],
8+
"semicolon": true,
109
"triple-equals": true
11-
}
10+
},
11+
"defaultSeverity": "warning"
1212
}

tslint/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ Integrates the [tslint](https://github.com/palantir/tslint) linter for the TypeS
44
Please refer to the tslint [documentation](https://github.com/palantir/tslint) for how to configure the linting rules.
55

66
# Prerequisites
7-
The extension requires that tslint is installed either locally or globally.
7+
The extension requires that the `tslint` and `typescript` modules are installed either locally or globally. The extension will use the tslint module that is installed closest to the linted file. To install tslint and typescript globally you can run `npm install -g tslint typescript`.
88

9-
>Tip: if you get an error saying, "failed to load tslint", but you have tslint installed locally,
10-
try to install tslint and its typescript dependency globally using `npm install -g tslint typescript`.
9+
# FAQ
10+
11+
- The `no-unused-variable` rule doesn't report warnings any more?
12+
13+
Since tslint version 5 the rule [no-unused-variable](https://palantir.github.io/tslint/rules/no-unused-variable/) rule requires type information. Rules with type information are currently not supported by vscode-tslint, pls see [issue #70](https://github.com/Microsoft/vscode-tslint/issues/70#issuecomment-241041929). The recommended work around is to enable the TypeScript compiler option `noUnusedLocals` and `noUnusedParameters`in your `tsconfig.json` file.
14+
15+
- How can I use tslint rules that require type information
16+
17+
The recommended way is to run tslint manually on your project from a [task](https://code.visualstudio.com/docs/editor/tasks). To see the lint warnings in the Problems panel you can associate the task with a [Problem matcher](https://code.visualstudio.com/docs/editor/tasks#_processing-task-output-with-problem-matchers) as described in the section [below](#Using-the-extension-with-tasks-running-tslint).
18+
19+
- Linting does not seem to work what can I do?
20+
21+
Click on the `TSlint` status bar item at the bottom left of the status bar to see the output from the vscode-tslint extension.
22+
You can enable more tracing output by adding the setting "tslint.trace.server" with a value of "verbose" or "messages".
1123

1224
# Configuration options
1325

tslint/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface AllFixesParams {
1717
interface AllFixesResult {
1818
readonly documentVersion: number;
1919
readonly edits: TextEdit[];
20-
readonly ruleId?: string
20+
readonly ruleId?: string;
2121
}
2222

2323
namespace AllFixesRequest {
@@ -280,7 +280,7 @@ export function activate(context: ExtensionContext) {
280280
return;
281281
}
282282
let folderPicks = folders.map(each => {
283-
return {label: each.name, description: each.uri.fsPath}
283+
return {label: each.name, description: each.uri.fsPath};
284284
});
285285
let selection;
286286
if (folderPicks.length === 1) {

tslint/package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,18 @@
126126
"default": false,
127127
"description": "Always show rule failures as warnings, independent of the tslint configuration.",
128128
"scope": "resource"
129-
}
129+
},
130+
"tslint.trace.server": {
131+
"scope": "window",
132+
"type": "string",
133+
"enum": [
134+
"off",
135+
"messages",
136+
"verbose"
137+
],
138+
"default": "off",
139+
"description": "Traces the communication between VSCode and the tslint linter service."
140+
}
130141
}
131142
},
132143
"colors": [

0 commit comments

Comments
 (0)