Socket
Socket
Sign inDemoInstall

gulp-tslint

Package Overview
Dependencies
58
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0 to 6.0.0

35

CHANGELOG.md

@@ -0,1 +1,36 @@

<a name="6.0.0"></a>
# 6.0.0 (2016-07-09)
## Changes
- **breaking change**: Add support for custom TSLint formatters, gulp-tslint reporters have been removed.
- **breaking change**: The signature for `tslintPlugin.report` has changed to `tslintPlugin.report(options?: ReportOptions)`.
This requires e.g. the following to be changed from
```
.pipe(tslint())
.pipe(tslint.report("verbose"))
```
to
```
.pipe(tslint({
formatter: "verbose"
}))
.pipe(tslint.report())
```
- Custom gulp-tslint reporters will no longer work; instead users will have to make use of the TSLint equivalents.
For more information see [pull #66](https://github.com/panuhorsmalahti/gulp-tslint/pull/66).
- **breaking change**: `tslintPlugin.ProseErrorFormat` is no longer exported.
- **breaking change**: The options passed to tslintPlugin have changed. The PluginOptions interface is now:
```
interface PluginOptions {
configuration?: any;
formatter?: string;
formattersDirectory?: string;
rulesDirectory?: string;
tslint?: any;
}
```
- **breaking change**: "full" formatter was removed
- Added "vso", "pmd" and "checkstyle" formatters
<a name="5.0.0"></a>

@@ -2,0 +37,0 @@ # 5.0.0 (2016-04-24)

26

index.d.ts
export interface PluginOptions {
configuration?: any;
formatter?: string;
formattersDirectory?: string;
rulesDirectory?: string;

@@ -19,23 +21,13 @@ tslint?: any;

}
export interface Position {
position: number;
line: number;
character: number;
}
export interface Failure {
name: string;
failure: string;
startPosition: Position;
endPosition: Position;
ruleName: string;
}
export interface Reporter {
(failures: Failure[], file?: TslintFile, options?: ReportOptions): void;
}
export interface TslintPlugin {
(pluginOptions?: PluginOptions): any;
proseErrorFormat: (failure: Failure) => string;
report: (reporter: string | Reporter, options?: ReportOptions) => any;
report: (options?: ReportOptions) => any;
}
/**
* Main plugin function
* @param {PluginOptions} [pluginOptions] contains the options for gulp-tslint.
* Optional.
* @returns {any}
*/
declare const tslintPlugin: TslintPlugin;
export default tslintPlugin;

@@ -55,9 +55,12 @@ /*jshint node:true */

* Convert a failure to the prose error format.
* @param {Failure} failure
* @param {Lint.RuleFailure} failure
* @returns {string} The failure in the prose error formar.
*/
var proseErrorFormat = function (failure) {
// line + 1 because TSLint's first line and character is 0
return failure.name + "[" + (failure.startPosition.line + 1) + ", " +
(failure.startPosition.character + 1) + "]: " + failure.failure;
var fileName = failure.getFileName();
var failureString = failure.getFailure();
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
var line = lineAndCharacter.line + 1;
var character = lineAndCharacter.character + 1;
return fileName + " [" + line + ", " + character + "]: " + failureString;
};

@@ -89,5 +92,4 @@ /**

configuration: pluginOptions.configuration,
formatter: "json",
// not used, use reporters instead
formattersDirectory: null,
formatter: pluginOptions.formatter || "prose",
formattersDirectory: pluginOptions.formattersDirectory || null,
rulesDirectory: pluginOptions.rulesDirectory || null

@@ -97,4 +99,4 @@ };

if (pluginOptions.configuration === null ||
pluginOptions.configuration === undefined
|| isString(pluginOptions.configuration)) {
pluginOptions.configuration === undefined ||
isString(pluginOptions.configuration)) {
// configuration can be a file path or null, if it's unknown

@@ -109,74 +111,8 @@ options.configuration = linter.findConfiguration(pluginOptions.configuration || null, file.path);

};
/**
* Define default reporters
*/
/**
* JSON error reporter.
* @param {Array<Failure>} failures
*/
var jsonReporter = function (failures) {
log(JSON.stringify(failures), "error");
};
/**
* Prose error reporter.
* @param {Array<Failure>} failures
*/
var proseReporter = function (failures) {
failures.forEach(function (failure) {
log(proseErrorFormat(failure), "error");
});
};
/**
* Verbose error reporter.
* @param {Array<Failure>} failures
*/
var verboseReporter = function (failures) {
failures.forEach(function (failure) {
// line + 1 because TSLint's first line and character is 0
log("(" + failure.ruleName + ") " + failure.name +
"[" + (failure.startPosition.line + 1) + ", " +
(failure.startPosition.character + 1) + "]: " +
failure.failure, "error");
});
};
/**
* Full error reporter. Like verbose, but prints full path.
* @param {Array<Failure>} failures
* @param {TslintFile} file
*/
var fullReporter = function (failures, file) {
failures.forEach(function (failure) {
// line + 1 because TSLint's first line and character is 0
log("(" + failure.ruleName + ") " + file.path +
"[" + (failure.startPosition.line + 1) + ", " +
(failure.startPosition.character + 1) + "]: " +
failure.failure, "error");
});
};
/**
* MsBuild Format error reporter.
* @param {Array<Failure>} failures
* @param {TslintFile} file
*/
var msbuildReporter = function (failures, file) {
failures.forEach(function (failure) {
var positionTuple = "(" + (failure.startPosition.line + 1) + "," +
(failure.startPosition.character + 1) + ")";
console.log(file.path + positionTuple + ": warning " +
failure.ruleName + ": " + failure.failure);
});
};
// Export proseErrorFormat function
tslintPlugin.proseErrorFormat = proseErrorFormat;
/* Output is in the following form:
* [{
* "name": "invalid.ts",
* "failure": "missing whitespace",
* // Lines and characters start from 0
* "startPosition": {"position": 8, "line": 0, "character": 8},
* "endPosition": {"position": 9, "line": 0, "character": 9},
* "ruleName": "one-line"
* }]
*/
tslintPlugin.report = function (reporter, options) {
tslintPlugin.report = function (options) {
// Notify the user that the old interface is used, this can be removed at some point
if (isString(options)) {
throw new Error("Deprecated interface used! See 6.0.0 changelog " +
"https://github.com/panuhorsmalahti/gulp-tslint/blob/master/CHANGELOG.md");
}
// Default options

@@ -202,28 +138,11 @@ if (!options) {

var totalReported = 0;
// Run the reporter for each file individually
// Log formatted output for each file individually
var reportFailures = function (file) {
var failures = JSON.parse(file.tslint.output);
if (failures.length > 0) {
var failureCount = file.tslint.failureCount;
if (failureCount > 0) {
errorFiles.push(file);
Array.prototype.push.apply(allFailures, failures);
Array.prototype.push.apply(allFailures, file.tslint.failures);
if (options.reportLimit <= 0 || (options.reportLimit && options.reportLimit > totalReported)) {
totalReported += failures.length;
if (reporter === "json") {
jsonReporter(failures);
}
else if (reporter === "prose") {
proseReporter(failures);
}
else if (reporter === "verbose") {
verboseReporter(failures);
}
else if (reporter === "full") {
fullReporter(failures, file);
}
else if (reporter === "msbuild") {
msbuildReporter(failures, file);
}
else if (isFunction(reporter)) {
reporter(failures, file, options);
}
console.log(file.tslint.output);
totalReported += failureCount;
if (options.reportLimit > 0 &&

@@ -230,0 +149,0 @@ options.reportLimit <= totalReported) {

{
"name": "gulp-tslint",
"preferGlobal": false,
"version": "5.0.0",
"version": "6.0.0",
"author": "Panu Horsmalahti <panu.horsmalahti@iki.fi>",

@@ -38,3 +38,3 @@ "description": "TypeScript linter Gulp plugin",

"gulp-concat": "^2.6.0",
"gulp-typescript": "^2.13.0",
"gulp-typescript": "^2.13.6",
"tslint": "^3",

@@ -41,0 +41,0 @@ "typescript": "latest"

@@ -29,4 +29,6 @@ gulp-tslint

gulp.src("source.ts")
.pipe(tslint())
.pipe(tslint.report("verbose"))
.pipe(tslint({
formatter: "verbose"
}))
.pipe(tslint.report())
);

@@ -40,5 +42,8 @@ ```

The output (stringified JSON) is added to file.tslint.output.
You can output the errors by using reporters.
There are five default reporters:
Failures generated by TSLint are added to `file.tslint`.
The format in which failures are outputted may be controlled by specifying a TSLint formatter.
The default formatter is "prose".
The available formatters include:
* "json" prints stringified JSON to console.log.

@@ -49,7 +54,16 @@ * "prose" prints short human-readable failures to console.log.

* "msbuild" for Visual Studio
* "vso" outputs failures in a format that can be integrated with Visual Studio Online.
* "checkstyle" for the Checkstyle development tool
* "pmd" for the PMD source code analyzer
Reporters are executed only if there is at least one failure.
Custom [TSLint formatters](https://palantir.github.io/tslint/develop/custom-formatters/) may also be
used by specifying the `formatter` and `formattersDirectory` properties on the options passed to
`gulp-tslint`.
If there is at least one failure a PluginError is
emitted after execution of the reporters:
If upgrading to gulp-tslint v6.0.0 or greater, it should be noted that reporters have been removed
in favour of using TSLint formatters directly. If you were previously specifying a reporter in calls
to `.report()`, these should be removed and instead `formatter` should be specified in calls to
`gulp-tslint`.
If there is at least one failure a PluginError is emitted after execution of the reporters:
```javascript

@@ -64,6 +78,8 @@ [gulp] Error in plugin 'gulp-tslint': Failed to lint: input.ts

gulp.src("input.ts")
.pipe(tslint())
.pipe(tslint.report("prose", {
emitError: false
.pipe(tslint({
formatter: "prose"
}))
.pipe(tslint.report({
emitError: false
}))
);

@@ -77,34 +93,11 @@ ```

gulp.src("input.ts")
.pipe(tslint())
.pipe(tslint.report("prose", {
summarizeFailureOutput: true
.pipe(tslint({
formatter: "prose"
}))
.pipe(tslint.report({
summarizeFailureOutput: true
}))
);
```
You can use your own reporter by supplying a function.
```javascript
/* output is in the following form:
* [{
* "name": "invalid.ts",
* "failure": "missing whitespace",
* // Lines and characters start from 0
* "startPosition": {"position": 8, "line": 0, "character": 8},
* "endPosition": {"position": 9, "line": 0, "character": 9},
* "ruleName": "one-line"
* }]
*/
const testReporter = function (output, file, options) {
// file is a reference to the vinyl File object
console.log("Found " + output.length + " errors in " + file.path);
// options is a reference to the reporter options, e.g. including the emitError boolean
};
gulp.task("invalid-custom", () =>
gulp.src("input.ts")
.pipe(tslint())
.pipe(tslint.report(testReporter))
);
```
tslint.json can be supplied as a parameter by setting the configuration property.

@@ -122,3 +115,3 @@ ```javascript

}))
.pipe(tslint.report("prose"))
.pipe(tslint.report())
);

@@ -145,4 +138,6 @@ ```

gulp.src(["input.ts",])
.pipe(tslint())
.pipe(tslint.report("prose", {
.pipe(tslint({
formatter: "prose"
}))
.pipe(tslint.report({
reportLimit: 2

@@ -174,2 +169,4 @@ }))

configuration: {},
formatter: "prose",
formattersDirectory: null,
rulesDirectory: null,

@@ -176,0 +173,0 @@ tslint: null

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc