Коммит
f4e06b17d0
|
@ -4,21 +4,22 @@
|
|||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Mocha Tests",
|
||||
"program": "${workspaceFolder}/tslint-runner/node_modules/mocha/bin/_mocha",
|
||||
"args": [
|
||||
"-u",
|
||||
"tdd",
|
||||
"--timeout",
|
||||
"999999",
|
||||
"--colors",
|
||||
"${workspaceFolder}/tslint-runner/out/test",
|
||||
"-g", "getNonOverlappingReplacements"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Mocha Tests",
|
||||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||
"args": [
|
||||
"-u",
|
||||
"tdd",
|
||||
"--timeout",
|
||||
"999999",
|
||||
"--colors",
|
||||
"${workspaceFolder}/out/runner/test",
|
||||
// "-g",
|
||||
// "exclude"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -126,6 +126,7 @@ export class TSLintPlugin {
|
|||
configFile: config.configFile,
|
||||
ignoreDefinitionFiles: config.ignoreDefinitionFiles,
|
||||
jsEnable: config.jsEnable,
|
||||
exclude: config.exclude,
|
||||
});
|
||||
if (result.configFilePath) {
|
||||
this.configFileWatcher.ensureWatching(result.configFilePath);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as cp from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as minimatch from 'minimatch';
|
||||
import { dirname, delimiter } from 'path';
|
||||
import { dirname, delimiter, relative } from 'path';
|
||||
import * as tslint from 'tslint'; // this is a dev dependency only
|
||||
import * as typescript from 'typescript'; // this is a dev dependency only
|
||||
import * as util from 'util';
|
||||
|
@ -208,14 +208,19 @@ export class TsLintRunner {
|
|||
this.trace('start doValidate ' + filePath);
|
||||
const uri = filePath;
|
||||
|
||||
if (this.fileIsExcluded(configuration, filePath)) {
|
||||
let cwd = configuration.workspaceFolderPath;
|
||||
if (!cwd && typeof contents === "object") {
|
||||
cwd = contents.getCurrentDirectory();
|
||||
}
|
||||
|
||||
if (this.fileIsExcluded(configuration, filePath, cwd)) {
|
||||
this.trace(`No linting: file ${filePath} is excluded`);
|
||||
return emptyResult;
|
||||
}
|
||||
|
||||
if (configuration.workspaceFolderPath) {
|
||||
this.trace(`Changed directory to ${configuration.workspaceFolderPath}`);
|
||||
process.chdir(configuration.workspaceFolderPath);
|
||||
if (cwd) {
|
||||
this.trace(`Changed directory to ${cwd}`);
|
||||
process.chdir(cwd);
|
||||
}
|
||||
|
||||
const configFile = configuration.configFile || null;
|
||||
|
@ -338,7 +343,7 @@ export class TsLintRunner {
|
|||
return this.configCache.configuration;
|
||||
}
|
||||
|
||||
private fileIsExcluded(settings: RunConfiguration, filePath: string): boolean {
|
||||
private fileIsExcluded(settings: RunConfiguration, filePath: string, cwd: string | undefined): boolean {
|
||||
if (settings.ignoreDefinitionFiles) {
|
||||
if (filePath.endsWith('.d.ts')) {
|
||||
return true;
|
||||
|
@ -348,11 +353,11 @@ export class TsLintRunner {
|
|||
if (settings.exclude) {
|
||||
if (Array.isArray(settings.exclude)) {
|
||||
for (const pattern of settings.exclude) {
|
||||
if (testForExclusionPattern(filePath, pattern)) {
|
||||
if (testForExclusionPattern(filePath, pattern, cwd)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (testForExclusionPattern(filePath, settings.exclude)) {
|
||||
} else if (testForExclusionPattern(filePath, settings.exclude, cwd)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +395,18 @@ export class TsLintRunner {
|
|||
}
|
||||
}
|
||||
|
||||
function testForExclusionPattern(filePath: string, pattern: string): boolean {
|
||||
function testForExclusionPattern(filePath: string, pattern: string, cwd: string | undefined): boolean {
|
||||
if (cwd) {
|
||||
// try first as relative
|
||||
const relPath = relative(cwd, filePath);
|
||||
if (minimatch(relPath, pattern, { dot: true })) {
|
||||
return true;
|
||||
}
|
||||
if (relPath === filePath) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return minimatch(filePath, pattern, { dot: true });
|
||||
}
|
||||
|
||||
|
@ -433,7 +449,7 @@ function isExcludedFromLinterOptions(
|
|||
if (config === undefined || config.linterOptions === undefined || config.linterOptions.exclude === undefined) {
|
||||
return false;
|
||||
}
|
||||
return config.linterOptions.exclude.some(pattern => testForExclusionPattern(fileName, pattern));
|
||||
return config.linterOptions.exclude.some(pattern => testForExclusionPattern(fileName, pattern, undefined));
|
||||
}
|
||||
|
||||
function getConfigurationFailureMessage(err: any): string {
|
||||
|
|
|
@ -67,7 +67,7 @@ describe('TSLintRunner', () => {
|
|||
expect(errorResult.lintResult.warningCount).to.equal(0);
|
||||
});
|
||||
|
||||
it('should not return any errors for excluded file', () => {
|
||||
it('should not return any errors for excluded file (absolute path)', () => {
|
||||
const filePath = path.join(testDataRoot, 'with-tslint', 'test.ts');
|
||||
const result = createTsLintRunner().runTsLint(filePath, fs.readFileSync(filePath).toString(), {
|
||||
exclude: [filePath],
|
||||
|
@ -76,6 +76,17 @@ describe('TSLintRunner', () => {
|
|||
expect(result.lintResult.errorCount).to.equal(0);
|
||||
});
|
||||
|
||||
it('should not return any errors for excluded file (relative path)', () => {
|
||||
const root = path.join(testDataRoot, 'with-tslint');
|
||||
const filePath = path.join(root, 'test.ts');
|
||||
const result = createTsLintRunner().runTsLint(filePath, fs.readFileSync(filePath).toString(), {
|
||||
workspaceFolderPath: root,
|
||||
exclude: ['test.ts'],
|
||||
} as RunConfiguration);
|
||||
|
||||
expect(result.lintResult.errorCount).to.equal(0);
|
||||
});
|
||||
|
||||
it('should set working directory to workspace path', () => {
|
||||
const workspacePath = path.join(testDataRoot, 'with-tslint');
|
||||
const filePath = path.join(workspacePath, 'test.ts');
|
||||
|
|
|
@ -12,6 +12,7 @@ export interface Configuration {
|
|||
readonly configFile?: string;
|
||||
readonly suppressWhileTypeErrorsPresent?: boolean;
|
||||
readonly jsEnable?: boolean;
|
||||
readonly exclude?: string | string[];
|
||||
}
|
||||
|
||||
export class ConfigurationManager {
|
||||
|
|
Загрузка…
Ссылка в новой задаче