I’ve noticed that I am a loose coder on my personal projects but want some level of decorum on Mozilla and other open source projects. The more developers you have contributing to a project, the tighter the ship you must keep. The easiest way to do that is requiring contributions to meet a certain code convention criteria via a tool like ESLint. Since I like to use gulp.js for my build process, I thought I’d share a very basic use of ESLint for your project.
You start by adding ESLint to your package.json file or installing via NPM manually:
npm install gulp-eslint
With ESLint available somewhere within the node path, you can set up a lint task within your gulpfile.js:
gulp.task('lint', function() {
return gulp.src('lib/**').pipe(eslint({
'rules':{
'quotes': [1, 'single'],
'semi': [1, 'always']
}
}))
.pipe(eslint.format())
// Brick on failure to be super strict
.pipe(eslint.failOnError());
});
You can get a full list of rules and possible values here. How strict you want to be depends on your general philosophy within JavaScript. Many people make lint a part of their test task as well so that travis-ci can reject code that isn’t up to snuff.
Now that I’ve written this post, I’ll probably take the time to add ESLint to my personal projects so that I can get in the habit of always coding to a certain standard. Practice makes perfect!
The post Adding ESLint with gulp.js appeared first on David Walsh Blog.
Source: David Walsh