Skip to content

Commit 7a26340

Browse files
GerHobbeltjasonLaster
authored andcommitted
add prettier task for standardized code formatting => easier cross-branch/fork code comparison and merging (#397)
1. add eslint prettier integration so that npm run lint catches issues 2. re-runs npm run lint on the project to catch issues prettier introduced 3. add npm run lint to the travis.yml
1 parent 1be1541 commit 7a26340

35 files changed

+3082
-1716
lines changed

.eslintrc.js

+78-51
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
"use strict";
22

33
module.exports = {
4-
"env": {
5-
"node": true,
6-
"es6": true
4+
env: {
5+
node: true,
6+
es6: true
77
},
88

9-
"parserOptions": {
10-
"ecmaVersion": 9
9+
plugins: ["prettier"],
10+
extends: ["prettier"],
11+
12+
parserOptions: {
13+
ecmaVersion: 9
1114
},
1215

13-
"globals": {
14-
"fetch": false,
15-
"WebAssembly": false
16+
globals: {
17+
fetch: false,
18+
WebAssembly: false
1619
},
1720

18-
"rules": {
21+
rules: {
1922
// Require spacing around =>
2023
"arrow-spacing": "error",
2124

@@ -26,17 +29,17 @@ module.exports = {
2629
"block-spacing": "error",
2730

2831
// No newline before open brace for a block
29-
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
32+
"brace-style": ["error", "1tbs", { allowSingleLine: true }],
3033

3134
// No space before always a space after a comma
32-
"comma-spacing": ["error", {"after": true, "before": false}],
35+
"comma-spacing": ["error", { after: true, before: false }],
3336

3437
// Commas at the end of the line not the start
3538
"comma-style": "error",
3639

3740
// Warn about cyclomatic complexity in functions.
3841
// XXX Get this down to 20?
39-
"complexity": ["error", 25],
42+
complexity: ["error", 25],
4043

4144
// Don't require spaces around computed properties
4245
"computed-property-spacing": ["error", "never"],
@@ -45,7 +48,7 @@ module.exports = {
4548
"consistent-return": "error",
4649

4750
// Require braces around blocks that start a new line
48-
"curly": ["error", "multi-line"],
51+
curly: ["error", "multi-line"],
4952

5053
// Encourage the use of dot notation whenever possible.
5154
"dot-notation": "error",
@@ -57,17 +60,20 @@ module.exports = {
5760
"func-call-spacing": "error",
5861

5962
// Require function* name()
60-
"generator-star-spacing": ["error", {"after": true, "before": false}],
63+
"generator-star-spacing": ["error", { after: true, before: false }],
6164

6265
// Two space indent
6366
// "indent": ["error", 2, { "SwitchCase": 1 }],
6467

6568
// Space after colon not before in property declarations
66-
"key-spacing": ["error", {
67-
"afterColon": true,
68-
"beforeColon": false,
69-
"mode": "minimum"
70-
}],
69+
"key-spacing": [
70+
"error",
71+
{
72+
afterColon: true,
73+
beforeColon: false,
74+
mode: "minimum"
75+
}
76+
],
7177

7278
// Require spaces before and after keywords
7379
"keyword-spacing": "error",
@@ -125,7 +131,7 @@ module.exports = {
125131
"no-else-return": "error",
126132

127133
// No empty statements
128-
"no-empty": ["error", {"allowEmptyCatch": true}],
134+
"no-empty": ["error", { allowEmptyCatch: true }],
129135

130136
// No empty character classes in regex
131137
"no-empty-character-class": "error",
@@ -163,7 +169,7 @@ module.exports = {
163169
// Disallow the use of the __iterator__ property
164170
"no-iterator": "error",
165171

166-
// No labels
172+
// No labels
167173
"no-labels": "error",
168174

169175
// Disallow unnecessary nested blocks
@@ -176,12 +182,17 @@ module.exports = {
176182
// "no-mixed-spaces-and-tabs": "error",
177183

178184
// No unnecessary spacing
179-
"no-multi-spaces": ["error", { exceptions: {
180-
"ArrayExpression": true,
181-
"AssignmentExpression": true,
182-
"ObjectExpression": true,
183-
"VariableDeclarator": true
184-
} }],
185+
"no-multi-spaces": [
186+
"error",
187+
{
188+
exceptions: {
189+
ArrayExpression: true,
190+
AssignmentExpression: true,
191+
ObjectExpression: true,
192+
VariableDeclarator: true
193+
}
194+
}
195+
],
185196

186197
// No reassigning native JS objects
187198
"no-native-reassign": "error",
@@ -250,10 +261,13 @@ module.exports = {
250261
"no-unsafe-negation": "error",
251262

252263
// No declaring variables that are never used
253-
"no-unused-vars": ["error", {
254-
"args": "none",
255-
"vars": "local"
256-
}],
264+
"no-unused-vars": [
265+
"error",
266+
{
267+
args: "none",
268+
vars: "local"
269+
}
270+
],
257271

258272
// No using variables before defined
259273
"no-use-before-define": ["error", "nofunc"],
@@ -278,48 +292,58 @@ module.exports = {
278292
"no-with": "error",
279293

280294
// Require object-literal shorthand with ES6 method syntax
281-
"object-shorthand": ["error", "always", { "avoidQuotes": true }],
295+
"object-shorthand": ["error", "always", { avoidQuotes: true }],
282296

283297
// Use const instead of let where possible
284298
"prefer-const": "error",
285299

286300
// Require double-quotes everywhere, except where quotes are escaped
287301
// or template literals are used.
288-
"quotes": ["error", "double", {
289-
"allowTemplateLiterals": true,
290-
"avoidEscape": true
291-
}],
302+
quotes: [
303+
"error",
304+
"double",
305+
{
306+
allowTemplateLiterals: true,
307+
avoidEscape: true
308+
}
309+
],
292310

293311
// No spacing inside rest or spread expressions
294312
"rest-spread-spacing": "error",
295313

296314
// Always require semicolon at end of statement
297-
"semi": ["error", "always"],
315+
semi: ["error", "always"],
298316

299317
// Require space before blocks
300318
"space-before-blocks": "error",
301319

302320
// Never use spaces before function parentheses
303-
"space-before-function-paren": ["error", {
304-
"anonymous": "never",
305-
"asyncArrow": "always",
306-
"named": "never"
307-
}],
321+
"space-before-function-paren": [
322+
"error",
323+
{
324+
anonymous: "never",
325+
asyncArrow: "always",
326+
named: "never"
327+
}
328+
],
308329

309330
// No space padding in parentheses
310331
"space-in-parens": ["error", "never"],
311332

312333
// Require spaces around operators
313-
"space-infix-ops": ["error", { "int32Hint": true }],
334+
"space-infix-ops": ["error", { int32Hint: true }],
314335

315336
// ++ and -- should not need spacing
316-
"space-unary-ops": ["error", {
317-
"nonwords": false,
318-
"overrides": {
319-
"typeof": false // We tend to use typeof as a function call
320-
},
321-
"words": true
322-
}],
337+
"space-unary-ops": [
338+
"error",
339+
{
340+
nonwords: false,
341+
overrides: {
342+
typeof: false // We tend to use typeof as a function call
343+
},
344+
words: true
345+
}
346+
],
323347

324348
// Requires or disallows a whitespace (space or tab) beginning a comment
325349
"spaced-comment": "error",
@@ -328,6 +352,9 @@ module.exports = {
328352
"use-isnan": "error",
329353

330354
// Only check typeof against valid results
331-
"valid-typeof": "error"
355+
"valid-typeof": "error",
356+
357+
"prettier/prettier": "error",
358+
"max-len": ["error", { code: 120, ignoreUrls: true }]
332359
}
333360
};

.travis.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ node_js:
77
- "9"
88

99
install:
10-
- npm install
11-
- npm install coveralls
10+
- npm install
11+
- npm install coveralls
1212

1313
script:
14-
- npm run coverage
14+
- npm run coverage
15+
- npm run lint
1516

1617
after_success:
17-
- nyc report --reporter=text-lcov | coveralls
18+
- nyc report --reporter=text-lcov | coveralls
1819

1920
cache:
2021
directories:

0 commit comments

Comments
 (0)