gulp-tslint = function (pluginOptions) {
var loader;
var tslint;
// If user options are undefined, set an empty options object
if (!pluginOptions) {
pluginOptions = {};
}
return map(function (file, cb) {
// Skip
if (file.isNull()) {
return cb(null, file);
}
// Stream is not supported
if (file.isStream()) {
return cb(new PluginError("gulp-tslint", "Streaming not supported"));
}
// TSLint default options
var options = {
fix: pluginOptions.fix || false,
formatter: pluginOptions.formatter || "prose",
formattersDirectory: pluginOptions.formattersDirectory || null,
rulesDirectory: pluginOptions.rulesDirectory || null
};
var linter = getTslint(pluginOptions);
if (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 = new linter.Linter(options, pluginOptions.program);
tslint.lint(file.path, file.contents.toString("utf8"), pluginOptions.configuration);
file.tslint = tslint.getResult();
// Pass file
cb(null, file);
});
}n/a
default = function (pluginOptions) {
var loader;
var tslint;
// If user options are undefined, set an empty options object
if (!pluginOptions) {
pluginOptions = {};
}
return map(function (file, cb) {
// Skip
if (file.isNull()) {
return cb(null, file);
}
// Stream is not supported
if (file.isStream()) {
return cb(new PluginError("gulp-tslint", "Streaming not supported"));
}
// TSLint default options
var options = {
fix: pluginOptions.fix || false,
formatter: pluginOptions.formatter || "prose",
formattersDirectory: pluginOptions.formattersDirectory || null,
rulesDirectory: pluginOptions.rulesDirectory || null
};
var linter = getTslint(pluginOptions);
if (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 = new linter.Linter(options, pluginOptions.program);
tslint.lint(file.path, file.contents.toString("utf8"), pluginOptions.configuration);
file.tslint = tslint.getResult();
// Pass file
cb(null, file);
});
}n/a
report = function (options) {
// Default options
if (!options) {
options = {};
}
if (options.emitError === undefined) {
options.emitError = true;
}
if (options.reportLimit === undefined) {
// 0 or less is unlimited
options.reportLimit = 0;
}
if (options.summarizeFailureOutput === undefined) {
options.summarizeFailureOutput = false;
}
// Collect all files with errors
var errorFiles = [];
// Collect all failures
var allFailures = [];
// Track how many errors have been reported
var totalReported = 0;
// Log formatted output for each file individually
var reportFailures = function (file) {
if (file.tslint) {
// Version 5.0.0 of tslint no longer has a failureCount member
// It was renamed to errorCount. See tslint issue #2439
var failureCount = file.tslint.errorCount + file.tslint.warningCount;
if (failureCount > 0) {
errorFiles.push(file);
Array.prototype.push.apply(allFailures, file.tslint.failures);
if (options.reportLimit <= 0 || (options.reportLimit && options.reportLimit > totalReported)) {
if (file.tslint.output !== undefined) {
console.log(file.tslint.output);
}
totalReported += failureCount;
if (options.reportLimit > 0 &&
options.reportLimit <= totalReported) {
log("More than " + options.reportLimit
+ " failures reported. Turning off reporter.");
}
}
}
}
// Pass file
this.emit("data", file);
};
/**
* After reporting on all files, throw the error.
*/
var throwErrors = function () {
// Throw error
if (options && errorFiles.length > 0) {
var failuresToOutput = allFailures;
var ignoreFailureCount = 0;
// If error count is limited, calculate number of errors not shown and slice reportLimit
// number of errors to be included in the error.
if (options.reportLimit > 0) {
ignoreFailureCount = allFailures.length - options.reportLimit;
failuresToOutput = allFailures.slice(0, options.reportLimit);
}
// Always use the proseErrorFormat for the error.
var failureOutput = failuresToOutput.map(function (failure) {
return proseErrorFormat(failure);
}).join(", ");
var errorOutput = "Failed to lint: ";
if (options.summarizeFailureOutput) {
errorOutput += failuresToOutput.length + " errors.";
}
else {
errorOutput += failureOutput + ".";
}
if (ignoreFailureCount > 0) {
errorOutput += " (" + ignoreFailureCount
+ " other errors not shown.)";
}
if (options.emitError === true) {
return this.emit("error", new PluginError("gulp-tslint", errorOutput));
}
else if (options.summarizeFailureOutput) {
log(errorOutput);
}
}
// Notify through that we're done
this.emit("end");
};
return through(reportFailures, throwErrors);
}...
var tslint = require("gulp-tslint");
gulp.task("tslint", () =>
gulp.src("source.ts")
.pipe(tslint({
formatter: "verbose"
}))
.pipe(tslint.report())
);
```
Types should work automatically.
**tslint.json** is attempted to be read from near the input file.
It **must be available** or supplied directly through the options.
...default = function (pluginOptions) {
var loader;
var tslint;
// If user options are undefined, set an empty options object
if (!pluginOptions) {
pluginOptions = {};
}
return map(function (file, cb) {
// Skip
if (file.isNull()) {
return cb(null, file);
}
// Stream is not supported
if (file.isStream()) {
return cb(new PluginError("gulp-tslint", "Streaming not supported"));
}
// TSLint default options
var options = {
fix: pluginOptions.fix || false,
formatter: pluginOptions.formatter || "prose",
formattersDirectory: pluginOptions.formattersDirectory || null,
rulesDirectory: pluginOptions.rulesDirectory || null
};
var linter = getTslint(pluginOptions);
if (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 = new linter.Linter(options, pluginOptions.program);
tslint.lint(file.path, file.contents.toString("utf8"), pluginOptions.configuration);
file.tslint = tslint.getResult();
// Pass file
cb(null, file);
});
}n/a
report = function (options) {
// Default options
if (!options) {
options = {};
}
if (options.emitError === undefined) {
options.emitError = true;
}
if (options.reportLimit === undefined) {
// 0 or less is unlimited
options.reportLimit = 0;
}
if (options.summarizeFailureOutput === undefined) {
options.summarizeFailureOutput = false;
}
// Collect all files with errors
var errorFiles = [];
// Collect all failures
var allFailures = [];
// Track how many errors have been reported
var totalReported = 0;
// Log formatted output for each file individually
var reportFailures = function (file) {
if (file.tslint) {
// Version 5.0.0 of tslint no longer has a failureCount member
// It was renamed to errorCount. See tslint issue #2439
var failureCount = file.tslint.errorCount + file.tslint.warningCount;
if (failureCount > 0) {
errorFiles.push(file);
Array.prototype.push.apply(allFailures, file.tslint.failures);
if (options.reportLimit <= 0 || (options.reportLimit && options.reportLimit > totalReported)) {
if (file.tslint.output !== undefined) {
console.log(file.tslint.output);
}
totalReported += failureCount;
if (options.reportLimit > 0 &&
options.reportLimit <= totalReported) {
log("More than " + options.reportLimit
+ " failures reported. Turning off reporter.");
}
}
}
}
// Pass file
this.emit("data", file);
};
/**
* After reporting on all files, throw the error.
*/
var throwErrors = function () {
// Throw error
if (options && errorFiles.length > 0) {
var failuresToOutput = allFailures;
var ignoreFailureCount = 0;
// If error count is limited, calculate number of errors not shown and slice reportLimit
// number of errors to be included in the error.
if (options.reportLimit > 0) {
ignoreFailureCount = allFailures.length - options.reportLimit;
failuresToOutput = allFailures.slice(0, options.reportLimit);
}
// Always use the proseErrorFormat for the error.
var failureOutput = failuresToOutput.map(function (failure) {
return proseErrorFormat(failure);
}).join(", ");
var errorOutput = "Failed to lint: ";
if (options.summarizeFailureOutput) {
errorOutput += failuresToOutput.length + " errors.";
}
else {
errorOutput += failureOutput + ".";
}
if (ignoreFailureCount > 0) {
errorOutput += " (" + ignoreFailureCount
+ " other errors not shown.)";
}
if (options.emitError === true) {
return this.emit("error", new PluginError("gulp-tslint", errorOutput));
}
else if (options.summarizeFailureOutput) {
log(errorOutput);
}
}
// Notify through that we're done
this.emit("end");
};
return through(reportFailures, throwErrors);
}...
var tslint = require("gulp-tslint");
gulp.task("tslint", () =>
gulp.src("source.ts")
.pipe(tslint({
formatter: "verbose"
}))
.pipe(tslint.report())
);
```
Types should work automatically.
**tslint.json** is attempted to be read from near the input file.
It **must be available** or supplied directly through the options.
...