Hi all,
I started a new project with ionic.
As it grows i want to prevent from making errors like arr.push[3] instead of arr.push(3).
For this purpose i may use jshint.
How do i integrate it in the ionic process, so that after each file change ionic serve runs jshint and will warn me on mistakes?
Thanks,
David
1 Like
So adding jsLint/Hint isnât a too difficult,
- make a project and cd into it
- run
npm install
- run
npm install gulp-jshint jshint-stylish --save-dev
- edit
gulpfile.js
to include var jshint = require('gulp-jshint');
- then add this gulp taks:
gulp.task('lint', function() {
return gulp.src('./www/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
Note that jshint-stylish isnât required, but make the output much more legible.
Now you can run gulp lint
and see where your errors are.
Its my result after ran âgulp lintâ:
[22:47:25] Using gulpfile e:\mypath
[22:47:25] Starting âlintââŚ
[22:47:26] Finished âlintâ after 633 ms
Whatâs wrong from me?
Try this!
function handleError(err){
'use strict';
console.log(err.toString());
}
gulp.task('lint', function() {
return gulp.src('./www/js/*.js')
.pipe(jshint())
.on('error', handleError)
.pipe(jshint.reporter('jshint-stylish'));
});
Hi, I get the error: Cannot find module âbowerâ. Any suggestions? Thanks.
I used this and it works great thank you! I have a bunch of seperate modules so the src to the js folder wouldnât work for me so my code looks like this:
function handleError(err){
'use strict';
console.log(err.toString());
}
gulp.task('lint', function() {
return gulp.src('./www/*/*.js')
.pipe(jshint())
.on('error', handleError)
.pipe(jshint.reporter('jshint-stylish'));
});
Iâm not sure if this is the prefered way of doing things but it helped me access all of my js files that were one level deeper in the www folder.