panuhorsmalahti / gulp-tslint

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

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

Closed Chowarmaan closed 8 years ago

Chowarmaan commented 8 years ago

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
panuhorsmalahti commented 8 years ago

Can you post the version of tslint at ~\Development\node_modules\tslint\ and the version of TypeScript used (perhaps located in ~\Development\node_modules\typescript)? Usually this kind of error happens due to a tslint and TypeScript version mismatch. Try to update them to the latest versions.

Chowarmaan commented 8 years ago

├─┬ tslint@3.2.1 │ ├── glob@6.0.4 │ ├─┬ optimist@0.6.1 │ │ ├── minimist@0.0.10 │ │ └── wordwrap@0.0.2 │ └── underscore.string@3.1.1 └── typescript@1.7.5

These are local to the project.

panuhorsmalahti commented 8 years ago

Can you post the output of tslint -v? Note that running tslint from the command line may use a different version than what is under node_modules of the current directory.

For example:

nawi ~/dev/gulp-tslint cat node_modules/tslint/package.json | grep version 
  "version": "3.2.1"
nawi ~/dev/gulp-tslint tslint -v
3.1.1
nawi ~/dev/gulp-tslint which tslint
/usr/local/bin/tslint
Chowarmaan commented 8 years ago

~\Development>cat node_modules/tslint/package.json | grep version "version": "3.2.1"

node_modules.bin\tslint -v 3.2.1

panuhorsmalahti commented 8 years ago

Hi, sorry to both again, but I meant the output of tslint -v, not node_modules.bin\tslint -v (I'm not quite sure if they're the same thing for you).

Chowarmaan commented 8 years ago

Sorry, running just tslint gives an error as I did not install it globally, it is only in the project directory which is why I added the second line with the node_modules.bin\tslint -v.

I added typescript and tslint to the global install, and the same error occurs. The tslint -v when installed globally still returns 3.2.1

panuhorsmalahti commented 8 years ago

Can you try again with the latest versions of gulp-tslint and tslint?

Chowarmaan commented 8 years ago

Using the latest version, 3.7.4 has this problem solved. It is working properly.