panuhorsmalahti / gulp-tslint

TypeScript linter plugin for Gulp
MIT License
118 stars 44 forks source link

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

Closed meriturva closed 8 years ago

meriturva commented 8 years ago

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

panuhorsmalahti commented 8 years ago

What version of tslint are you using? Seems to be a tslint issue, the line exists in a few rules, e.g. https://github.com/palantir/tslint/blob/master/src/rules/noShadowedVariableRule.ts#L72

meriturva commented 8 years ago

Tslint version 3.1.1. The same version installed globally without gulp works! So I think it is related to gulp integration. What could I check?

panuhorsmalahti commented 8 years ago

Can you post app.ts? And did you verify the tslint version from node_modules/tslint/package.json?

meriturva commented 8 years ago

Ok here more information:

  1. tslint version is 3.1.1 (i have check the file node_modules/tslint/package.json
  2. Here an update gulp script with the use directly of tslint and with gulp-tslint:
gulp.task('src-lint-ts', function () {

    var configuration = require('./tslint.json');

    var options = {
        formatter: "json",
        configuration: configuration
    };

    var fileName = 'wwwroot/src/app/app.ts';
    var Linter = require("tslint");
    var fs = require("fs");
    var contents = fs.readFileSync(fileName, "utf8");

    var ll = new Linter(fileName, contents, options);
    var result = ll.lint();

    console.log(result);
    console.log("-------------------------------------");

    return gulp.src('wwwroot/src/app/app.ts')
      .pipe(tslint())
      .pipe(tslint.report('verbose'));
});
  1. The file used for configuration is: https://github.com/panuhorsmalahti/gulp-tslint/blob/master/test/tslint.json
  2. The ouput is just correct when using tslint directly:
....

       failure: 'missing semicolon',
       ruleName: 'semicolon' } ],
  format: 'json',
  output: '[{"endPosition":{"character":4,"line":5,"position":188},"failure":"trailing whitespace","name":"wwwroot/src/app/app.ts","ruleName":"no-trailing-whitespace","startPosition":{"character":0,"line":5,"position":184}},{"endPosition":{"character":61,"line":0,"position":61},"failure":"\' should be \\"","name":"wwwroot/src/app/app.ts","ruleName":"quotemark","startPosition":{"character":42,"line":0,"position":42}},{"endPosition":{"character":19,"line":4,"position":181},"failure":"\' should be \\"","name":"wwwroot/src/app/app.ts","ruleName":"quotemark","startPosition":{"character":14,"line":4,"position":176}},{"endPosition":{"character":46,"line":17,"position":464},"failure":"\' should be \\"","name":"wwwroot/src/app/app.ts","ruleName":"quotemark","startPosition":{"character":27,"line":17,"position":445}},{"endPosition":{"character":1,"line":19,"position":502},"failure":"missing semicolon","name":"wwwroot/src/app/app.ts","ruleName":"semicolon","startPosition":{"character":1,"line":19,"position":502}}]' }
-------------------------------------
  1. Using gulp-tslint we have errors:
-------------------------------------
Process terminated with code 1.
stream.js:74
      throw er; // Unhandled stream error in pipe.
      ^
SyntaxError: Unexpected token 
    at Object.parse (native)
    at RcFinder.loader (...\node_modules\rcfinder\index.js:20:17)
    at get (...\node_modules\rcfinder\index.js:68:18)
    at respond ...\node_modules\rcfinder\index.js:122:22)
    at ...\node_modules\rcfinder\index.js:173:28
    at...\node_modules\rcfinder\index.js:53:7
    at FSReqWrap.oncomplete (fs.js:82:15)
  1. Here the app.ts file:
import {bootstrap, Component, View} from 'angular2/angular2';
import {LoginButton} from "./components/loginbutton/loginbutton";

@Component({
    selector: 'app',

})
    @View({
        directives: [LoginButton],
        template: `
            <loginbutton [currentuser]="'test'"></loginbutton>
        `
})
class AppComponent { }

bootstrap(AppComponent).then(
    success => console.log('app started!'),
    error => console.log(error)
)
meriturva commented 8 years ago

Ok i found the error....it is related to the tslint.json file. I had to rename tslint.json to tslint2.json even if we pass the configuration object to tslint. Secondly i really don't know with the json file generate JSON.parse error and require command not. So basically i could suggest to fix:

  1. when a configuration object is passed don't check and try to load tslint.json file
panuhorsmalahti commented 8 years ago

Hmm, I was also having an exception from tslint itself when updating the depencies.

At first I was getting the same exception when using both gulp-tslint and tslint, but then I upgraded typescript with npm install -g typescript adn the exception disappeared with tslint. The problem remained when using gulp-tslint, but it was using the 3.0.0 version of tslint due to devDependency semver. After I changed that I got rid of the exception I was getting.

Now I'll investigate your file.

panuhorsmalahti commented 8 years ago

I believe your error message would be clear if you return the gulp.src in your gulp.task. e.g., you should

gulp.task('invalid-noemit', function(){
    return gulp.src('invalid.ts')
        .pipe(tslint())
        .pipe(tslint.report('prose', {
            emitError: false
        }));
});

instead of

gulp.task('invalid-noemit', function(){
    gulp.src('invalid.ts')
        .pipe(tslint())
        .pipe(tslint.report('prose', {
            emitError: false
        }));
});

Not sure if you did that of course, just guessing.

EDIT: There's also #23 for better error message for invalid tslint files.

panuhorsmalahti commented 8 years ago

Added #45 for the suggestion.

meriturva commented 8 years ago

yes i did the "return"...thanks for the suggestion! Anyway now it works but i had to load the configuration file manually so now i have:

gulp.task('src-lint-ts', function (callback) {
    var configuration = require('./tslintconfig.json');

    return gulp.src('**/*.ts', { cwd: config.APP_SRC })
      .pipe(tslint({
          configuration:configuration          
      }))
      .pipe(tslint.report('verbose', {
          emitError: false
      }));
});
alexangas commented 8 years ago

It might be an idea to reopen this or create a new issue... Like @meriturva I'm getting the exact same "Unexpected token" error in RcFinder when using a file named "tslint.config". If I rename it then it works. I can't find any other workaround.