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

    gulp-tslint

TypeScript linter Gulp plugin


Version published
Weekly downloads
25K
decreased by-0.86%
Maintainers
1
Install size
860 kB
Created
Weekly downloads
 

Changelog

Source

5.0.0 (2016-04-24)

Changes

  • support for extends property

<a name="4.3.0"></a>

Readme

Source

gulp-tslint

Build Status Dependency Status

TypeScript linter plugin for Gulp.

First install gulp-tslint

npm install --save-dev gulp-tslint
Peer dependencies

The tslint module is a peer dependency of gulp-tslint, which allows you to update tslint independently from gulp-tslint.

Usage:

// Importing in ES6
import tslint from "gulp-tslint";

// or requiring in ES5
var tslint = require("gulp-tslint");

gulp.task("tslint", () =>
    gulp.src("source.ts")
        .pipe(tslint())
        .pipe(tslint.report("verbose"))
);

Types should work automatically with TypeScript 1.6 or newer when used in TypeScript.

tslint.json is attempted to be read from near the input file. It must be available or supplied directly through the options.

The output (stringified JSON) is added to file.tslint.output. You can output the errors by using reporters. There are five default reporters:

  • "json" prints stringified JSON to console.log.
  • "prose" prints short human-readable failures to console.log.
  • "verbose" prints longer human-readable failures to console.log.
  • "full" is like verbose, but displays full path to the file
  • "msbuild" for Visual Studio

Reporters are executed only if there is at least one failure.

If there is at least one failure a PluginError is emitted after execution of the reporters:

[gulp] Error in plugin 'gulp-tslint': Failed to lint: input.ts

You can prevent emiting the error by setting emitError in report options to false.

gulp.task("invalid-noemit", () =>
    gulp.src("input.ts")
        .pipe(tslint())
        .pipe(tslint.report("prose", {
          emitError: false
        }))
);

You can summarize the gulp error message to the number of errors by setting summarizeFailureOutput in report options.

gulp.task("invalid-noemit", () =>
    gulp.src("input.ts")
        .pipe(tslint())
        .pipe(tslint.report("prose", {
          summarizeFailureOutput: true
        }))
);

You can use your own reporter by supplying a function.

/* 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.

gulp.task("tslint-json", () =>
    gulp.src("input.ts")
        .pipe(tslint({
            configuration: {
              rules: {
                "class-name": true,
                // ...
              }
            }
        }))
        .pipe(tslint.report("prose"))
);

You can also supply a file path to the configuration option, and the file name doesn't need to be tslint.json.

.pipe(tslint({
    // contains rules in the tslint.json format
    configuration: "source/settings.json"
}))

Report limits

You can optionally specify a report limit in the .report options that will turn off reporting for files after the limit has been reached. If the limit is 0 or less, the limit is ignored, which is the default setting.

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

Specifying the tslint module

If you want to use a different version of tslint, you can supply it with the tslint option.

npm install tslint@next
.pipe(tslint({
    tslint: require("tslint")
}));

All default tslint options

const tslintOptions = {
    configuration: {},
    rulesDirectory: null,
    tslint: null
};

All default report options

const reportOptions = {
    emitError: true,
    reportLimit: 0,
    summarizeFailureOutput: false
};

Development

Fork this repository, run npm install and send pull requests. The project can be build with gulp command.

Keywords

FAQs

Last updated on 24 Apr 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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