Giter Site home page Giter Site logo

gulp-tslint's Introduction

gulp-tslint

Build Status Dependency Status

TypeScript linter plugin for Gulp.

First install gulp-tslint

npm install --save-dev gulp-tslint

Usage:

const tslint = require('gulp-tslint');

gulp.task('tslint', function(){
      return gulp.src('source.ts')
        .pipe(tslint())
        .pipe(tslint.report('verbose'));
});

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 four 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

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', function(){
    return gulp.src('input.ts')
        .pipe(tslint())
        .pipe(tslint.report('prose', {
          emitError: false
        }));
});

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', function(){
    return 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', function(){
    return gulp.src('input.ts')
        .pipe(tslint({
            configuration: {
              rules: {
                "class-name": true,
                // ...
              }
            }
        }))
        .pipe(tslint.report('prose'));;
});

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', function(){
    return 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
};

Development

Fork this repository, run npm install and send pull requests.

gulp-tslint's People

Contributors

panuhorsmalahti avatar pepaar avatar mrhen avatar xt0rted avatar pspeter3 avatar bookman25 avatar

Watchers

Tarmo Leppänen avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.