JavaScript CodeStyle. Automatically!

Varya Stepanova, SC5 Online

JavaScript CodeStyle. Automatically!

in use at SC5

me

Varya Stepanova

Senior Frontend Developer @ SC5 Online

Codestyle is important

You develop but you don’t code with respect

You don’t even follow the codestyle

JavaScript linting tools

JSHint ❤ JSCS

JSLint

gulp.task('jslint',
  [ 'jshint', 'jscs' ]
);

JSCS in use

JSCS

$ npm install jscs

.jscsrc presets

{
    "preset": "airbnb",
    /*
    "preset": crockford,
    "preset": google,
    "preset": jquery,
    "preset": mdcs,
    "preset": wikimedia,
    "preset": yandex
    */
}

to exclude

{
    "preset": "airbnb",

    "excludeFiles": [
      "node_modules/**"
    ]
}

to extend

{
    "preset": "airbnb",

    "validateIndentation": 2,
    "requireMultipleVarDecl": true,

    "excludeFiles": [
      "node_modules/**"
    ]

}

In use

One by one

{
    ...

    "excludeFiles": [
      "node_modules/**",
      "src/modules/a/**",
      "src/modules/b/**",
      "src/*.js
    ]
}

Pushy

Division of responsibility

upstream repository

must be clean

  • Pull requests
  • Travis

your fork

may be clean

  • Editor
  • Pre-comit hooks

Editor plugins

Travis builds

Some tips

In of memory

gulp.task('jscs', function() {
  return gulp.src([
    '**/*.js'
  ])
  .pipe(gulpIgnore.exclude([
    'node_modules/**',
    'demo-output/**'
  ]))
  .pipe(jscs());
});

Never stop watching

gulp.task('jscs', function() {
  return gulp.src([
    '**/*.js'
  ])
  ...
  .pipe(plumber())
  .pipe(jscs());
});

JSCS

JSCS in use

Varya Stepanova, SC5 Online

varya.me/jscs-talk

Fork me on Github