Don't commit your ugly code.
A guide for writing cleaner code.
Troy M. Connor / troy0820
@troy0820
I play work with robots while writing JavaScript stuff at Emerging Technology Advisors
Ugly Code?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2371370/ugly.gif)
"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?"
~ Brian Kernighan
ESLINT
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2371699/lint.gif)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2371706/Screen_Shot_2016-03-20_at_6.21.27_PM.png)
Text
Text
http://github.com/eslint
ESLINT
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2371743/Screen_Shot_2016-03-20_at_6.30.37_PM.png)
What do you need?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2371894/Screen_Shot_2016-03-20_at_7.47.18_PM.png)
npm install -g eslint
3 ways to configure
//terminal
eslint --init
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2371915/Screen_Shot_2016-03-20_at_8.08.12_PM.png)
3 ways to configure
//.eslintrc.json
{
"extends": "eslint: recommended"
}
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2371920/Screen_Shot_2016-03-20_at_8.10.26_PM.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2371928/Screen_Shot_2016-03-20_at_8.13.05_PM.png)
3 ways to configure
//package.json
eslintConfig: {
"extends": "eslint:recommended"
}
Environments
{
"env": {
"browser": true,
"node": true
}
}
http://eslint.org/docs/user-guide/configuring#specifying-environments
Plugins
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2372075/Screen_Shot_2016-03-20_at_9.45.48_PM.png)
//.eslintrc.js
"plugins": ['react']
Shareable eslint configs
- eslint-config-airbnb
- eslint-config-eta
- eslint-config-trails
- eslint-config-standard
Okay, you're set up......, or so you think
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2372112/denzel.gif)
How do I use it?
//terminal
eslint . --ext .js
//package.json
{
"scripts": {
"lint": "eslint . --ext .js"
}
}
npm run lint
//gulpfile.js
var gulp = require('gulp'),
eslint = require('gulp-eslint');
gulp.task('lint', function () {
return gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('default', ['lint'], function () {
});
How do I use it?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2372175/Screen_Shot_2016-03-20_at_10.56.40_PM.png)
//terminal
eslint {fileName} --fix
.editorConfig
//.editorConfig
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# Change these settings to your own preference
indent_style = space
indent_size = 2
# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
http://editorconfig.org/
Going to eslint 2.0
//removed rules
no-arrow-condition is replaced by a combination of no-confusing-arrow and no-constant-condition. Turn on both of these rules to get the same functionality as no-arrow-condition.
no-empty-label is replaced by no-labels with {"allowLoop": true, "allowSwitch": true} option.
space-after-keywords is replaced by keyword-spacing.
space-before-keywords is replaced by keyword-spacing.
space-return-throw-case is replaced by keyword-spacing.
{
parserOptions: {
ecmaVersion: 6
}
}
//new rules in recommended
constructor-super
no-case-declarations
no-class-assign
no-const-assign
no-dupe-class-members
no-empty-pattern
no-new-symbol
no-self-assign
no-this-before-super
no-unexpected-multiline
no-unused-labels
DEMO TIME!!!
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2372131/yes.gif)
When it works
![](https://s3.amazonaws.com/media-p.slid.es/uploads/472466/images/2372166/thankyou.gif)
Don't commit your ugly code
By Troy M. Connor
Don't commit your ugly code
- 2,433