2

I have been following the tutorials from Dan Wahlin and the online examples to configure Gulp and Typescript. I have the code running, but I am unable to get tslint() to work. The tslint() call always throws an exception:

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] (C:\Users\sscott\Development\OntarioDarts.com\node_modules\tslint\lib\language\walker\ruleWalker.js:18:37)
at EnableDisableRulesWalker.SkippableTokenAwareRuleWalker [as constructor] (C:\Users\sscott\Development\OntarioDarts.com\node_modules\tslint\lib\language\walker\skippableTokenAwareRuleWalker.js:11:16)
at new EnableDisableRulesWalker (C:\Users\sscott\Development\OntarioDarts.com\node_modules\tslint\lib\enableDisableRules.js:13:16)
at Linter.lint (C:\Users\sscott\Development\OntarioDarts.com\node_modules\tslint\lib\tslint.js:16:27)
at C:\Users\sscott\Development\OntarioDarts.com\node_modules\gulp-tslint\index.js:96:34
at respond (C:\Users\sscott\Development\OntarioDarts.com\node_modules\rcloader\index.js:73:7)
at respond (C:\Users\sscott\Development\OntarioDarts.com\node_modules\rcfinder\index.js:140:7)
at next (C:\Users\sscott\Development\OntarioDarts.com\node_modules\rcfinder\index.js:164:16)
at nextTickCallbackWith0Args (node.js:433:9)
at process._tickCallback (node.js:362:13)

I am using Windows 10. I have typescript, tslint, gulp-typescript and gulp-tslint.

Installed Versions:

├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│   └─┬ [email protected]
│     └─┬ [email protected]
│       └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│   └── [email protected]
└── [email protected]

Gulp task:

module.exports = function (gulp, PlugIns, Settings) {
    return function () {
        gulp.src([Settings.SourceFiles.TypeScript])
            .pipe(PlugIns.plumber())
            .pipe(PlugIns.debug())
            .pipe(PlugIns.typescript())

            .pipe(PlugIns.tslint( {
                configuration: {
                    rules: {
                        "class-name": true,
                        "comment-format": [
                            true,
                            "check-space",
                            "check-uppercase"
                        ],
                        "curly": true,
                        "eofline": true,
                        "indent": [
                            true,
                            "tabs"
                        ],
                        "jsdoc-format": true,
                        "max-line-length": 100,
                        "no-unreachable": true,
                        "no-unused-expression": true,
                        "no-unused-variable": true,
                        "no-use-before-declare": true,

                        "one-line": [
                            true,
                            "check-open-brace",
                            "check-catch",
                            "check-else",
                            "check-whitespace"
                        ],
                        "quotemark": [
                            true,
                            "single",
                            "avoid-escape"
                        ],
                        "semicolon": true,
                        "switch-default": true,

                        "variable-name": [
                            true,
                            "allow-trailing-underscore",
                            "ban-keywords"
                        ],
                        "whitespace": [
                            true,
                            "check-branch",
                            "check-decl",
                            "check-operator",
                            "check-separator",
                            "check-type"
                        ]
                    }
                }
            }))
            .pipe(PlugIns.tslint.report("stylish"))
            .pipe(gulp.dest(Settings.Destination.TSCompiled))
        ;
    }
};

1 Answer 1

8

This error often occurs if TSLint is told to process a file that doesn't end in a .ts or a .tsx extension. I would make sure that you aren't accidentally sending any .js files or files with other extensions. It's possible in the future that .js files work correctly, but right now they won't.

In addition, I would try running TSLint from the command line with the same configuration on a few of your files. If it's not working correctly like this, it could indicate a TSLint bug.

Sign up to request clarification or add additional context in comments.

3 Comments

I changed my file to try to only process one file, which failed the same way on a .ts and a .tsx. However, tslint does work from the command line as you suggested. I have logged a bug with gulp-tslint. github.com/panuhorsmalahti/gulp-tslint/issues/52
As I cannot edit my last comment now due to age, the issue with gulp-tslint has been corrected and works with the newer versions.
Thanks for the answer! When using tslint src/ts/Person.ts linting worked for me. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.