SlideShare a Scribd company logo
ENFORCING

CODING 

STANDARDS

in a JS PROJECT

Sebastiano Armeli
@sebarmeli 14/05/2015 - JSConf BD
to enforce
verb (used with object), enforced, enforcing.
to put or keep in force; to compel obedience to:

“to enforce a rule; Traffic laws will be strictly
enforced.”
Enforcing coding standards in a JS project
Enforcing coding standards in a JS project
standard
noun
a rule or principle that is used as a basis for judgment:

“They tried to establish standards for a new approach.”
Enforcing coding standards in a JS project
commit 111111
Author: Sebastiano Armeli
Date: Sun Dec 21 22:08:00
2014 -0500
adding something
commit 2222222
Author: Sebastiano Armeli
Date: Thu Dec 18 15:35:39
2014 -0500
it will work, trust me
myProject
|
|— module1.js
|— module2.js
|— module_3.js
|— module_4.js
|— module5.js
|— package.json
Enforcing coding standards in a JS project
defined by your team
Automate
http://facilitationjapan.com/wp-content/uploads/2013/09/consensus_building.jpg
AD LIBRARY
Enforcing coding standards in a JS project
Enforcing coding standards in a JS project
! IDE (Editorconfig)
! Quality & Style tools (JSHint, JSCS, ESLint)
! Git commits standards
! Build tools (Grunt, Gulp)
! Language - Transpiler (ES6 - Babel)
! Complexity tool (Plato)
Summary 1/2
! Testing (Mocha, Karma)
! Automated Release Flow (Jenkins, NPM)
! Setup script
! Documentation
Summary 2/2
Enforcing coding standards in a JS project
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
.editorconfig
Coding Style
& Quality Tools
Prevent bugs
Improve code maintainability 

& readability
Easy to use
function increment(a) {
return
a + 1;
}
increment(1); // undefined
BUG!!
var x = y = z = "example";
Leaking Variables!!
Enforcing coding standards in a JS project
{
"curly": true,
"eqeqeq": false,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"boss": true,
"indent": 2,
"noempty": true,
"expr": true,
"eqnull": true,
"esnext": true,
"browser": true,
"white": true,
"undef": true,
"predef": [ “require”, "module", “exports", "CustomEvent"]
}
.jshintrc
{
"curly": true,
"eqeqeq": false,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"boss": true,
"indent": 2,
"noempty": true,
"expr": true,
"eqnull": true,
"esnext": true,
"browser": true,
"white": true,
"undef": true,
"predef": [ “require”, "module", “exports", "CustomEvent"]
}
.jshintrc
{
"curly": true,
"eqeqeq": false,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"boss": true,
"indent": 2,
"noempty": true,
"expr": true,
"eqnull": true,
"esnext": true,
"browser": true,
"white": true,
"undef": true,
"predef": [ “require”, "module", “exports", "CustomEvent"]
}
.jshintrc
JSCS
{
"requireSpaceAfterKeywords": ["if", "else",
"for", "while", "do", "switch", "return", "try"],
"disallowImplicitTypeConversion": ["string"],
"disallowMultipleLineBreaks": true,
"disallowMixedSpacesAndTabs": true,
"disallowKeywords": ["with"],
"disallowMultipleVarDecl": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"maximumLineLength": 80,
"esnext": true
}
.jscsrc
{
"requireSpaceAfterKeywords": ["if", "else",
"for", "while", "do", "switch", "return", "try"],
"disallowImplicitTypeConversion": ["string"],
"disallowMultipleLineBreaks": true,
"disallowMixedSpacesAndTabs": true,
"disallowKeywords": ["with"],
"disallowMultipleVarDecl": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"maximumLineLength": 80,
"esnext": true
}
.jscsrc
{
"requireSpaceAfterKeywords": ["if", "else",
"for", "while", "do", "switch", "return", "try"],
"disallowImplicitTypeConversion": ["string"],
"disallowMultipleLineBreaks": true,
"disallowMixedSpacesAndTabs": true,
"disallowKeywords": ["with"],
"disallowMultipleVarDecl": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"maximumLineLength": 80,
"esnext": true
}
.jscsrc
Enforcing coding standards in a JS project
---
parser: babel-eslint
env:
browser: true
node: true
mocha: true
es6: true
.eslintrc
rules:
space-before-blocks: 2
eqeqeq: [2, 'smart']
curly: [2, 'multi-line']
quotes: [2, 'single']
space-after-keywords: 2
no-unused-vars: [2, args: none]
no-comma-dangle: 2
no-unused-expressions: 0
no-multi-spaces: 2
…
rules:
space-before-blocks: 2
eqeqeq: [2, 'smart']
curly: [2, 'multi-line']
quotes: [2, 'single']
space-after-keywords: 2
no-unused-vars: [2, args: none]
no-comma-dangle: 2
no-unused-expressions: 0
no-multi-spaces: 2
…
no-unused-vars: [2, args: none]
function test1(a, b) {
var c, d = 2;
return a + d;
}
test1(1, 2);
Error!!
function test2(a, b, c) {
return a + b;
}
test2(1, 2);
Ok
no-trailing-spaces: 2
no-mixed-spaces-and-tabs: 2
quotes: [2, ‘single’]
indent: [2, 2]
"use strict”;
module.exports = function(context) {
return {
"NewExpression": function(node) {
if (node.callee.name === "Object") {
context.report(node, “Error …”);
}
}
};
};
no-new-object.js
let obj = new Object(); let obj = {};
"use strict”;
module.exports = function(context) {
return {
"NewExpression": function(node) {
if (node.callee.name === "Object") {
context.report(node, “Error …”);
}
}
};
};
no-new-object.js
let obj = {};
Enforcing coding standards in a JS project
Git Commits
(feat | fix | docs | style | refactor | test | chore)(<scope>):

<description>
E.g.

doc(readme): update with additional links.
Changelog
conventional-changelog Changelog.md
commit 7aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Author: Sebastiano Armeli <xxx@yyy.com>
Date: Tue Jan 6 11:48:59 2015 -0500
refactor(BaseAd): Removed addToStreamTime method from
BaseAd
commit 7bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
Author: Sebastiano Armeli <xxx@yyy.com>
Date: Tue Jan 6 00:04:49 2015 -0500
style(gpt): rearrange for better readability
CHANGELOG.md
Build tool
gulp test / gulp dev
var gulp = require('gulp');
var plugins = require(‘gulp-load-plugins')();
…
gulp.task('eslint', function() {
return gulp.src(['src/**/*.js'])
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failOnError());
});
…
gulpfile.js
Enforcing coding standards in a JS project
gulp es6/src /dist
ES6 ES5
Plato
gulp plato
Testing
describe('#_onContainerResume', function() {
it('should call play when container resumes', function() {
videoAd.views.set(mockedVideoAdMetadata.id, {
play: function() {},
hasBeenPlayed: true
});
sinon.stub(videoAd.views.get(mockedVideoAdMetadata.id), 'play');
videoAd._onContainerResume();
expect(videoAd.views.get(mockedVideoAdMetadata.id).play).to.have
.been.called;
});
});
module.exports = function(config) {
config.set({
basePath: '../',
frameworks: ['mocha', 'fixture'],
files: [
….
],
browsers: ‘Chrome’,
singleRun: false,
preprocessors: {
'**/*.html': ['html2js'],
'**/*.json': ['html2js']
},
sauceLabs: {
…
}
});
};
karma.conf.js
module.exports = function(config) {
config.set({
basePath: '../',
frameworks: ['mocha', 'fixture'],
files: [
….
],
browsers: ‘Chrome’,
singleRun: false,
preprocessors: {
'**/*.html': ['html2js'],
'**/*.json': ['html2js']
},
sauceLabs: {
…
}
});
};
karma.conf.js
module.exports = function(config) {
config.set({
basePath: '../',
frameworks: ['mocha', 'fixture'],
files: [
….
],
browsers: ‘Chrome’,
singleRun: false,
preprocessors: {
'**/*.html': ['html2js'],
'**/*.json': ['html2js']
},
sauceLabs: {
…
}
});
};
karma.conf.js
Automated Release flow
gulp test:ci gulp bump:path
gulp bump:minor
gulp bump:major
Changelog.md
./setup.sh
pre-commit hook
+
npm i && gulp test
Documentation
README.md
CONTRIBUTING.md
Documentation
README.md
CONTRIBUTING.md
/doc
Sebastiano Armeli <…@spotify.com>
Brice Lin <..@spotify.com> <…@gmail.com>
Jason Palmer <..@spotify.com> <..@spotify.com>
Joseph Werle <..@spotify.com> <…@gmail.com>
Olof Kihlberg <…@spotify.com>
Sigfrido Chirinos <…@spotify.com>
.mailmap
Enforcing coding standards in a JS project
Sebastiano Armeli
@sebarmeli

More Related Content

PDF
Cache is King - RubyHACK 2019
PDF
Cache is King: RubyConf Columbia
PDF
DEF CON 23 - amit ashbel and maty siman - game of hacks
PDF
Real World Mocking In Swift
PDF
Rapid web development, the right way.
PDF
Thanksgiving role play-hollaus
PPTX
Vacademia 13 3 нн 2015
PPT
vAcademia 2015
Cache is King - RubyHACK 2019
Cache is King: RubyConf Columbia
DEF CON 23 - amit ashbel and maty siman - game of hacks
Real World Mocking In Swift
Rapid web development, the right way.
Thanksgiving role play-hollaus
Vacademia 13 3 нн 2015
vAcademia 2015

Viewers also liked (20)

PPSX
Bmd opdracht 2
PPT
ЭОР нового поколения по Химии
PPT
Cscl m mlab-2011
DOC
Violència bullying
PPT
Icalt2002 2
DOC
A native american_welcome
PPTX
Bmd opdracht 2
PPSX
Bmd opdracht 6.1
PPSX
Build my dream 4 opdracht 04
PPSX
Build my dream 4 opdracht 02 show 02
PPSX
BMD opdracht 1
PPTX
Climate change
PPSX
Bmd opdracht 4
PPSX
Bmd 6 o1 show
PPSX
Build my dream 4 opdracht 01
PPSX
Bmd opdracht 5
PDF
Halloween story
Bmd opdracht 2
ЭОР нового поколения по Химии
Cscl m mlab-2011
Violència bullying
Icalt2002 2
A native american_welcome
Bmd opdracht 2
Bmd opdracht 6.1
Build my dream 4 opdracht 04
Build my dream 4 opdracht 02 show 02
BMD opdracht 1
Climate change
Bmd opdracht 4
Bmd 6 o1 show
Build my dream 4 opdracht 01
Bmd opdracht 5
Halloween story
Ad

Similar to Enforcing coding standards in a JS project (20)

PDF
前端MVC之BackboneJS
PDF
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
PPT
AngularJS and SPA
PDF
Node.js for enterprise - JS Conference
PPTX
Introduction à AngularJS
PDF
Boost delivery stream with code discipline engineering
PPTX
A Guide to Event-Driven SRE-inspired DevOps
PPTX
Azure from scratch part 4
PDF
Webpack Encore - Asset Management for the rest of us
PDF
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
PDF
PPTX
Good karma: UX Patterns and Unit Testing in Angular with Karma
PPT
AngularJS for Legacy Apps
PDF
Automated Tests and CSS
PDF
OOScss Architecture For Rails Apps
PDF
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
PDF
Wt unit 2 ppts client side technology
PDF
Wt unit 2 ppts client sied technology
PDF
Node.js vs Play Framework
PDF
Packing it all: JavaScript module bundling from 2000 to now
前端MVC之BackboneJS
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
AngularJS and SPA
Node.js for enterprise - JS Conference
Introduction à AngularJS
Boost delivery stream with code discipline engineering
A Guide to Event-Driven SRE-inspired DevOps
Azure from scratch part 4
Webpack Encore - Asset Management for the rest of us
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Good karma: UX Patterns and Unit Testing in Angular with Karma
AngularJS for Legacy Apps
Automated Tests and CSS
OOScss Architecture For Rails Apps
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Wt unit 2 ppts client side technology
Wt unit 2 ppts client sied technology
Node.js vs Play Framework
Packing it all: JavaScript module bundling from 2000 to now
Ad

More from Sebastiano Armeli (12)

PDF
Managing a software engineering team
PDF
Enforcing coding standards
PDF
ES6: The future is now
PDF
EcmaScript 6 - The future is here
PDF
Dependency management & Package management in JavaScript
PDF
Karma - JS Test Runner
PDF
KEY
Lazy load Everything!
KEY
MVC on the server and on the client
KEY
Backbone.js in a real-life application
KEY
Getting started with Selenium 2
PDF
Web Storage
Managing a software engineering team
Enforcing coding standards
ES6: The future is now
EcmaScript 6 - The future is here
Dependency management & Package management in JavaScript
Karma - JS Test Runner
Lazy load Everything!
MVC on the server and on the client
Backbone.js in a real-life application
Getting started with Selenium 2
Web Storage

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
Teaching material agriculture food technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
cuic standard and advanced reporting.pdf
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Modernizing your data center with Dell and AMD
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
The AUB Centre for AI in Media Proposal.docx
cuic standard and advanced reporting.pdf
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Monthly Chronicles - July 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Review of recent advances in non-invasive hemoglobin estimation
Modernizing your data center with Dell and AMD
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx

Enforcing coding standards in a JS project