# Code validation, conventions, linting

> Date 16/09/2014

[First assignment is given.](https://paazmaya.gitbook.io/modern-web-tools-with-node-js/assignments/1-command-line)

## Why code style, validation and linting matters?

Whether there is just one or more developers working on a given code base, over time it comes difficult to read one's own code if the code style differs. Any shared code should follow certain style guides for making it consistent.

Code validation checks against syntax failures, possible naming collitions and other relevant things that might be needed in order for the code to work in a given set of environments. What works in one browser, might not work in another.

For Node.js, the environment is somewhat stable and while updating patch level (`0.0.x`) versions, should not break existing code. Also since is is always made from the same basic components, namely [V8](https://code.google.com/p/v8/), it has somewhat similar runtime expectations between minor (`0.x.0`) versions.

Code linting validates and evaluates code against a set of given rules, usually based on code style and validation best practises, as well as personal taste.

## Tasks for the day

Use the repository `hello-node-js` that was created during the previous lecture.

1. Automatic Semicolon Insertion (ASI) is a handy helper found in many browsers, but it is usually best to be avoided
   * Found out about ASI and write about it few lines in your `README.md`
   * Validate your code, `task-*.js` files against ASI and add a validation configuration file in your repository
2. Choose an existing Node.js module from [npm](https://www.npmjs.com/) which does not have code validation included
   * Create a fork from its source
   * Add code validation configuration, which would approximately match the existing code style used in that module
   * Optional: Create pull request to the module
   * Link your pull request or fork to [the list below](#links-to-the-pull-requests-and-forks-made-for-task-2)
3. Take a look at the source codes of the following linters and observe how they are achieving similar

   things differently. Then write down in your `hello-node-js` repository `linters-study.md` file

   about the similarities and differences, as well as external module usage.

   Write a short configuration example how to prevent ASI failures, for each three linters

   * [jslint](http://jslint.com/)
   * [JSHint](http://jshint.com/)
   * [ESLint](http://eslint.org/)
4. Optional: Write a rule for one of the three linters
   * Create a new repository or clone the original linter project
   * Instead of using the `master` branch, create a new branch with name of your new rule, prepended by `rule-`
   * Feeling adventurous: create a pull request to the linter project for adding your rule in it.

## Links to the pull requests and forks made for task 2

* [ESLint validation added to node-easyimage](https://github.com/hacksparrow/node-easyimage/pull/39) / Heikki Alanen
* [JSHint validation added to ncht](https://github.com/nenv/ncht/pull/1) / Joonas Meriläinen
* [ESLint validation added to gulp-minify-css](https://github.com/jukra/gulp-minify-css/commit/f59052132eccd2d85a6140e0c2db3756e8ed1cf2) / Jukka Rautanen
* [JSHint validation added to async](https://github.com/mpiivonen/async) / Markus Iivonen
* [JSHint validation added to Lo-Dash](https://github.com/Markoham/lodash/commit/93405e7dfceca7b11dcc67c134907d516c9738f4) / Marko Hamppula
* [Toomaksen pull request](https://github.com/tfjorge/tellki-agent)

## Links related to the lecture subject

* [A Bit of Advice for the JavaScript Semicolon Haters](http://benalman.com/news/2013/01/advice-javascript-semicolon-haters/)
* [winning style](https://github.com/Seravo/js-winning-style)
* [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)
* [JavaScript Code Style checker](https://github.com/jscs-dev/node-jscs)
* [Create a new branch with git and manage branches](https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches)
* [ESLint Rules List, with comparison of jslint, jscs and JSHint equivalents](https://docs.google.com/spreadsheet/ccc?key=0Ap5QGaRT4AJ_dGV6VXBlMEw3NHhVRl9vQ0lIX2FnVlE\&usp=drive_web#gid=0)

## Examples for the tasks
