Perform the tslint checks in the context of a program to enable checks which require type information

This commit is contained in:
Erich Gamma 2018-02-02 16:11:16 +01:00
parent c51cdbdf8f
commit c7b7ace3d4
4 changed files with 32 additions and 25 deletions

View file

@ -225,23 +225,14 @@ const hygiene = exports.hygiene = (some, options) => {
});
}
const program = tslint.Linter.createProgram("src/tsconfig.json");
const configuration = tslint.Configuration.findConfiguration('tslint.json', '.');
const tslintOptions = { formatter: 'json', rulesDirectory: 'build/lib/tslint' };
const linter = new tslint.Linter(tslintOptions, program);
const tsl = es.through(function (file) {
const configuration = tslint.Configuration.findConfiguration(null, '.');
const program = tslint.Linter.createProgram("tsconfig.json", "src/");
const options = { formatter: 'json', rulesDirectory: 'build/lib/tslint' };
const contents = file.contents.toString('utf8');
const linter = new tslint.Linter(options, program);
if (file.relative.startsWith('src')) {
linter.lint(file.relative, contents, configuration.results);
const result = linter.getResult();
if (result.failures.length > 0) {
reportFailures(result.failures);
errorCount += result.failures.length;
}
}
linter.lint(file.relative, contents, configuration.results);
this.emit('data', file);
});
@ -275,6 +266,13 @@ const hygiene = exports.hygiene = (some, options) => {
this.emit('data', data);
}, function () {
process.stdout.write('\n');
const tslintResult = linter.getResult();
if (tslintResult.failures.length > 0) {
reportFailures(tslintResult.failures);
errorCount += tslintResult.failures.length;
}
if (errorCount > 0) {
this.emit('error', 'Hygiene failed with ' + errorCount + ' errors. Check \'build/gulpfile.hygiene.js\'.');
} else {

View file

@ -108,7 +108,7 @@
"rimraf": "^2.2.8",
"sinon": "^1.17.2",
"source-map": "^0.4.4",
"tslint": "^5.8.0",
"tslint": "^5.9.1",
"typescript": "2.6.1",
"typescript-formatter": "4.0.1",
"uglify-es": "^3.0.18",

View file

@ -6,7 +6,7 @@
"no-string-throw": true,
"no-unused-expression": true,
"no-duplicate-variable": true,
"no-unused-variable": true, // requires type information in tslint > v4
"no-unused-variable": true, // requires type information in tslint > v4 only works for hyiene tasks
"curly": true,
"class-name": true,
"semicolon": [

View file

@ -569,7 +569,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"
chalk@^2.1.0:
chalk@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba"
dependencies:
@ -770,6 +770,10 @@ commander@2.8.x:
dependencies:
graceful-readlink ">= 1.0.0"
commander@^2.12.1:
version "2.13.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"
commandpost@^1.0.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/commandpost/-/commandpost-1.2.1.tgz#2e9c4c7508b9dc704afefaa91cab92ee6054cc68"
@ -3070,7 +3074,7 @@ js-yaml@3.6.1:
argparse "^1.0.7"
esprima "^2.6.0"
js-yaml@3.x, js-yaml@^3.5.1:
js-yaml@3.x, js-yaml@^3.5.1, js-yaml@^3.7.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc"
dependencies:
@ -5485,20 +5489,25 @@ tslib@^1.7.1:
version "1.8.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.8.0.tgz#dc604ebad64bcbf696d613da6c954aa0e7ea1eb6"
tslint@^5.8.0:
version "5.8.0"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.8.0.tgz#1f49ad5b2e77c76c3af4ddcae552ae4e3612eb13"
tslib@^1.8.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
tslint@^5.9.1:
version "5.9.1"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.9.1.tgz#1255f87a3ff57eb0b0e1f0e610a8b4748046c9ae"
dependencies:
babel-code-frame "^6.22.0"
builtin-modules "^1.1.1"
chalk "^2.1.0"
commander "^2.9.0"
chalk "^2.3.0"
commander "^2.12.1"
diff "^3.2.0"
glob "^7.1.1"
js-yaml "^3.7.0"
minimatch "^3.0.4"
resolve "^1.3.2"
semver "^5.3.0"
tslib "^1.7.1"
tslib "^1.8.0"
tsutils "^2.12.1"
tsutils@^2.12.1: