Skip to content

Commit 8f18166

Browse files
hekikeWilliam Blankenship
authored and
William Blankenship
committed
chore(prettier): use prettier for style checking and fixing (#1537)
1 parent 70b8690 commit 8f18166

File tree

103 files changed

+4865
-4809
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+4865
-4809
lines changed

.eslintrc.js

+21-47
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ var OFF = 0;
44
var ERROR = 2;
55

66
var config = {
7+
extends: [],
8+
plugins: ['jsdoc'],
79
env: {
810
browser: false,
911
node: true,
1012
es6: false
1113
},
12-
plugins: ['jsdoc'],
1314
rules: {}
1415
};
1516

@@ -40,12 +41,15 @@ if (!process.env.NO_LINT) {
4041
config.rules['no-sparse-arrays'] = ERROR;
4142
config.rules['no-unreachable'] = ERROR;
4243
config.rules['use-isnan'] = ERROR;
43-
config.rules['valid-jsdoc'] = [ ERROR, {
44-
'requireReturnDescription': false,
45-
'prefer': {
46-
'return': 'returns'
44+
config.rules['valid-jsdoc'] = [
45+
ERROR,
46+
{
47+
requireReturnDescription: false,
48+
prefer: {
49+
return: 'returns'
50+
}
4751
}
48-
}];
52+
];
4953
config.rules['valid-typeof'] = ERROR;
5054

5155
// best practices
@@ -54,7 +58,7 @@ if (!process.env.NO_LINT) {
5458
config.rules['consistent-return'] = ERROR;
5559
config.rules['curly'] = OFF;
5660
config.rules['default-case'] = ERROR;
57-
config.rules['dot-notation'] = [ ERROR, { 'allowKeywords': true } ];
61+
config.rules['dot-notation'] = [ERROR, { allowKeywords: true }];
5862
config.rules['eqeqeq'] = ERROR;
5963
config.rules['guard-for-in'] = ERROR;
6064
config.rules['no-alert'] = ERROR;
@@ -90,13 +94,13 @@ if (!process.env.NO_LINT) {
9094
config.rules['no-throw-literal'] = ERROR;
9195
config.rules['no-unused-expressions'] = ERROR;
9296

93-
config.rules['no-warning-comments'] = [ 1 ];
97+
config.rules['no-warning-comments'] = [1];
9498
config.rules['no-with'] = ERROR;
9599
config.rules['radix'] = ERROR;
96100
config.rules['wrap-iife'] = ERROR;
97101

98102
// strict mode
99-
config.rules['strict'] = [ ERROR, 'global' ];
103+
config.rules['strict'] = [ERROR, 'global'];
100104

101105
// variables
102106
config.rules['no-catch-shadow'] = ERROR;
@@ -106,11 +110,11 @@ if (!process.env.NO_LINT) {
106110
config.rules['no-undef'] = ERROR;
107111
config.rules['no-undef-init'] = ERROR;
108112
config.rules['no-undefined'] = OFF;
109-
config.rules['no-unused-vars'] = [ ERROR, { 'vars': 'all', 'args': 'none' } ];
110-
config.rules['no-use-before-define'] = [ ERROR, 'nofunc' ];
113+
config.rules['no-unused-vars'] = [ERROR, { vars: 'all', args: 'none' }];
114+
config.rules['no-use-before-define'] = [ERROR, 'nofunc'];
111115

112116
// node.js
113-
config.rules['handle-callback-err'] = [ ERROR, '^.*(e|E)rr' ];
117+
config.rules['handle-callback-err'] = [ERROR, '^.*(e|E)rr'];
114118
config.rules['no-mixed-requires'] = ERROR;
115119
config.rules['no-new-require'] = ERROR;
116120
config.rules['no-path-concat'] = OFF;
@@ -119,40 +123,10 @@ if (!process.env.NO_LINT) {
119123

120124
// stylistic.
121125
if (!process.env.NO_STYLE) {
122-
// general rules
123-
config.rules['consistent-this'] = [ERROR, 'self'];
124-
125-
// alignment rules
126-
config.rules['max-len'] = [ERROR, 80];
127-
config.rules['indent'] = [ERROR, 4];
128-
129-
// newline on EOF
130-
config.rules['eol-last'] = [ERROR, 'always'];
131-
132-
// disallow rules
133-
config.rules['no-implicit-coercion'] = ERROR;
134-
config.rules['no-mixed-spaces-and-tabs'] = ERROR;
135-
config.rules['no-trailing-spaces'] = ERROR;
136-
config.rules['no-array-constructor'] = ERROR;
137-
config.rules['no-nested-ternary'] = ERROR;
138-
config.rules['no-new-object'] = ERROR;
139-
config.rules['no-lonely-if'] = ERROR;
140-
config.rules['no-underscore-dangle'] = OFF;
141-
config.rules['no-whitespace-before-property'] = ERROR;
142-
config.rules['yoda'] = ERROR;
143-
144-
// require rules
145-
config.rules['semi'] = ERROR;
146-
config.rules['comma-dangle'] = ERROR;
147-
config.rules['key-spacing'] = ERROR;
148-
config.rules['new-cap'] = ERROR;
149-
config.rules['quotes'] = [ ERROR, 'single' ];
150-
config.rules['space-infix-ops'] = ERROR;
151-
config.rules['keyword-spacing'] = ERROR;
152-
config.rules['space-unary-ops'] = ERROR;
153-
config.rules['space-before-blocks'] = ERROR;
154-
config.rules['space-infix-ops'] = ERROR;
155-
config.rules['space-unary-ops'] = ERROR;
126+
// Prettier
127+
config.extends.push('prettier');
128+
config.plugins.push('prettier');
129+
config.rules['prettier/prettier'] = ERROR;
156130

157131
// JSDoc
158132
config.rules['jsdoc/check-param-names'] = ERROR;
@@ -164,6 +138,6 @@ if (!process.env.NO_STYLE) {
164138
config.rules['jsdoc/require-param-type'] = ERROR;
165139
config.rules['jsdoc/require-returns-description'] = ERROR;
166140
config.rules['jsdoc/require-returns-type'] = ERROR;
167-
};
141+
}
168142

169143
module.exports = config;

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cover_html

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"tabWidth": 4,
3+
"singleQuote": true
4+
}

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ NODECOVER := ./node_modules/.bin/cover
2626
DOCS_BUILD := ./tools/docsBuild.js
2727
NPM := npm
2828
NODE := node
29+
PRETTIER := ./node_modules/.bin/prettier
2930

3031
#
3132
# Files

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
[![Dependency Status](https://david-dm.org/restify/node-restify.svg)](https://david-dm.org/restify/node-restify)
3131
[![devDependency Status](https://david-dm.org/restify/node-restify/dev-status.svg)](https://david-dm.org/restify/node-restify#info=devDependencies)
3232
[![bitHound Score](https://www.bithound.io/github/restify/node-restify/badges/score.svg)](https://www.bithound.io/github/restify/node-restify/master)
33+
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
3334

3435
[restify](http://restify.com) is a framework, utilizing
3536
[connect](https://github.com/senchalabs/connect) style middleware for building

examples/bench/bench.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var server = require('../../lib').createServer();
22
//var server = require('express')();
33

4-
server.get('/echo/:name', function (req, res, next) {
4+
server.get('/echo/:name', function(req, res, next) {
55
res.setHeader('content-type', 'text/plain');
66
res.send(200, req.params.name);
77
});
88

9-
server.listen(8080, function () {
9+
server.listen(8080, function() {
1010
console.log('ready');
1111
});
12-

examples/dtrace/demo.js

+27-24
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@
6868
// 256 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 9
6969
// 512 | 0
7070

71-
7271
var restify = require('../../lib');
7372
var Logger = require('bunyan');
7473

7574
///--- Globals
7675

7776
var NAME = 'exampleapp';
7877

79-
8078
///--- Mainline
8179

8280
var log = new Logger({
@@ -90,7 +88,7 @@ var server = restify.createServer({
9088
name: NAME,
9189
Logger: log,
9290
formatters: {
93-
'application/foo': function (req, res, body) {
91+
'application/foo': function(req, res, body) {
9492
if (body instanceof Error) {
9593
body = body.stack;
9694
} else if (Buffer.isBuffer(body)) {
@@ -108,12 +106,13 @@ var server = restify.createServer({
108106
break;
109107

110108
default:
111-
body = body === null ? '' :
112-
'Demoing application/foo formatter; ' +
113-
JSON.stringify(body);
109+
body =
110+
body === null
111+
? ''
112+
: 'Demoing application/foo formatter; ' +
113+
JSON.stringify(body);
114114
break;
115115
}
116-
117116
}
118117
return body;
119118
}
@@ -127,53 +126,57 @@ server.use(restify.plugins.queryParser());
127126
server.use(restify.plugins.urlEncodedBodyParser());
128127

129128
server.use(function slowHandler(req, res, next) {
130-
setTimeout(function () {
129+
setTimeout(function() {
131130
next();
132131
}, 250);
133132
});
134133

135-
server.get({url: '/foo/:id', name: 'GetFoo'}, function (req, res, next) {
136-
next();
137-
}, function sendResult(req, res, next) {
138-
res.contentType = 'application/foo';
139-
res.send({
140-
hello: req.params.id
141-
});
142-
next();
143-
});
134+
server.get(
135+
{ url: '/foo/:id', name: 'GetFoo' },
136+
function(req, res, next) {
137+
next();
138+
},
139+
function sendResult(req, res, next) {
140+
res.contentType = 'application/foo';
141+
res.send({
142+
hello: req.params.id
143+
});
144+
next();
145+
}
146+
);
144147

145-
server.head('/foo/:id', function (req, res, next) {
148+
server.head('/foo/:id', function(req, res, next) {
146149
res.send({
147150
hello: req.params.id
148151
});
149152
next();
150153
});
151154

152-
server.put('/foo/:id', function (req, res, next) {
155+
server.put('/foo/:id', function(req, res, next) {
153156
res.send({
154157
hello: req.params.id
155158
});
156159
next();
157160
});
158161

159-
server.post('/foo/:id', function (req, res, next) {
162+
server.post('/foo/:id', function(req, res, next) {
160163
res.json(201, req.params);
161164
next();
162165
});
163166

164-
server.del('/foo/:id', function (req, res, next) {
167+
server.del('/foo/:id', function(req, res, next) {
165168
res.send(204);
166169
next();
167170
});
168171

169-
server.on('after', function (req, res, name) {
172+
server.on('after', function(req, res, name) {
170173
req.log.info('%s just finished: %d.', name, res.code);
171174
});
172175

173-
server.on('NotFound', function (req, res) {
176+
server.on('NotFound', function(req, res) {
174177
res.send(404, req.url + ' was not found');
175178
});
176179

177-
server.listen(9080, function () {
180+
server.listen(9080, function() {
178181
log.info('listening: %s', server.url);
179182
});

examples/dtrace/hello.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@ server.use(restify.plugins.queryParser());
1111
server.use(restify.plugins.urlEncodedBodyParser());
1212

1313
server.use(function slowHandler(req, res, next) {
14-
setTimeout(function () {
14+
setTimeout(function() {
1515
next();
1616
}, 250);
1717
});
1818

19-
server.get({
20-
path: '/hello/:name',
21-
name: 'GetFoo'
22-
}, function respond(req, res, next) {
23-
res.send({
24-
hello: req.params.name
25-
});
26-
next();
27-
});
19+
server.get(
20+
{
21+
path: '/hello/:name',
22+
name: 'GetFoo'
23+
},
24+
function respond(req, res, next) {
25+
res.send({
26+
hello: req.params.name
27+
});
28+
next();
29+
}
30+
);
2831

29-
server.listen(8080, function () {
32+
server.listen(8080, function() {
3033
console.log('listening: %s', server.url);
3134
});

examples/jsonp/jsonp.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ var restify = require('../../lib');
33
var srv = restify.createServer();
44
srv.use(restify.plugins.queryParser());
55
srv.use(restify.plugins.jsonp());
6-
srv.get('/', function (req, res, next) {
7-
res.send({hello: 'world'});
6+
srv.get('/', function(req, res, next) {
7+
res.send({ hello: 'world' });
88
next();
99
});
1010

11-
srv.listen(8080, function () {
11+
srv.listen(8080, function() {
1212
console.log('ready on %s', srv.url);
1313
});

examples/sockio/sockio.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ var socketio = require('socket.io');
44

55
var restify = require('../../lib');
66

7-
87
///--- Globals
98

10-
var HTML = '<script src="/socket.io/socket.io.js"></script>\n' +
9+
var HTML =
10+
'<script src="/socket.io/socket.io.js"></script>\n' +
1111
'<script>\n' +
1212
'var socket = io("http://localhost:8080");\n' +
1313
'socket.on("news", function (data) {\n' +
@@ -16,7 +16,6 @@ var HTML = '<script src="/socket.io/socket.io.js"></script>\n' +
1616
'});\n' +
1717
'</script>';
1818

19-
2019
///--- Mainline
2120

2221
var server = restify.createServer();
@@ -31,14 +30,13 @@ server.get('/', function indexHTML(req, res, next) {
3130
next();
3231
});
3332

34-
35-
io.on('connection', function (socket) {
33+
io.on('connection', function(socket) {
3634
socket.emit('news', { hello: 'world' });
37-
socket.on('my other event', function (data) {
35+
socket.on('my other event', function(data) {
3836
console.log(data);
3937
});
4038
});
4139

42-
server.listen(8080, function () {
40+
server.listen(8080, function() {
4341
console.log('socket.io server listening at %s', server.url);
4442
});

0 commit comments

Comments
 (0)