Report warnings in diagnostics when we find a tslint config file but encounte an error during actual linting
This commit is contained in:
Родитель
ebeeac10f9
Коммит
9dde9c7ce9
|
@ -1,4 +1,5 @@
|
|||
import * as tslint from 'tslint';
|
||||
import * as path from 'path';
|
||||
import * as ts_module from 'typescript/lib/tsserverlibrary';
|
||||
import { TSLINT_ERROR_CODE, TSLINT_ERROR_SOURCE } from './config';
|
||||
import { ConfigFileWatcher } from './configFileWatcher';
|
||||
|
@ -160,10 +161,31 @@ export class TSLintPlugin {
|
|||
return diagnostics;
|
||||
}
|
||||
|
||||
const file = this.getProgram().getSourceFile(fileName)!;
|
||||
|
||||
for (const warning of result.warnings) {
|
||||
this.logger.info(`[tslint] ${warning}`);
|
||||
const program = this.getProgram();
|
||||
const file = program.getSourceFile(fileName)!;
|
||||
if (result.warnings) {
|
||||
const defaultTsconfigJsonPath = path.join(program.getCurrentDirectory(), 'tslint.json');
|
||||
if ((result.configFilePath && this.ts.sys.fileExists(result.configFilePath)) || this.ts.sys.fileExists(defaultTsconfigJsonPath)) {
|
||||
// If we have a config file, the user likely wanted to lint. The fact that linting has a
|
||||
// warning should be reported to them.
|
||||
for (const warning of result.warnings) {
|
||||
diagnostics.unshift({
|
||||
file,
|
||||
start: 0,
|
||||
length: 1,
|
||||
category: this.ts.DiagnosticCategory.Warning,
|
||||
code: TSLINT_ERROR_CODE,
|
||||
messageText: warning,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// If we have not found a config file, then we don't want to annoy users by generating warnings
|
||||
// about tslint not being installed or misconfigured. In many cases, the user is opening a
|
||||
// file/project that was not intended to be linted.
|
||||
for (const warning of result.warnings) {
|
||||
this.logger.info(`[tslint] ${warning}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const tslintProblems = filterProblemsForFile(fileName, result.lintResult.failures);
|
||||
|
@ -332,7 +354,6 @@ export class TSLintPlugin {
|
|||
: `${failure.getFailure()}`;
|
||||
|
||||
const category = this.getDiagnosticCategory(failure);
|
||||
|
||||
return {
|
||||
file,
|
||||
start: failure.getStartPosition().getPosition(),
|
||||
|
|
|
@ -113,7 +113,6 @@ export class TsLintRunner {
|
|||
warnings: [
|
||||
getInstallFailureMessage(
|
||||
filePath,
|
||||
configuration.workspaceFolderPath,
|
||||
configuration.packageManager || 'npm'),
|
||||
],
|
||||
};
|
||||
|
@ -392,7 +391,7 @@ function testForExclusionPattern(filePath: string, pattern: string, cwd: string
|
|||
return minimatch(filePath, pattern, { dot: true });
|
||||
}
|
||||
|
||||
function getInstallFailureMessage(filePath: string, workspaceFolder: string | undefined, packageManager: 'npm' | 'yarn'): string {
|
||||
function getInstallFailureMessage(filePath: string, packageManager: 'npm' | 'yarn'): string {
|
||||
const localCommands = {
|
||||
npm: 'npm install tslint',
|
||||
yarn: 'yarn add tslint',
|
||||
|
@ -401,23 +400,12 @@ function getInstallFailureMessage(filePath: string, workspaceFolder: string | un
|
|||
npm: 'npm install -g tslint',
|
||||
yarn: 'yarn global add tslint',
|
||||
};
|
||||
if (workspaceFolder) { // workspace opened on a folder
|
||||
return [
|
||||
'',
|
||||
`Failed to load the TSLint library for the document ${filePath}`,
|
||||
'',
|
||||
`To use TSLint in this workspace please install tslint using \'${localCommands[packageManager]}\' or globally using \'${globalCommands[packageManager]}\'.`,
|
||||
'TSLint has a peer dependency on `typescript`, make sure that `typescript` is installed as well.',
|
||||
'You need to reopen the workspace after installing tslint.',
|
||||
].join('\n');
|
||||
} else {
|
||||
return [
|
||||
`Failed to load the TSLint library for the document ${filePath}`,
|
||||
`To use TSLint for single file install tslint globally using \'${globalCommands[packageManager]}\'.`,
|
||||
'TSLint has a peer dependency on `typescript`, make sure that `typescript` is installed as well.',
|
||||
'You need to reopen VS Code after installing tslint.',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
return [
|
||||
`Failed to load the TSLint library for '${filePath}'`,
|
||||
`To use TSLint, please install tslint using \'${localCommands[packageManager]}\' or globally using \'${globalCommands[packageManager]}\'.`,
|
||||
'Be sure to restart your editor after installing tslint.',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function isJsDocument(filePath: string) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче