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

Add jsEnable option #154

Merged
merged 2 commits into from
Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tslint-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Delayer } from './delayer';
interface Settings {
tslint: {
enable: boolean;
jsEnable: boolean;
rulesDirectory: string | string[];
configFile: string;
ignoreDefinitionFiles: boolean;
Expand Down Expand Up @@ -442,6 +443,11 @@ function doValidate(conn: server.IConnection, document: server.TextDocument): se
return diagnostics;
}

if (settings && settings.tslint && !settings.tslint.jsEnable &&
(document.languageId === "javascript" || document.languageId === "javascriptreact")) {
return diagnostics;
}

if (settings && settings.tslint && settings.tslint.validateWithDefaultConfig === false && configCache.isDefaultConfig) {
return diagnostics;
}
Expand Down
1 change: 1 addition & 0 deletions tslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ then try to install tslint and its typescript dependency globally using `npm ins
# Configuration options

- `tslint.enable` - enable/disable tslint.
- `tslint.jsEnable` - enable/disable tslint for .js files.
- `tslint.run` - run the linter `onSave` or `onType`, default is `onType`.
- `tslint.rulesDirectory` - an additional rules directory, for user-created rules.
- `tslint.configFile` - the configuration file that tslint should use instead of the default `tslint.json`.
Expand Down
20 changes: 16 additions & 4 deletions tslint/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,19 @@ export function activate(context: ExtensionContext) {
}

function isTypeScriptDocument(languageId) {
return languageId === 'typescript' || languageId === 'typescriptreact' ||
languageId === 'javascript' || languageId === 'javascriptreact';
return languageId === 'typescript' || languageId === 'typescriptreact';
}

function isJavaScriptDocument(languageId) {
return languageId === 'javascript' || languageId === 'javascriptreact';
}

function isEnableForJavaScriptDocument(languageId) {
let isJsEnable = workspace.getConfiguration('tslint').get('jsEnable', true);
if (isJsEnable && isJavaScriptDocument(languageId)) {
return true;
}
return false;
}

function udpateStatusBarVisibility(editor: TextEditor): void {
Expand All @@ -108,7 +119,7 @@ export function activate(context: ExtensionContext) {
serverRunning &&
(
tslintStatus !== Status.ok ||
(editor && (isTypeScriptDocument(editor.document.languageId)))
(editor && (isTypeScriptDocument(editor.document.languageId) || isEnableForJavaScriptDocument(editor.document.languageId)))
)
);
}
Expand Down Expand Up @@ -282,7 +293,8 @@ export function activate(context: ExtensionContext) {
willSaveTextDocument = workspace.onWillSaveTextDocument((event) => {
let document = event.document;
// only auto fix when the document was not auto saved
if (!isTypeScriptDocument(document.languageId) || event.reason === TextDocumentSaveReason.AfterDelay) {
if (!(isTypeScriptDocument(document.languageId) || isEnableForJavaScriptDocument(document.languageId))
|| event.reason === TextDocumentSaveReason.AfterDelay) {
return;
}
const version = document.version;
Expand Down
5 changes: 5 additions & 0 deletions tslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
"default": true,
"description": "Control whether tslint is enabled for TypeScript files or not."
},
"tslint.jsEnable": {
"type": "boolean",
"default": true,
"description": "Control whether tslint is enabled for JavaScript files or not."
},
"tslint.rulesDirectory": {
"type": [
"string",
Expand Down