Closed meriturva closed 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
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?
Can you post app.ts? And did you verify the tslint version from node_modules/tslint/package.json
?
Ok here more information:
node_modules/tslint/package.json
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'));
});
https://github.com/panuhorsmalahti/gulp-tslint/blob/master/test/tslint.json
....
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}}]' }
-------------------------------------
-------------------------------------
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)
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)
)
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:
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.
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.
Added #45 for the suggestion.
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
}));
});
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.
I'm just try a simple gulp task....
no special src, no special pipe.....really simple and i see the error:
I have tried the same tslint.json configuration directly with tslint:
tslint app.ts
without any errors! Ps: i'm on windows