ionic-team / ionic-gulp-tasks

Collection of gulp tasks for building Ionic apps
41 stars 33 forks source link

Ionic Gulp ESLint Task #11

Closed devilleweppenaar closed 8 years ago

devilleweppenaar commented 8 years ago

I made a task for linting code via ESLint: ionic-gulp-eslint

Example gulpfile.js:

var gulp = require('gulp'),
    gulpWatch = require('gulp-watch'),
    del = require('del'),
    runSequence = require('run-sequence'),
    argv = process.argv;

/**
 * Ionic hooks
 * Add ':before' or ':after' to any Ionic project command name to run the specified
 * tasks before or after the command.
 */
gulp.task('serve:before', ['watch']);
gulp.task('emulate:before', ['build']);
gulp.task('deploy:before', ['build']);
gulp.task('build:before', ['build']);

// we want to 'watch' when livereloading
var shouldWatch = argv.indexOf('-l') > -1 || argv.indexOf('--livereload') > -1;
gulp.task('run:before', [shouldWatch ? 'watch' : 'build']);

/**
 * Ionic Gulp tasks, for more information on each see
 * https://github.com/driftyco/ionic-gulp-tasks
 *
 * Using these will allow you to stay up to date if the default Ionic 2 build
 * changes, but you are of course welcome (and encouraged) to customize your
 * build however you see fit.
 */
var buildBrowserify = require('ionic-gulp-browserify-es2015');
var buildSass = require('ionic-gulp-sass-build');
var copyHTML = require('ionic-gulp-html-copy');
var copyFonts = require('ionic-gulp-fonts-copy');
var copyScripts = require('ionic-gulp-scripts-copy');
var eslint = require('ionic-gulp-eslint');

gulp.task('watch', ['clean'], function(done){
  runSequence(
    ['sass', 'html', 'fonts', 'scripts', 'lint'],
    function () {
      gulpWatch('app/**/*.js', function(){ gulp.start('lint'); });
      gulpWatch('app/**/*.scss', function(){ gulp.start('sass'); });
      gulpWatch('app/**/*.html', function(){ gulp.start('html'); });
      buildBrowserify({ watch: true }).on('end', done);
    }
  );
});

gulp.task('build', ['clean'], function(done){
  runSequence(
    ['sass', 'html', 'fonts', 'scripts', 'lint'],
    function(){
      buildBrowserify().on('end', done);
    }
  );
});
gulp.task('lint', eslint);
gulp.task('sass', buildSass);
gulp.task('html', copyHTML);
gulp.task('fonts', copyFonts);
gulp.task('scripts', copyScripts);
gulp.task('clean', function(){
  return del('www/build');
});

Example .eslintrc:

{
  "extends": "eslint:recommended",
  "env": {
    "node": true
  },
  "parser": "babel-eslint",
  "parserOptions": {
      "sourceType": "module"
  },

  "rules": {
    // overrides from 'recommended'
    "indent": [1, "tab"],
    "max-len": [2, 140, 4, {"ignoreUrls": true, "ignoreComments": false}],

    "comma-dangle": 0,
    "no-console": 0,

    // strict
    "strict": [2, "global"],

    // formatting, spaces, operators
    "quotes": [2, "single"],
    "semi": [2, "always"],
    "keyword-spacing": 2,
    "space-before-blocks": [2, "always"],
    "space-before-function-paren": [2, "never"],
    "dot-location": [2, "property"],
    "space-infix-ops": 2,
    "key-spacing": [2, {"beforeColon": false, "afterColon": true}],
    "operator-linebreak": [2, "after"],
    "no-spaced-func": 2,
    "comma-spacing": [1, {"before": false, "after": true}],
    "no-multiple-empty-lines": [2, {"max": 2}],
    "camelcase": [1, {"properties": "always"}],

    // coding style
    "curly": 2,
    "wrap-iife": [2, "inside"],
    "eqeqeq": 2,
    "no-use-before-define": [2, "nofunc"],
    "no-unused-vars": 2,
    "no-unexpected-multiline": 2,
    "no-multi-str": 2,
    "no-irregular-whitespace": 2,

    // os/git options
    "no-trailing-spaces": 2,
    "linebreak-style": [2, "unix"],
    "eol-last": 2
  }
}
tlancina commented 8 years ago

Woot! Added to the README, thanks!

As far as integration with the starters goes, we'll be looking into adding options for starting with tests, linting etc. but for now by default they won't have it.