Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit f741ea9

Browse files
author
fractaltheory
committed
Merge pull request #44 from mobify/eslint
Removes JSCS/JSHint in favor of ESLint
2 parents 16ea780 + 7ee1ede commit f741ea9

2 files changed

Lines changed: 123 additions & 20 deletions

File tree

README.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,28 @@ A repo to document code standards for different languages and provide tools for
66

77
## JavaScript
88

9-
Typically we lint our javascript files using [Grunt](http://gruntjs.com/). We have two javascript linters with different features. [jshint](https://github.com/gruntjs/grunt-contrib-jshint) and [jscs](https://github.com/gustavohenke/grunt-jscs).
9+
Typically, we lint our javascript files using [Grunt](http://gruntjs.com/) and [grunt-eslint](https://github.com/sindresorhus/grunt-eslint). grunt-eslint is a Grunt helper for the [ESLint](http://eslint.org/) linter.
1010

1111
To add javascript linting to your project:
1212

13-
1. Install the NPM `mobify-code-style`, `grunt-contrib-jshint`, and `grunt-contrib-jscs` modules.
13+
1. Install the NPM `mobify-code-style` and `grunt-eslint` modules.
1414
2. Create a [Gruntfile](http://gruntjs.com/sample-gruntfile) if you don't have one already.
15-
3. In the initConfig of your gruntfile, add sections for jshint and/or jscs pointing to the correct linting file.
15+
3. In the initConfig of your gruntfile, add a section for eslint pointing to the correct linting file.
1616

17-
Sample jshint config:
17+
Sample eslint config:
1818

1919
```javascript
20-
jshint:{
20+
eslint:{
2121
dev: {
2222
src: ['src/**/*.js'],
2323
options: {
24-
// The task fails if force is set to false. With true, it shows the
25-
// linting errors, but continues
26-
force: false,
27-
jshintrc: 'node_modules/mobify-code-style/javascript/.jshintrc'
24+
// When true, eslint will test _only_ the rules set in the provided
25+
// configuration file
26+
reset: false,
27+
config: 'node_modules/mobify-code-style/javascript/.eslintrc'
2828
}
2929
}
3030
}
3131
```
32-
33-
Sample jscs config:
34-
35-
```javascript
36-
jscs: {
37-
options: {
38-
config: 'node_modules/mobify-code-style/javascript/.jscsrc'
39-
},
40-
src: ['src/**/*.js']
41-
}
42-
```
4332
## CSS
4433
Our Client Services team's [CSS Style Guide](/css/Readme.md). Written with a lot of tender care by @kpeatt and @jeffkamo.

javascript/.eslintrc

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"browser": true,
5+
"amd": true,
6+
"mocha": true,
7+
"jquery": true
8+
},
9+
"globals": {
10+
"Mobify": true,
11+
"Zepto": true,
12+
"Adaptive": true
13+
},
14+
"rules": {
15+
// Enforce === instead of ==; !== instead of !=
16+
"eqeqeq": 2,
17+
18+
// Enforce if statement within 'for in'
19+
"guard-for-in": 2,
20+
21+
// Disallow overwriting native types like 'Array' or 'Date'
22+
"no-extend-native": 2,
23+
24+
// Enforce wrapping immediate invocations in parentheses
25+
"wrap-iife": 2,
26+
27+
// Disallow usage of a variable before declaration; ignores functions
28+
"no-use-before-define": [2, "nofunc"],
29+
30+
// Enforce capitalization of constructor functions
31+
"new-cap": 2,
32+
33+
// Disallow creation of dense arrays using the Array constructor
34+
"no-array-constructor": 2,
35+
36+
// Disallow use of the Object constructor
37+
"no-new-object": 2,
38+
39+
// Disallow use of argument.caller and argument.callee
40+
"no-caller": 2,
41+
42+
// Disallow empty block statements
43+
"no-empty": 2,
44+
45+
// Disallow use of the with statement
46+
"no-with": 2,
47+
48+
// Disallow mixed spaces and tabs for indentation
49+
"no-mixed-spaces-and-tabs": 2,
50+
51+
// Disallow use of multiline strings
52+
"no-multi-str": 2,
53+
54+
// Warn if variables are not named with camelCase
55+
"camelcase": 1,
56+
57+
// Disallow trailing whitespace at the end of lines
58+
"no-trailing-spaces": 2,
59+
60+
// Disallow spacing before commas; enforce spacing after commas
61+
"comma-spacing": [2, { "before": false, "after": true }],
62+
63+
// Enforce spacing after keywords: if, else, for, while, do, switch, try,
64+
// catch, and finally
65+
"space-after-keywords": 2,
66+
67+
// Enforce spacing before opening brace of block statements
68+
"space-before-blocks": [2, "always"],
69+
70+
// Enforce spaceing around infix operators: +, -, :, ?
71+
"space-infix-ops": 2,
72+
73+
// Enforce spacing around word unary operators: new, delete, typeof, void
74+
// Disallow spacing around non-word unary operators: -, +, --, ++, !, !!
75+
"space-unary-ops": [2, { "words": true, "nonwords": false }],
76+
77+
// Disallow undeclared variables (unless mentioned in /*global ...*/ comment)
78+
"no-undef": 2,
79+
80+
// Warn if single newline at end of file is missing
81+
"eol-last": 1,
82+
83+
// Enforce single quotes for string literals
84+
"quotes": [2, "single"],
85+
86+
// Disallow unnecessary parentheses
87+
"no-extra-parens": 2,
88+
89+
// Disallow unnecessary semicolons
90+
"no-extra-semi": 2,
91+
92+
// Disallow function or variable declarations in nested blocks
93+
"no-inner-declarations": 2,
94+
95+
// Disallows the nesting of blocks more than 5 deep
96+
"max-depth": [2, "5"],
97+
98+
// Enforces a maximum of 10 parameters in a function declaration
99+
"max-params": [2, "10"],
100+
101+
// Enforces a maximum of 25 statements within a single function
102+
"max-statements": [2, "25"],
103+
104+
// Enforces a maximum of 100 characters in a single line; adjusts tabs
105+
// to equal 4 characters
106+
"max-len": [2, "300", "4"],
107+
108+
// Enforces semicolons at the end of statements
109+
"semi": 2,
110+
111+
// Disallow function definitions of the form 'function myFunc() {'
112+
"func-style": [2, "expression"]
113+
}
114+
}

0 commit comments

Comments
 (0)