Skip to content

Commit 842256e

Browse files
committed
test(eslint): Add eslint back to our test suite
Refs #710. Fixes #765
1 parent ed5c2a0 commit 842256e

File tree

6 files changed

+488
-66
lines changed

6 files changed

+488
-66
lines changed

.eslintrc

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,31 @@
88
"flowtype"
99
],
1010
"rules": {
11-
"space-in-parens": 2,
12-
"space-before-blocks": 2,
13-
"keyword-spacing": 2,
14-
"space-unary-ops": 2,
15-
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
1611
"no-use-before-define": [2, "nofunc"],
1712
"camelcase": 2,
18-
"semi": 2,
19-
"comma-style": 2,
2013
"no-lonely-if": 2,
21-
"max-len": [2, 120],
2214
"no-else-return": 2,
23-
"no-trailing-spaces": 2,
2415
"new-cap": 2,
2516
"no-empty": 2,
2617
"consistent-return": 0,
2718
"no-new": 2,
28-
"key-spacing": 2,
29-
"no-multi-spaces": 2,
30-
"brace-style": 2,
3119
"object-shorthand": ["error", "always", { "avoidQuotes": true }],
3220
"no-throw-literal": 2,
3321
"no-self-compare": 2,
3422
"no-void": 2,
3523
"no-unused-vars": 2,
3624
"wrap-iife": 2,
3725
"no-eq-null": 2,
38-
"quotes": [2, "single"],
39-
"indent": [2, 2],
40-
"curly": 2,
4126
"strict": [2, "global"],
4227
"no-shadow": 0,
4328
"no-undef": 2,
4429
"flowtype/define-flow-type": 1,
4530
"flowtype/use-flow-type": 1
4631
},
47-
"extends": "eslint:recommended",
32+
"extends": [
33+
"eslint:recommended",
34+
"prettier"
35+
],
4836
"env": {
4937
"node": true,
5038
"es6": true

lib/infer/params.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const generate = require('babel-generator').default;
66
const _ = require('lodash');
77
const findTarget = require('./finders').findTarget;
88
const flowDoctrine = require('../flow_doctrine');
9-
const util = require('util');
109

1110
/**
1211
* Infers param tags by reading function parameter names
@@ -98,7 +97,8 @@ function paramToDoc(
9897
const prefixedName = prefix + '.' + param.name;
9998

10099
switch (param.type) {
101-
case 'AssignmentPattern': // (a = b)
100+
case 'AssignmentPattern': {
101+
// (a = b)
102102
const newAssignmentParam = paramToDoc(param.left, '', i);
103103

104104
if (Array.isArray(newAssignmentParam)) {
@@ -111,8 +111,10 @@ function paramToDoc(
111111
}).code,
112112
type: newAssignmentParam.type
113113
});
114+
}
114115
// ObjectPattern <AssignmentProperty | RestElement>
115-
case 'ObjectPattern': // { a }
116+
case 'ObjectPattern': {
117+
// { a }
116118
if (prefix === '') {
117119
// If this is a root-level param, like f({ x }), then we need to name
118120
// it, like $0 or $1, depending on its position.
@@ -151,8 +153,10 @@ function paramToDoc(
151153
return _.flatMap(param.properties, prop => {
152154
return paramToDoc(prop, prefix);
153155
});
156+
}
154157
// ArrayPattern<Pattern | null>
155-
case 'ArrayPattern': // ([a, b, { c }])
158+
case 'ArrayPattern': {
159+
// ([a, b, { c }])
156160
if (prefix === '') {
157161
return {
158162
title: 'param',
@@ -182,12 +186,14 @@ function paramToDoc(
182186
});
183187
return paramToDoc(indexedElement, prefix);
184188
});
185-
case 'ObjectProperty':
189+
}
190+
case 'ObjectProperty': {
186191
return _.assign(paramToDoc(param.value, prefix + '.' + param.key.name), {
187192
name: prefix + '.' + param.key.name
188193
});
194+
}
189195
case 'RestProperty': // (a, ...b)
190-
case 'RestElement':
196+
case 'RestElement': {
191197
let type /*: DoctrineType */ = {
192198
type: 'RestType'
193199
};
@@ -196,12 +202,12 @@ function paramToDoc(
196202
}
197203
return {
198204
title: 'param',
199-
name: param.argument.name,
200205
name: prefix ? `${prefix}.${param.argument.name}` : param.argument.name,
201206
lineNumber: param.loc.start.line,
202207
type
203208
};
204-
default:
209+
}
210+
default: {
205211
// (a)
206212
var newParam /*: CommentTag*/ = {
207213
title: 'param',
@@ -215,6 +221,7 @@ function paramToDoc(
215221
}
216222

217223
return newParam;
224+
}
218225
}
219226
}
220227

lib/inline_tokenizer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ var tokenizeTutorial = makeTokenizer(
5656
* This does not handle the `[text]({@link url})` and `[text]({@tutorial url})` forms of these tags.
5757
* That's a JSDoc misfeature; just use regular markdown syntax instead: `[text](url)`.
5858
*
59-
* @param {Object} options - for the plugin
6059
* @returns {undefined}
6160
*/
62-
module.exports = function(options /*: Object*/) {
61+
module.exports = function(/* options: Object*/) {
6362
var proto = this.Parser.prototype;
6463
proto.inlineTokenizers.tokenizeLink = tokenizeLink;
6564
proto.inlineTokenizers.tokenizeTutorial = tokenizeTutorial;

lib/parse.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var flatteners = {
1919
* @param {Object} tag the tag
2020
* @returns {undefined} has side-effects
2121
*/
22-
access: function(result, tag) {
22+
access(result, tag) {
2323
// doctrine ensures that tag.access is valid
2424
result.access = tag.access;
2525
},
@@ -33,7 +33,7 @@ var flatteners = {
3333
* @param {Object} tag the tag
3434
* @returns {undefined} has side-effects
3535
*/
36-
augments: function(result, tag) {
36+
augments(result, tag) {
3737
// Google variation of augments/extends tag:
3838
// uses type with brackets instead of name.
3939
// https://github.com/google/closure-library/issues/746
@@ -55,7 +55,7 @@ var flatteners = {
5555
* @param {Object} tag the tag
5656
* @returns {undefined} has side-effects
5757
*/
58-
callback: function(result, tag) {
58+
callback(result, tag) {
5959
result.kind = 'typedef';
6060

6161
if (tag.description) {
@@ -92,7 +92,7 @@ var flatteners = {
9292
* @param {Object} tag the tag
9393
* @returns {undefined} has side-effects
9494
*/
95-
event: function(result, tag) {
95+
event(result, tag) {
9696
result.kind = 'event';
9797

9898
if (tag.description) {
@@ -106,7 +106,7 @@ var flatteners = {
106106
* @param {Object} tag the tag
107107
* @returns {undefined} has side-effects
108108
*/
109-
example: function(result, tag) {
109+
example(result, tag) {
110110
if (!tag.description) {
111111
result.errors.push({
112112
message: '@example without code',
@@ -135,7 +135,7 @@ var flatteners = {
135135
* @param {Object} tag the tag
136136
* @returns {undefined} has side-effects
137137
*/
138-
external: function(result, tag) {
138+
external(result, tag) {
139139
result.kind = 'external';
140140

141141
if (tag.description) {
@@ -149,7 +149,7 @@ var flatteners = {
149149
* @param {Object} tag the tag
150150
* @returns {undefined} has side-effects
151151
*/
152-
file: function(result, tag) {
152+
file(result, tag) {
153153
result.kind = 'file';
154154

155155
if (tag.description) {
@@ -166,7 +166,7 @@ var flatteners = {
166166
* @param {Object} result target comment
167167
* @returns {undefined} has side-effects
168168
*/
169-
global: function(result) {
169+
global(result) {
170170
result.scope = 'global';
171171
},
172172
host: synonym('external'),
@@ -179,7 +179,7 @@ var flatteners = {
179179
* @param {Object} result target comment
180180
* @returns {undefined} has side-effects
181181
*/
182-
inner: function(result) {
182+
inner(result) {
183183
result.scope = 'inner';
184184
},
185185
/**
@@ -188,7 +188,7 @@ var flatteners = {
188188
* @param {Object} result target comment
189189
* @returns {undefined} has side-effects
190190
*/
191-
instance: function(result) {
191+
instance(result) {
192192
result.scope = 'instance';
193193
},
194194
/**
@@ -198,7 +198,7 @@ var flatteners = {
198198
* @param {Object} tag the tag
199199
* @returns {undefined} has side-effects
200200
*/
201-
interface: function(result, tag) {
201+
interface(result, tag) {
202202
result.interface = true;
203203
if (tag.description) {
204204
result.name = tag.description;
@@ -211,7 +211,7 @@ var flatteners = {
211211
* @param {Object} tag the tag
212212
* @returns {undefined} has side-effects
213213
*/
214-
kind: function(result, tag) {
214+
kind(result, tag) {
215215
// doctrine ensures that tag.kind is valid
216216
result.kind = tag.kind;
217217
},
@@ -235,7 +235,7 @@ var flatteners = {
235235
* @param {Object} tag the tag
236236
* @returns {undefined} has side-effects
237237
*/
238-
param: function(result, tag) {
238+
param(result, tag) {
239239
var param /*: CommentTag */ = {
240240
title: 'param',
241241
name: tag.name,
@@ -265,7 +265,7 @@ var flatteners = {
265265
* @param {Object} result target comment
266266
* @returns {undefined} has side-effects
267267
*/
268-
private: function(result) {
268+
private(result) {
269269
result.access = 'private';
270270
},
271271
prop: synonym('property'),
@@ -276,7 +276,7 @@ var flatteners = {
276276
* @param {Object} tag the tag
277277
* @returns {undefined} has side-effects
278278
*/
279-
property: function(result, tag) {
279+
property(result, tag) {
280280
var property /*: CommentTag */ = {
281281
title: 'property',
282282
name: tag.name,
@@ -299,7 +299,7 @@ var flatteners = {
299299
* @param {Object} result target comment
300300
* @returns {undefined} has side-effects
301301
*/
302-
protected: function(result) {
302+
protected(result) {
303303
result.access = 'protected';
304304
},
305305
/**
@@ -308,7 +308,7 @@ var flatteners = {
308308
* @param {Object} result target comment
309309
* @returns {undefined} has side-effects
310310
*/
311-
public: function(result) {
311+
public(result) {
312312
result.access = 'public';
313313
},
314314
readonly: flattenBoolean,
@@ -321,7 +321,7 @@ var flatteners = {
321321
* @param {Object} tag the tag
322322
* @returns {undefined} has side-effects
323323
*/
324-
returns: function(result, tag) {
324+
returns(result, tag) {
325325
var returns /*: CommentTag */ = {
326326
description: parseMarkdown(tag.description),
327327
title: 'returns'
@@ -340,7 +340,7 @@ var flatteners = {
340340
* @param {Object} tag the tag
341341
* @returns {undefined} has side-effects
342342
*/
343-
see: function(result, tag) {
343+
see(result, tag) {
344344
result.sees.push(parseMarkdown(tag.description));
345345
},
346346
since: flattenDescription,
@@ -350,7 +350,7 @@ var flatteners = {
350350
* @param {Object} result target comment
351351
* @returns {undefined} has side-effects
352352
*/
353-
static: function(result) {
353+
static(result) {
354354
result.scope = 'static';
355355
},
356356
summary: flattenMarkdownDescription,
@@ -362,7 +362,7 @@ var flatteners = {
362362
* @param {Object} tag the tag
363363
* @returns {undefined} has side-effects
364364
*/
365-
throws: function(result, tag) {
365+
throws(result, tag) {
366366
var throws = {};
367367

368368
if (tag.description) {
@@ -382,7 +382,7 @@ var flatteners = {
382382
* @param {Object} tag the tag
383383
* @returns {undefined} has side-effects
384384
*/
385-
todo: function(result, tag) {
385+
todo(result, tag) {
386386
result.todos.push(parseMarkdown(tag.description));
387387
},
388388
tutorial: todo,
@@ -396,7 +396,7 @@ var flatteners = {
396396
* @param {Object} tag the tag
397397
* @returns {undefined} has side-effects
398398
*/
399-
variation: function(result, tag) {
399+
variation(result, tag) {
400400
result.variation = tag.variation;
401401
},
402402
version: flattenDescription,

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@
5858
},
5959
"devDependencies": {
6060
"are-we-flow-yet": "^1.0.0",
61+
"babel-eslint": "^7.2.3",
6162
"chdir": "0.0.0",
6263
"cz-conventional-changelog": "2.0.0",
6364
"documentation-schema": "0.0.1",
65+
"eslint": "^3.19.0",
66+
"eslint-config-prettier": "^1.7.0",
67+
"eslint-plugin-flowtype": "^2.32.1",
6468
"flow-bin": "^0.44.0",
6569
"fs-extra": "^3.0.0",
6670
"husky": "^0.13.3",
@@ -93,7 +97,7 @@
9397
"doc": "./bin/documentation.js build lib/index.js -f md --access=public > docs/NODE_API.md",
9498
"changelog": "standard-changelog -i CHANGELOG.md -w",
9599
"self-lint": "node ./bin/documentation.js lint",
96-
"test": "are-we-flow-yet lib && flow check && npm run self-lint && npm run test-tap",
100+
"test": "eslint lib && are-we-flow-yet lib && flow check && npm run self-lint && npm run test-tap",
97101
"test-tap": "tap -t 120 --coverage --nyc-arg=--cache test/*.js test/lib test/streams"
98102
},
99103
"config": {

0 commit comments

Comments
 (0)