Skip to content

Commit

Permalink
Determine configuration separately for each source file
Browse files Browse the repository at this point in the history
Add tests for the above change.
  • Loading branch information
Charles Cook committed Jul 16, 2017
1 parent e8a25e3 commit 3192ee0
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 13 deletions.
12 changes: 6 additions & 6 deletions index.js
Expand Up @@ -94,14 +94,14 @@ var tslintPlugin = function (pluginOptions) {
if (file.isStream()) {
return cb(new PluginError("gulp-tslint", "Streaming not supported"));
}
if (pluginOptions.configuration === null ||
var configuration = (pluginOptions.configuration === null ||
pluginOptions.configuration === undefined ||
isString(pluginOptions.configuration)) {
// Configuration can be a file path or null, if it's unknown
pluginOptions.configuration = linter.Configuration.findConfiguration(pluginOptions.configuration || null, file.path).results;
}
tslint.lint(file.path, file.contents.toString("utf8"), pluginOptions.configuration);
isString(pluginOptions.configuration))
? linter.Configuration.findConfiguration(pluginOptions.configuration || null, file.path).results
: pluginOptions.configuration;
tslint.lint(file.path, file.contents.toString("utf8"), configuration);
file.tslint = tslint.getResult();
// Clear all results for current file from tslint
tslint.failures = [];
tslint.fixes = [];
// Pass file
Expand Down
13 changes: 6 additions & 7 deletions index.ts
Expand Up @@ -148,18 +148,17 @@ const tslintPlugin = <TslintPlugin> function(pluginOptions?: PluginOptions) {
return cb(new PluginError("gulp-tslint", "Streaming not supported"));
}

if (pluginOptions.configuration === null ||
const configuration = (pluginOptions.configuration === null ||
pluginOptions.configuration === undefined ||
isString(pluginOptions.configuration)) {

isString(pluginOptions.configuration))
// Configuration can be a file path or null, if it's unknown
pluginOptions.configuration = linter.Configuration.findConfiguration(
? linter.Configuration.findConfiguration(
pluginOptions.configuration || null,
file.path
).results;
}
).results
: pluginOptions.configuration;

tslint.lint(file.path, file.contents.toString("utf8"), pluginOptions.configuration);
tslint.lint(file.path, file.contents.toString("utf8"), configuration);
file.tslint = tslint.getResult();

// Clear all results for current file from tslint
Expand Down
45 changes: 45 additions & 0 deletions test/gulpfile.js
Expand Up @@ -444,3 +444,48 @@ gulp.task("warnings-and-errors", function() {
}))
.pipe(tslint.report());
});

// Should report triple-equals error for override/source.ts
//
// Should ignore triple-equals rule for override/suboverride1/subsource.ts
// (because of override in override/suboverride1/tslint.json)
//
// Should report semicolon error for override/suboverride1/subsource1.ts
// (from the semicolon rule in override/tslint.json via the extends in
// override/suboverride/tslint.json)
//
// Should ignore semicolon error for override/suboverride2/subsource2.ts
// (because no extends in override/suboverride2/tslint.json)
gulp.task("override", function() {
return gulp.src([
"override/source.ts",
"override/suboverride1/subsource1.ts",
"override/suboverride2/subsource2.ts",
])
.pipe(tslint({
formatter: "prose"
}))
.pipe(tslint.report());
});

// Should report triple-equals error for override/source.ts
//
// Should report triple-equals error for override/suboverride1/subsource.ts
// (ignoring override in tslint.json in override/suboverride1 because of
// the config file path provided in the options configuration property)
//
// Should report semicolon error for override/suboverride1/subsource1.ts
//
// Should report semicolon error for override/suboverride2/subsource2.ts
gulp.task("no-override", function() {
return gulp.src([
"override/source.ts",
"override/suboverride1/subsource1.ts",
"override/suboverride2/subsource2.ts",
])
.pipe(tslint({
configuration: "tslint.json",
formatter: "prose"
}))
.pipe(tslint.report());
});
1 change: 1 addition & 0 deletions test/override/source.ts
@@ -0,0 +1 @@
const b = (10 == 10);
1 change: 1 addition & 0 deletions test/override/suboverride1/subsource1.ts
@@ -0,0 +1 @@
const b = (10 == 10)
6 changes: 6 additions & 0 deletions test/override/suboverride1/tslint.json
@@ -0,0 +1,6 @@
{
"extends": "../../tslint.json",
"rules": {
"triple-equals": [false, "allow-null-check"]
}
}
1 change: 1 addition & 0 deletions test/override/suboverride2/subsource2.ts
@@ -0,0 +1 @@
const b = (10 === 10)
5 changes: 5 additions & 0 deletions test/override/suboverride2/tslint.json
@@ -0,0 +1,5 @@
{
"rules": {
"triple-equals": [false, "allow-null-check"]
}
}

0 comments on commit 3192ee0

Please sign in to comment.