Git Product home page Git Product 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
Peer dependencies

The tslint module is a peer dependency of gulp-tslint, which allows you to update tslint independently from gulp-tslint. gulp-tslint requires TypeScript version >=2 and tslint version >=4.

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({
            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.

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.
  • "prose" prints short human-readable failures to console.log.
  • "verbose" prints longer 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
  • "stylish" human-readable formatter which creates stylish messages.

Custom TSLint formatters may also be used by specifying the formatter and formattersDirectory properties on the options passed to gulp-tslint.

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:

[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({
            formatter: "prose"
        }))
        .pipe(tslint.report({
            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({
            formatter: "prose"
        }))
        .pipe(tslint.report({
            summarizeFailureOutput: true
        }))
);

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())
);

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({
            formatter: "prose"
        }))
        .pipe(tslint.report({
            reportLimit: 2
        }))
);

Allowing Warnings

TSLint 5.0 introduced support for a "warning" severity for linting errors. By default, warnings cause gulp-tslint to emit an error to maintain backwards-compatibility with previous versions. To let the build succeed in the presence of warnings, use the allowWarnings report option.

gulp.task("tslint", () =>
    gulp.src("input.ts")
        .pipe(tslint({
            formatter: "prose"
        }))
        .pipe(tslint.report({
            allowWarnings: true
        }))
);

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")
}));

Type checked rules

Type checked rules require a TypeScript program object to be provided to the linter in the options. For more information see tslint documentation.

var gulpTslint = require("gulp-tslint");
var tslint = require("tslint");

// NOTE: Ensure 'Linter.createProgram' is called inside the gulp task else the contents of the files will be cached
// if this tasks is called again (eg. as part of a 'watch' task).
gulp.task('lint', function() {
    var program = tslint.Linter.createProgram("./tsconfig.json");

    return gulp.src('src/**/*.ts', { base: '.' })
        .pipe(gulpTslint({ program }));
}

All default tslint options

const tslintOptions = {
    configuration: {},
    fix: false,
    formatter: "prose",
    formattersDirectory: null,
    rulesDirectory: null,
    tslint: null,
    program: null
};

All default report options

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

Development

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

gulp-tslint's People

Contributors

alexeagle avatar ayamorisawa avatar bookman25 avatar cgwrench avatar demurgos avatar ebugusey avatar ejmarino avatar giedriusgrabauskas avatar greenkeeperio-bot avatar hekystyle avatar jfstephe avatar jkillian avatar jp7677 avatar jucrouzet avatar mindfreakthemon avatar mrhen avatar mxl avatar okaufmann avatar palortoff avatar panuhorsmalahti avatar pepaar avatar pspeter3 avatar romkevdmeulen avatar silic0ns0ldier avatar sjbarag avatar stevejhiggs avatar tmos avatar valorkin avatar wvanderdeijl avatar xt0rted avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-tslint's Issues

How can I lint without having a tslint.json file?

When I run $ tslint app/main.ts from the commandline I get a couple of errors about using ' instead of ".

When I run via gulp I do not. I created a tslint.json file and then reran it and the errors showed up as expected. I would like to run gulp-tslint without having a tslint.json file however. I just want it to use all of the default rules instead. I've been trying to figure out how to do this but the documentation doesn't make it clear how to run without one.

Additionally, I would recommend, without knowing more, that the default behavior is to apply the default rules if no tslint.json file is found and require no extra configuration than the basic example given at the top of the README.

Details:

gulp-tslint version: 4.3.4
tslint version: 3.6.0
Operating system: osx

Example gulp configuration (if applicable):

gulp.task('typescript:lint', () => {
    return gulp.src('app/main.ts')
        .pipe(tslint())
        .pipe(tslint.report('prose'))
})

Error console output:

10:51:26:justin:~/code/test (master)$ gulp typescript:lint
[10:51:29] Using gulpfile ~/code/test/gulpfile.js
[10:51:29] Starting 'typescript:lint'...
[10:51:29] Finished 'typescript:lint' after 33 ms

TypeScript example code (if applicable):

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';

bootstrap(AppComponent);

Old version of tslint used

Hi

Thanks for the plugin! I have a bit of a problem that you do not provide for use of latest language enhancements such as "for of" loop and linting fails. Tslint already supports that, or at least it is not throwing errors. Seems like you are using outdated ts lint?

Following is ok for tslint, but fails with gulp-tslint with use of undeclared variable and duplicate variable

var fixtures : string[] = ["siteConfig"];
for (var fixture of fixtures) {
}

Thanks!

semicolonRule - TypeError: Cannot read property 'length' of undefined

I'm receiving the following error stack:

I have a "fix" for which I'm submitting a PR. I'm not sure if it's a legit fix, but submitting to illustrate what is removing the error, yet detecting missing semicolons in linted files.

/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/rules/semicolonRule.js:70
        for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
                                                   ^

TypeError: Cannot read property 'length' of undefined
    at SemicolonWalker.visitInterfaceDeclaration (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/rules/semicolonRule.js:70:52)
    at SemicolonWalker.SyntaxWalker.visitNode (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/language/walker/syntaxWalker.js:332:22)
    at /Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/language/walker/syntaxWalker.js:443:63
    at visitEachNode (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/node_modules/typescript/lib/typescript.js:6886:30)
    at Object.forEachChild (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/node_modules/typescript/lib/typescript.js:7043:24)
    at SemicolonWalker.SyntaxWalker.walkChildren (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/language/walker/syntaxWalker.js:443:12)
    at SemicolonWalker.SyntaxWalker.visitNode (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/language/walker/syntaxWalker.js:437:22)
    at SemicolonWalker.SyntaxWalker.walk (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/language/walker/syntaxWalker.js:6:14)
    at Rule.AbstractRule.applyWithWalker (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/language/rule/abstractRule.js:18:16)
    at Rule.apply (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/rules/semicolonRule.js:14:21)
    at Linter.lint (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/tslint/lib/tslint.js:26:41)
    at /Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/gulp-tslint/index.js:95:34
    at respond (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/gulp-tslint/node_modules/rcloader/index.js:68:7)
    at respond (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/rcfinder/index.js:140:7)
    at next (/Users/jerryorta-dev/Dev/UIUXEngineering/angular1-typescript-ES6-jspm-gulp/node_modules/rcfinder/index.js:167:16)
    at nextTickCallbackWith0Args (node.js:456:9)
    at process._tickDomainCallback (node.js:426:13)

tslint cli correctly parsing JSDOC comments but not gulp task

The code below parses when running tslint directly in the IDE.
However, it fails from gulp-tslint with error asterisks in jsdoc must be aligned

/**
  * Accepts a C-printf style invocation.
  * Ex: foo('qcycle', "Expected promise to be resolved with value other than itself '{0}'", val));
  *
  * @param prefix
  * @param message
  * @param messageValues
  * @returns {Error}
  */
export default function foo(prefix : string, messageTemplate : string, ...messageValues : any[]) {

Override tslint.json with configuration.

If a tslint file is found, it seems as though the configuration object is ignored. Is there a way to override certain things from the tslint.json file through the configuration object when calling tslint in gulp.

Output to File

Any way to redirect the output to a file?

This not work :(

gulp.task('tslint', 'Lints all TypeScript source files', function(){
  return gulp.src(tsFiles)
  .pipe(tslint())
  .pipe(tslint.report('verbose'))
  .pipe(gulp.dest('./reports.html'));
});

Feature request: VSO reporter

It would be great if a reporter for Visual Studio Online/Team Foundation Server integration could be added to this project. I've had such a formatter added to TSLint itself, see palantir/tslint@cee7e71.

In order to make use of this new formatter from gulp-tslint, it appears that this formatter would need to be reimplemented as a new reporter for gulp-tslint. Would you like to see such a reporter added to gulp-tslint? If so, then I can contribute a pull request.

Alternatively, the ideal situation would be that I can make use of this new TSLint formatter directly from gulp-tslint, as suggested in #27 (comment). Is there likely to be any work being carried out to re-work gulp-tslint to make use of TSLint formatters directly? If so, then again, I am happy to try and contribute.

TypeError: undefined is not a function at Gulp

gulp-tslint version: 3.6.0
tslint version: 3.6.0
Operating system: Ubuntu 14.04

Example gulp configuration (if applicable):

/*jslint maxlen:160*/
 (function (require) {
   "use strict";
   var gulp, tslint;
   gulp   = require('gulp');
   tslint = require('gulp-tslint');
   gulp.task("tslint", function() {
    return gulp.src(["src/**/*.ts"])
               .pipe(tslint())
               .pipe(tslint.reporter("verbose"));
   });
 }(require));

Error console output:

[17:26:58] Using gulpfile /var/www/tests/gulp_error/gulpfile.js [17:26:58] Starting 'tslint'... [17:26:58] 'tslint' errored after 6.08 ms [17:26:58] TypeError: undefined is not a function at Gulp. (/var/www/tests/gulp_error/gulpfile.js:9:36) at module.exports (/var/www/tests/gulp_error/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7) at Gulp.Orchestrator._runTask (/var/www/tests/gulp_error/node_modules/gulp/node_modules/orchestrator/index.js:273:3) at Gulp.Orchestrator._runStep (/var/www/tests/gulp_error/node_modules/gulp/node_modules/orchestrator/index.js:214:10) at Gulp.Orchestrator.start (/var/www/tests/gulp_error/node_modules/gulp/node_modules/orchestrator/index.js:134:8) at /home/username/.nvm/versions/node/v0.12.12/lib/node_modules/gulp/bin/gulp.js:129:20 at process._tickCallback (node.js:355:11) at Function.Module.runMain (module.js:503:11) at startup (node.js:129:16) at node.js:814:3

TypeScript example code (if applicable):
https://github.com/yahyaKacem/gulp_error

Initial load performance, related to plugin?

Hi,

as I can see with spy.js, gulp-tslint takes 1500 ms to initialize with require("gulp-tslint")
this is the most out of all gulp and node requires

npm tslint itself takes 250ms and gulp-util 283ms = 530ms
there must be something in the index.js being slow.

any idea ?

Semicolon error on ES6 import

For example:

///<reference path="../typings/tsd.d.ts" />
import { expect } from 'chai';
[gulp-tslint] error (semicolon) plugin.spec.ts[2, 16]: missing semicolon

Error: var isSingleVariable = node.name.kind === 69;

I'm just try a simple gulp task....

gulp.task('src-lint-ts', function (callback) {

    gulp.src('app.ts')
        .pipe(tslint())
        .pipe(tslint.report('prose'));

});

no special src, no special pipe.....really simple and i see the error:

        var isSingleVariable = node.name.kind === 69;
                                        ^
TypeError: Cannot read property 'kind' of undefined

I have tried the same tslint.json configuration directly with tslint: tslint app.ts without any errors!
Ps: i'm on windows

combining tslint.report() and tslint()?

Is it possible to combine tslint and tslint.report calls?so there is alway only one pipe call to do tslint or tslint + report.

Current settings:

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

suggested settings

gulp.src("input.ts")
        .pipe(tslint({
            configuration: {
            },
            report: {
            ...
            }
        }))

TypeScript 1.8 support

Update support for TS 1.8.

npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants typescript@>=1.7.3

TypeScript 1.8 is one of my devDependencies as below:

"typescript": "^1.8.0-dev.20151204"

Failing lint doesn't fail gulp

I was going to hook gulp-tslint into our build server, and noticed that even if a lint rule is broken, gulp-tslint isn't failing gulp, which in turn isn't failing the build.

Output formatting

Thanks for putting this plugin together!

I'm curious if you had any plans to add support for output formatting, as it's just outputting raw json now, which is a little hard to read.

Or maybe it's possible to capture the output myself and reformat it? I'm not exactly sure how to do that with gulp.

gulp-tslint

Since tslint 3.1.1, whenever a linting error occurs, the gulp plugin causes an exception like this:

stream.js:74
      throw er; // Unhandled stream error in pipe.
      ^
 Error: Failed to lint: app/app.ts[13, 5]: unused variable: 'a'.

Support/example with plumber and notify

Passing the exception to notify,
it only gets the failing names in the error message, but the actual information about failing rule
is not within, but should be.

So the exception should also contain the failing information

How to run negative test?

gulp-tslint version: 4.3.3
tslint version: 3.5.0
Operating system: OSX 10.5

Cross-linking: https://github.com/unional/typescript/issues/7


Need some help on this:
https://github.com/unional/typescript/blob/master/packages/tslint-config-unional/gulpfile.js#L19-L21
To flip failed test to success and vice versa.

A little background:
That code is using gulp-tslint to ensure rules are working and specified as I meant it to be.
Positive test is easy.
I try to add negative test to make sure it does capture any violated style.

gulp-tslint pass back files, something like:

<File "label-position.fail.ts" <Buffer 73 74 61 72 74 3a 0a 76 61 72 20 78 20 3d 20 31 3b 0a>>
<File "no-conditional-assignment.fail.ts" <Buffer 76 61 72 20 78 2c 20 79 3b 0a 69 66 20 28 78 20 3d 20 79 29 20 7b 0a 0a 7d 0a>>
<File "no-construct.fail.ts" <Buffer 76 61 72 20 78 20 3d 20 6e 65 77 20 53 74 72 69 6e 67 28 27 73 27 29 3b 0a>>

I am expecting it would give me some information in the form of:
https://github.com/palantir/tslint/blob/master/src/lint.ts#L40-L45

export interface LintResult {
    failureCount: number;
    failures: RuleFailure[];
    format: string;
    output: string;
}

and
https://github.com/palantir/tslint/blob/master/src/language/rule/rule.ts#L74-L137:

export class RuleFailure {
    private sourceFile: ts.SourceFile;
    private fileName: string;
    private startPosition: RuleFailurePosition;
    private endPosition: RuleFailurePosition;
    private failure: string;
    private ruleName: string;

    constructor(sourceFile: ts.SourceFile,
                start: number,
                end: number,
                failure: string,
                ruleName: string) {

        this.sourceFile = sourceFile;
        this.fileName = sourceFile.fileName;
        this.startPosition = this.createFailurePosition(start);
        this.endPosition = this.createFailurePosition(end);
        this.failure = failure;
        this.ruleName = ruleName;
    }

    public getFileName() {
        return this.fileName;
    }

    public getRuleName() {
        return this.ruleName;
    }

    public getStartPosition(): RuleFailurePosition {
        return this.startPosition;
    }

    public getEndPosition(): RuleFailurePosition {
        return this.endPosition;
    }

    public getFailure() {
        return this.failure;
    }

    public toJson(): any {
        return {
            endPosition: this.endPosition.toJson(),
            failure: this.failure,
            name: this.fileName,
            ruleName: this.ruleName,
            startPosition: this.startPosition.toJson(),
        };
    }

    public equals(ruleFailure: RuleFailure) {
        return this.failure  === ruleFailure.getFailure()
            && this.fileName === ruleFailure.getFileName()
            && this.startPosition.equals(ruleFailure.getStartPosition())
            && this.endPosition.equals(ruleFailure.getEndPosition());
    }

    private createFailurePosition(position: number) {
        const lineAndCharacter = this.sourceFile.getLineAndCharacterOfPosition(position);
        return new RuleFailurePosition(position, lineAndCharacter);
    }
}

But I may be wrong.

specifying rules through options doesn't work with tslint.config present

If a tslint.json file is present, and you specify rules using

{configuration: {rules: {...}}

these rules do not overwrite the corresponding rules in the tslint.json (try this with max-line-length), furthermore, all the rules in tslint.json are used.

I think this is caused by spalger/rcloader#10. See also spalger/rcloader#8.

A temporary solution is to have a secondary configuration file (tslint.spec.json in my case), and pass it directly as a string.

5.0.0 - emitError: false - Does not stop error

gulp-tslint version: 5.0.0
tslint version: 3.11.0
Operating system: OS X

Example gulp configuration (if applicable):

gulp.task('lint', () => {
  return gulp.src('./src/**/*.ts')
    .pipe(tslint({
      configuration: lintConfig
    }))
    .pipe(tslint.report("prose", {
          emitError: false
        }))
})

Error console output:

[16:10:06] Error in plugin 'gulp-tslint'

TypeScript example code (if applicable):

cannot install with typescript@next

If I try to install this package along with typescript@next I get a [email protected] requires a peer of typescript@>=1.7.3 but none was installed.. I really need to use the nightly build of TS, is there any way to make the install work?

I tried using npm-shrinkwrap.json:

{
    "name": "name",
    "version": "0.0.0",
    "devDependencies": {
        "gulp-tslint": {
            "version": "4.3.x",
            "from": "[email protected]",
            "dependencies": {
                "tslint": {
                    "version": "3.3.x",
                    "from": "[email protected]"
                },
                "typescript": {
                    "version": "next",
                    "from": "typescript@next"
                }
            }
        },
        "tslint": {
            "version": "3.3.x",
            "from": "[email protected]",
            "dependencies": {
                "typescript": {
                    "version": "next",
                    "from": "typescript@next"
                }
            }
        }
    }
}

But that did not solve my problem.

sample task results with: stream.js:94 throw er; // Unhandled stream error in pipe.

I can run tslint on the same file OK, but using the sample gulp-tslint task results with: stream.js:94 throw er; // Unhandled stream error in pipe.

gulp.task('tslint2', () => {
    var linter = gulp.src(['gulpfile.ts'])
        .pipe(tslint())
        .pipe(tslint.report('prose'));
});

console:

C:\proj\GitHub\test>gulp tslint2
[21:44:07] Using gulpfile ~\GitHub\test\gulpfile.js
[21:44:07] Starting 'tslint2'...
[21:44:07] Finished 'tslint2' after 5.32 ms
[21:44:07] [gulp-tslint] error gulpfile.ts[42, 15]: comment must start with a sp
ace
[21:44:07] [gulp-tslint] error gulpfile.ts[48, 4]: file should end with a newlin
e
[21:44:07] [gulp-tslint] error gulpfile.ts[6, 8]: unused variable: 'concat'
[21:44:07] [gulp-tslint] error gulpfile.ts[16, 5]: unused variable: 'testReporte
r'
[21:44:07] [gulp-tslint] error gulpfile.ts[23, 9]: unused variable: 'linter'
[21:44:07] [gulp-tslint] error gulpfile.ts[4, 23]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[5, 29]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[6, 25]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[7, 29]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[8, 25]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[22, 11]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[23, 28]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[25, 29]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[29, 11]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[30, 30]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[37, 21]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[38, 21]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[43, 36]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[44, 29]: ' should be "
[21:44:07] [gulp-tslint] error gulpfile.ts[16, 17]: expected variable-declaratio
n: 'testReporter' to have a typedef
[21:44:07] [gulp-tslint] error gulpfile.ts[16, 28]: expected parameter: 'output'
 to have a typedef
[21:44:07] [gulp-tslint] error gulpfile.ts[16, 34]: expected parameter: 'file' t
o have a typedef
[21:44:07] [gulp-tslint] error gulpfile.ts[16, 43]: expected parameter: 'options
' to have a typedef
[21:44:07] [gulp-tslint] error gulpfile.ts[23, 15]: expected variable-declaratio
n: 'linter' to have a typedef
[21:44:07] [gulp-tslint] error gulpfile.ts[30, 17]: expected variable-declaratio
n: 'tsResult' to have a typedef
[21:44:07] [gulp-tslint] error gulpfile.ts[12, 1]: missing 'use strict'

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: Failed to lint: gulpfile.ts[42, 15]: comment must start with a space, gul
pfile.ts[48, 4]: file should end with a newline, gulpfile.ts[6, 8]: unused varia
ble: 'concat', gulpfile.ts[16, 5]: unused variable: 'testReporter', gulpfile.ts[
23, 9]: unused variable: 'linter', gulpfile.ts[4, 23]: ' should be ", gulpfile.t
s[5, 29]: ' should be ", gulpfile.ts[6, 25]: ' should be ", gulpfile.ts[7, 29]:
' should be ", gulpfile.ts[8, 25]: ' should be ", gulpfile.ts[22, 11]: ' should
be ", gulpfile.ts[23, 28]: ' should be ", gulpfile.ts[25, 29]: ' should be ", gu
lpfile.ts[29, 11]: ' should be ", gulpfile.ts[30, 30]: ' should be ", gulpfile.t
s[37, 21]: ' should be ", gulpfile.ts[38, 21]: ' should be ", gulpfile.ts[43, 36
]: ' should be ", gulpfile.ts[44, 29]: ' should be ", gulpfile.ts[16, 17]: expec
ted variable-declaration: 'testReporter' to have a typedef, gulpfile.ts[16, 28]:
 expected parameter: 'output' to have a typedef, gulpfile.ts[16, 34]: expected p
arameter: 'file' to have a typedef, gulpfile.ts[16, 43]: expected parameter: 'op
tions' to have a typedef, gulpfile.ts[23, 15]: expected variable-declaration: 'l
inter' to have a typedef, gulpfile.ts[30, 17]: expected variable-declaration: 't
sResult' to have a typedef, gulpfile.ts[12, 1]: missing 'use strict'.

Output file path as link for WebStorm

I'm using WebStorm as editor and its gulp plugin.

I have notice that if you output the file path using console.log() instead of gulp-utils.log(), then the file path will be rendered as link by WebStorm (and maybe some other editor too). Clicking on it will open the file to the exact position of the error, which is quite great.

The different is gulp-utils.log() will prefix the line with the time between [ ]. As the linting works is done under a few millisecondes, I would propose that you skip it. Anyway, gulp display the time for each tasks and its duration.

If you agree I can work on a pull request.

Ignore tslint.json when supplying the file directly

If tslint.json contains invalid JSON, but the tslint file is supplied with the configuration object, gulp-tslint will throw an error even if the tslint configuration object would be usable. However, gulp-tslint should just ignore the tslint.json file in these cases.

Update to [email protected]

Hi,

pls update to the newest verion of tslint.

Maybe, it would be nice, if tslint dependency was moved to peerDependencies. This way it works with tslint-loader.

Thanks,

O.

linter always uses file.relative

using something like this

gulp.src("foo/**/*.ts").pipe(tslint({formatter: "full"))

Currently gives

 [gulp-tslint] error (semicolon) hello/world.ts[82, 67]: Missing semicolon

I would expect the path to be either

foo/hello/world.ts

or

/Users/me/Documents/dev/foo/hello.world.ts

The ask is because I'm working on a tslint autofixer that can take the output of tslint or gulp-tslint and auto fix the errors.

Currently the gulp-tslint output is not very machine friendly since the paths it emits is missing info.

gulp-tslint does not pass on rulesDirectory to TSLint

It seems that the gulp plugin does not pass the rules directory setting on to lint, given your code (index.js)

 var options = {
                formatter: 'json',
                configuration: fileopts,
                rulesDirectory: pluginOptions.formatter || null,
                formattersDirectory: pluginOptions.formatter || null
            };

False-negative on unused private variables

When private variable is accessed only through self variable it produces 'unused variable' error.

Here is short example:

class SomeClass {
    constructor() {
         var self: SomeClass = this;
         self.doSomething();
         var newX: number = self.x;
    }

    private x: number;
    private doSomething(): void { 
    ...
    }
}

It occurs since 3.1.2 version.

usage of gulp-tslint breaks gulp-typescript with ts 1.5

I use gulp-typescript with the latest 1.5 beta (https://github.com/mhegazy/TypeScript) . When I install gulp-tslint it does not work anymore.

when require('gulp-tslint') before require('gulp-typescript') than I get then error:

var scanner = ts.createScanner(1, false, node.text);
                         ^
TypeError: undefined is not a function

the other way (gulp-typescript before gulp-tslint) I get an error on typescript transpiling :

TypeError: object is not a function

Is there a workaround?

tslint 1.0.0

Would it be an idea to bump the tslint version to 1.0.0? It doesn't install automagically due to it's version being specified as "~0.4.12"

Output path not relative to project root

My project file structure is like that:

* src/
  * app/
    * myapp.ts
* gulpfile.js
* package.json
* tsconfig.json

My tslint config is like this:
var tslint = require('gulp-tslint');

gulp.task('tslint', function(){
      return gulp.src('src/**/*.ts')
        .pipe(tslint())
        .pipe(tslint.report('prose'));
});

But the output is not relative the project root (should output path src/app/myapp.ts):

[14:27:30] [gulp-tslint] error app/myapp.ts[17, 5]: comment must start with a space

Is it a bug or a wrong configuration ?

rulesDirectory option of tslint.json not handled correctly

gulp-tslint version: 4.3.3
tslint version: 3.5.0
Operating system: All

If a tslint.json file specifies a rulesDirectory property, gulp-tslint needs to resolve those paths relative to the location of the tslint.json file and provide those to TSLint via the rulesDirectory option found here. TSLint has no way of resolving these paths itself since it has no way of knowing where the tslint.json file was located.

This is a subtle bug and I understand that it's not super predictable behavior from TSLint, but I'm now sure what TSLint could do differently. tslint-loader also has a similar bug.

no-var-keyword rule ignored

I have "no-var-keyword": true in my tslint.json. When running my global tslint.cmd, I get linting errors related to this rule. When running gulp tslint, I get no linting errors related to this rule.

My global tslint is 2.3.0-beta. I noticed that gulp-tslint uses tslint 2.2.0-beta. Might this have something to do with it?

Option summarizeFailureOutput: true does not work with emitError: false

They should be independent.

Example:

gulp.task('tslint', () =>
    ...
    .pipe(tslint.report('prose', {emitError: false, summarizeFailureOutput: true}))
);
$ gulp tslint
...
[22:29:42] [gulp-tslint] error app.ts[24, 71]: missing whitespace
[22:29:43] Finished 'tslint' after 865 ms

vs

gulp.task('tslint', () =>
    ...
    .pipe(tslint.report('prose', {emitError: true, summarizeFailureOutput: true}))
);
$ gulp tslint
...
[22:29:01] [gulp-tslint] error app.ts[24, 71]: missing whitespace
[22:29:01] 'tslint' errored after 851 ms
[22:29:01] Error in plugin 'gulp-tslint'
Message:
    Failed to lint: 1 errors.

Would be nice to have the message Failed to lint: x errors even if emitError is false.
In my case it helps me to see if the number of errors increases (knowing that I have already n errors that are false positive).

Template strings not properly parsed

Template strings (new feature of TS 1.4) don't seem to be properly handled.

Working example:

throw new Error(`ruleSet "${ruleSet.description}" has no defined output tied to type: ${rule.type}`);

Not working example:

throw new Error(`ruleSet "${ruleSet.description}" has no defined output for type: ${rule.type}`);

Output:

(curly) service.ts[89, 93]: for statements must be braced
(no-unused-expression) service.ts[89, 103]: expected an assignment or function call
(no-unused-expression) service.ts[89, 103]: expected an assignment or function call
(no-unused-expression) service.ts[89, 105]: expected an assignment or function call
(no-unreachable) service.ts[89, 93]: unreachable code
(semicolon) service.ts[89, 113]: missing semicolon

In this example, for was interpreted as an instruction instead of a template string. It results in several errors.

TSLint works on the command line - gulp-tslint returns TypeError: Cannot read property 'getFullWidth' of undefined

In trying to get this setup, I am getting an error in gulp-tslint, that I do not get using tslint on the command line.

This is the sub job that runs the Typescript compile and TSLint

module.exports = function (gulp, PlugIns, Settings) {
return function () {
    gulp.src(['./app/Modules/**/*.tsx'])
        .pipe(PlugIns.plumber())
        .pipe(PlugIns.debug())
        .pipe(PlugIns.typescript())
        .pipe(PlugIns.tslint( {
            configuration: {
                rules: {
                    "class-name": true,
                    "curly": true,
                    "eofline": true,
                    "indent": [
                        true,
                        "tabs"
                    ],
                }
            }
        }))
        .pipe(PlugIns.tslint.report("stylish"))
        .pipe(gulp.dest(Settings.Destination.TSCompiled))
        ;
    }
};

My Test file that should have errors

class Greeter {
    constructor(public greeting) { }
    greet() {
        return "<h2>" + this.greeting + "</h2>";
    }
    nogreet()
    {
return 'Not ' + this.greeting;
}
};

var greeter = new Greeter("Hello, world!");

gulp-tslint error generated when running gulp:

gulp
[18:20:20] Using gulpfile ~\Development\gulpfile.js
[18:20:20] Starting 'TypeScript'...
[18:20:20] Finished 'TypeScript' after 569 ms
[18:20:20] Starting 'default'...
[18:20:20] Finished 'default' after 7.84 ms
[18:20:20] gulp-debug: app\Modules\Cars\car.tsx
[18:20:20] gulp-debug: 1 item
~\Development\node_modules\tslint\lib\language\walker\ruleWalker.js:18
        this.limit = this.sourceFile.getFullWidth();
                                    ^
TypeError: Cannot read property 'getFullWidth' of undefined
    at EnableDisableRulesWalker.RuleWalker [as constructor] 
(~\Development\node_modules\tslint\lib\language\walker\ruleWalker.js
:18:37)
    at EnableDisableRulesWalker.SkippableTokenAwareRuleWalker [as constructor] (
~\Development\node_modules\tslint\lib\language\walker\skippableTokenAwareRuleWalker.js:11:16)
    at new EnableDisableRulesWalker (~\Development\node_modules\tslint\lib\enableDisableRules.js:13:16)
    at Linter.lint (~\Development\node_modules\tslint\lib\tslint.js:16:27)
    at ~\Development\node_modules\gulp-tslint\index.js:96:34
    at respond (~\Development\node_modules\rcloader\index.js:73:7)
    at respond (~\Development\node_modules\rcfinder\index.js:140:7)
    at ~\Development\node_modules\rcfinder\index.js:124:17
    at ~\Development\node_modules

However, running the tslint from the command line (in the same directory as gulp), the coding issues are returned.

tslint -c tslint.json app\Modules\Cars\Greet.tsx
app/Modules/Cars/Greet.tsx[3, 5]: default access modifier on member/method not a
llowed
app/Modules/Cars/Greet.tsx[6, 5]: default access modifier on member/method not a
llowed
app/Modules/Cars/Greet.tsx[2, 17]: 'greeting' cannot be declared in the construc
tor
app/Modules/Cars/Greet.tsx[12, 5]: unused variable: 'greeter'
app/Modules/Cars/Greet.tsx[12, 1]: forbidden var keyword
app/Modules/Cars/Greet.tsx[7, 5]: misplaced opening brace
app/Modules/Cars/Greet.tsx[8, 8]: ' should be "
app/Modules/Cars/Greet.tsx[2, 32]: expected parameter: 'greeting' to have a type
def
app/Modules/Cars/Greet.tsx[3, 11]: expected call-signature: 'greet' to have a ty
pedef
app/Modules/Cars/Greet.tsx[6, 13]: expected call-signature: 'nogreet' to have a
typedef
app/Modules/Cars/Greet.tsx[12, 12]: expected variable-declaration: 'greeter' to
have a typedef

Missing support for TSLint's 'exclude' CLI option

gulp-tslint version: 6.0.2
tslint version: 3.13.0
Operating system: OSX 10.11.5

There doesn't appear to be support for tslint's exclude CLI option. At least, I'm not seeing it in the code anywhere and adding it to the config object has no effect.

Unhandled stream error in pipe.

gulp-tslint throws the following error:
stream.js:74
throw er; // Unhandled stream error in pipe.

gulp-tslint version:4.3.3
tslint version:3.6.0
Operating system: Windows 8.1

Example gulp configuration (if applicable):

`
// ===========================================================================
// Load gulp plug-ins ========================================================
// ===========================================================================
var gulp = require('gulp');
var util = require('gulp-util');
var debug = require('gulp-debug');
var gulpif = require('gulp-if');
var rename = require('gulp-rename');

var sass = require('gulp-sass');
var stripCssComments = require('gulp-strip-css-comments');

var tsc = require('gulp-typescript');
var tslint = require('gulp-tslint');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');

var tsProject = tsc.createProject('tsconfig.json');

// ===========================================================================
// Configuration =============================================================
// ===========================================================================
var config = {
    src: {
        root: {
            sass: 'styles/_Custom/',
            ts: 'scripts/_Custom/'
        },
        bs: 'styles/bootstrap.scss'
    },
    dest: {
        root: {
            styles: '../css/',
            scripts: '../js/'
        },
        style: {
            bs: 'bootstrap.min.css',
            mainStyle: 'site.min.css',
            mergedResult: 'Main.css'
        },
        mainScriptName: 'Main.js'
    },
    isReleaseBuild: false,
    isInWatchMode: false
};


//Set typescript files
config.src.ts = [getTsPath('**/*.ts'), 'typings/tsd.d.ts'];

// Gets the path for the given typescript file.
function getTsPath(file) {
    return config.src.root.ts + file;
}

// ===========================================================================
// Tasks =====================================================================
// ===========================================================================

gulp.task('tsLint', function () {
    return gulp.src(config.src.ts)
        .pipe(tslint())
        .pipe(tslint.report('verbose', {
            /*emitError: false*/
        }))
        .on('error', function (error) {
            util.log('TS lint failed, details:');
            util.log(error.message);

            if (!config.isInWatchMode)
                return process.exit(-1);
        });
});

gulp.task('ts', ['tsLint'], function () {
    var tsResult = gulp.src(config.src.ts)
        .pipe(gulpif(!config.isReleaseBuild, sourcemaps.init()))
        .pipe(tsc(tsProject));

    tsResult.dts.pipe(gulp.dest(config.dest.root.scripts));
    return tsResult.js
        .pipe(concat(config.dest.mainScriptName))
        .pipe(uglify())
        .pipe(gulpif(!config.isReleaseBuild, sourcemaps.write()))
        .pipe(gulp.dest(config.dest.root.scripts));
});

// Default task, run when no arguments are specified
gulp.task('default', ['styles', 'ts']);

`

Error console output:
[17:57:49] Using gulpfile C:_git\HouseConcert.Src\HouseConcert\Assets\gulpfile.js
[17:57:49] Starting 'tsLint'...
stream.js:74
throw er; // Unhandled stream error in pipe.
^

SyntaxError: Unexpected token 
at Object.parse (native)
at RcFinder.loader (C:_git\HouseConcert.Src\HouseConcert\Assets\node_modules\rcfinder\index.js:20:17)
at get (C:_git\HouseConcert.Src\HouseConcert\Assets\node_modules\rcfinder\index.js:68:18)
at respond (C:_git\HouseConcert.Src\HouseConcert\Assets\node_modules\rcfinder\index.js:122:22)
at C:_git\HouseConcert.Src\HouseConcert\Assets\node_modules\rcfinder\index.js:173:28
at C:_git\HouseConcert.Src\HouseConcert\Assets\node_modules\rcfinder\index.js:53:7
at FSReqWrap.oncomplete (fs.js:82:15)

TypeScript example code (if applicable):

function initialize(): void {
console.log('hi');
}

Does not seem to do anything

Hi,

I just got a fresh copy of gulp-tslint from npm. Unfortunately, when I pipe my .ts files into it, nothing seems to happen - even running your sample code does nothing:

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

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

I would at least expect some error since source.ts does not exist on my system.

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.