gulp-tslint: Error when running rules that require type info
typescript version: 2.1.5
gulp-tslint version: 7.0.1
tslint version: 4.4.1
Operating system: Windows 10
Whenever I enable any tslint rule that require type info, I get the error shown below.
Example: "restrict-plus-operands": true
Am I setting this up correctly? Rules that don not require type info seem to work just fine.
Gulp configuration
const gulp = require("gulp");
const gulpTslint = require("gulp-tslint");
const ts = require("gulp-typescript");
const tslint = require("tslint");
const tsProject = ts.createProject("./tsconfig.json");
gulp.task("lint", () => {
const tslintProgram = tslint.Linter.createProgram("./tsconfig.json", ".");
const tsResult = tsProject.src()
.pipe(gulpTslint({
formatter: "stylish",
program: tslintProgram
}))
.pipe(gulpTslint.report({
emitError: false,
reportLimit: 50
}))
.pipe(tsProject());
return tsResult.js.pipe(gulp.dest("./"));
});
Error console output:
[07:42:23] Using gulpfile C:\<my-project>\gulpfile.js
[07:42:23] Starting 'lint'...
stream.js:74
throw er; // Unhandled stream error in pipe.
^
TypeError: Cannot read property 'name' of undefined
at getSignatureFromDeclaration (C:\<my-project>\node_modules\typescript\lib\typescript.js:28873:47)
at getThisTypeOfDeclaration (C:\<my-project>\node_modules\typescript\lib\typescript.js:27447:43)
at checkThisExpression (C:\<my-project>\node_modules\typescript\lib\typescript.js:34029:32)
at checkExpressionWorker (C:\<my-project>\node_modules\typescript\lib\typescript.js:38187:28)
at checkExpression (C:\<my-project>\node_modules\typescript\lib\typescript.js:38165:42)
at checkNonNullExpression (C:\<my-project>\node_modules\typescript\lib\typescript.js:35540:24)
at checkPropertyAccessExpressionOrQualifiedName (C:\<my-project>\node_modules\typescript\lib\typescript.js:35587:24)
at checkPropertyAccessExpression (C:\<my-project>\node_modules\typescript\lib\typescript.js:35554:20)
at checkExpressionWorker (C:\<my-project>\node_modules\typescript\lib\typescript.js:38208:28)
at checkExpression (C:\<my-project>\node_modules\typescript\lib\typescript.js:38165:42)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 25 (2 by maintainers)
@lddubeau !!! That was the key! Why isn’t this documented anywhere in this project?
Here’s my now working gulp task that can lint type-checked rules!
IMO, this configuration should be baked in to the gulp-tslint project. since
typescriptandtslintare dependencies anyway, this could just happen internally if it was passed the info needed to create the program.Here’s my ideal setup for how I think this should work
The problem is that how to activate type checking through the programmatic API is mostly undocumented. The README gives an example which suggests that the only thing needed is a program but that’s not the case at all. TypeScript’s
getPreEmitDiagnosticsmust also be called with the program, because this is what produces the type information that the rules later use.Like others who commented here I’ve tried everything and got nowhere fast until I added
ts.getPreEmitDiagnostics(program);to my Gulp task before startinggulp-tslint, and then I started getting errors generated by the rules that need type checking.The solution from @chrismbarr doesn’t work on my end. It still gives me an error:
Yep, I’am also having the same issue.
@m-sureshraj if you want you can inject the tsconfig JSON into your gulpfile so you only need to modify it at one location
Having the same issue here
Invalid source file: main.ts. Ensure that the files supplied to lint have a .ts, .tsx, .js or .jsx extension.Same bug here !
I’m having the same issue. Tried without
const tsProject = ts.createProject("./tsconfig.json"); and .pipe(tsProject());and several other combinations and still the same result.