Skip to content

Commit

Permalink
chore(prettier): use prettier for style checking and fixing (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike authored and William Blankenship committed Oct 31, 2017
1 parent 70b8690 commit 8f18166
Show file tree
Hide file tree
Showing 103 changed files with 4,865 additions and 4,809 deletions.
68 changes: 21 additions & 47 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ var OFF = 0;
var ERROR = 2;

var config = {
extends: [],
plugins: ['jsdoc'],
env: {
browser: false,
node: true,
es6: false
},
plugins: ['jsdoc'],
rules: {}
};

Expand Down Expand Up @@ -40,12 +41,15 @@ if (!process.env.NO_LINT) {
config.rules['no-sparse-arrays'] = ERROR;
config.rules['no-unreachable'] = ERROR;
config.rules['use-isnan'] = ERROR;
config.rules['valid-jsdoc'] = [ ERROR, {
'requireReturnDescription': false,
'prefer': {
'return': 'returns'
config.rules['valid-jsdoc'] = [
ERROR,
{
requireReturnDescription: false,
prefer: {
return: 'returns'
}
}
}];
];
config.rules['valid-typeof'] = ERROR;

// best practices
Expand All @@ -54,7 +58,7 @@ if (!process.env.NO_LINT) {
config.rules['consistent-return'] = ERROR;
config.rules['curly'] = OFF;
config.rules['default-case'] = ERROR;
config.rules['dot-notation'] = [ ERROR, { 'allowKeywords': true } ];
config.rules['dot-notation'] = [ERROR, { allowKeywords: true }];
config.rules['eqeqeq'] = ERROR;
config.rules['guard-for-in'] = ERROR;
config.rules['no-alert'] = ERROR;
Expand Down Expand Up @@ -90,13 +94,13 @@ if (!process.env.NO_LINT) {
config.rules['no-throw-literal'] = ERROR;
config.rules['no-unused-expressions'] = ERROR;

config.rules['no-warning-comments'] = [ 1 ];
config.rules['no-warning-comments'] = [1];
config.rules['no-with'] = ERROR;
config.rules['radix'] = ERROR;
config.rules['wrap-iife'] = ERROR;

// strict mode
config.rules['strict'] = [ ERROR, 'global' ];
config.rules['strict'] = [ERROR, 'global'];

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

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

// stylistic.
if (!process.env.NO_STYLE) {
// general rules
config.rules['consistent-this'] = [ERROR, 'self'];

// alignment rules
config.rules['max-len'] = [ERROR, 80];
config.rules['indent'] = [ERROR, 4];

// newline on EOF
config.rules['eol-last'] = [ERROR, 'always'];

// disallow rules
config.rules['no-implicit-coercion'] = ERROR;
config.rules['no-mixed-spaces-and-tabs'] = ERROR;
config.rules['no-trailing-spaces'] = ERROR;
config.rules['no-array-constructor'] = ERROR;
config.rules['no-nested-ternary'] = ERROR;
config.rules['no-new-object'] = ERROR;
config.rules['no-lonely-if'] = ERROR;
config.rules['no-underscore-dangle'] = OFF;
config.rules['no-whitespace-before-property'] = ERROR;
config.rules['yoda'] = ERROR;

// require rules
config.rules['semi'] = ERROR;
config.rules['comma-dangle'] = ERROR;
config.rules['key-spacing'] = ERROR;
config.rules['new-cap'] = ERROR;
config.rules['quotes'] = [ ERROR, 'single' ];
config.rules['space-infix-ops'] = ERROR;
config.rules['keyword-spacing'] = ERROR;
config.rules['space-unary-ops'] = ERROR;
config.rules['space-before-blocks'] = ERROR;
config.rules['space-infix-ops'] = ERROR;
config.rules['space-unary-ops'] = ERROR;
// Prettier
config.extends.push('prettier');
config.plugins.push('prettier');
config.rules['prettier/prettier'] = ERROR;

// JSDoc
config.rules['jsdoc/check-param-names'] = ERROR;
Expand All @@ -164,6 +138,6 @@ if (!process.env.NO_STYLE) {
config.rules['jsdoc/require-param-type'] = ERROR;
config.rules['jsdoc/require-returns-description'] = ERROR;
config.rules['jsdoc/require-returns-type'] = ERROR;
};
}

module.exports = config;
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cover_html
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 4,
"singleQuote": true
}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ NODECOVER := ./node_modules/.bin/cover
DOCS_BUILD := ./tools/docsBuild.js
NPM := npm
NODE := node
PRETTIER := ./node_modules/.bin/prettier

#
# Files
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
[![Dependency Status](https://david-dm.org/restify/node-restify.svg)](https://david-dm.org/restify/node-restify)
[![devDependency Status](https://david-dm.org/restify/node-restify/dev-status.svg)](https://david-dm.org/restify/node-restify#info=devDependencies)
[![bitHound Score](https://www.bithound.io/github/restify/node-restify/badges/score.svg)](https://www.bithound.io/github/restify/node-restify/master)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

[restify](http://restify.com) is a framework, utilizing
[connect](https://github.com/senchalabs/connect) style middleware for building
Expand Down
5 changes: 2 additions & 3 deletions examples/bench/bench.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var server = require('../../lib').createServer();
//var server = require('express')();

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

server.listen(8080, function () {
server.listen(8080, function() {
console.log('ready');
});

51 changes: 27 additions & 24 deletions examples/dtrace/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@
// 256 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 9
// 512 | 0


var restify = require('../../lib');
var Logger = require('bunyan');

///--- Globals

var NAME = 'exampleapp';


///--- Mainline

var log = new Logger({
Expand All @@ -90,7 +88,7 @@ var server = restify.createServer({
name: NAME,
Logger: log,
formatters: {
'application/foo': function (req, res, body) {
'application/foo': function(req, res, body) {
if (body instanceof Error) {
body = body.stack;
} else if (Buffer.isBuffer(body)) {
Expand All @@ -108,12 +106,13 @@ var server = restify.createServer({
break;

default:
body = body === null ? '' :
'Demoing application/foo formatter; ' +
JSON.stringify(body);
body =
body === null
? ''
: 'Demoing application/foo formatter; ' +
JSON.stringify(body);
break;
}

}
return body;
}
Expand All @@ -127,53 +126,57 @@ server.use(restify.plugins.queryParser());
server.use(restify.plugins.urlEncodedBodyParser());

server.use(function slowHandler(req, res, next) {
setTimeout(function () {
setTimeout(function() {
next();
}, 250);
});

server.get({url: '/foo/:id', name: 'GetFoo'}, function (req, res, next) {
next();
}, function sendResult(req, res, next) {
res.contentType = 'application/foo';
res.send({
hello: req.params.id
});
next();
});
server.get(
{ url: '/foo/:id', name: 'GetFoo' },
function(req, res, next) {
next();
},
function sendResult(req, res, next) {
res.contentType = 'application/foo';
res.send({
hello: req.params.id
});
next();
}
);

server.head('/foo/:id', function (req, res, next) {
server.head('/foo/:id', function(req, res, next) {
res.send({
hello: req.params.id
});
next();
});

server.put('/foo/:id', function (req, res, next) {
server.put('/foo/:id', function(req, res, next) {
res.send({
hello: req.params.id
});
next();
});

server.post('/foo/:id', function (req, res, next) {
server.post('/foo/:id', function(req, res, next) {
res.json(201, req.params);
next();
});

server.del('/foo/:id', function (req, res, next) {
server.del('/foo/:id', function(req, res, next) {
res.send(204);
next();
});

server.on('after', function (req, res, name) {
server.on('after', function(req, res, name) {
req.log.info('%s just finished: %d.', name, res.code);
});

server.on('NotFound', function (req, res) {
server.on('NotFound', function(req, res) {
res.send(404, req.url + ' was not found');
});

server.listen(9080, function () {
server.listen(9080, function() {
log.info('listening: %s', server.url);
});
25 changes: 14 additions & 11 deletions examples/dtrace/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ server.use(restify.plugins.queryParser());
server.use(restify.plugins.urlEncodedBodyParser());

server.use(function slowHandler(req, res, next) {
setTimeout(function () {
setTimeout(function() {
next();
}, 250);
});

server.get({
path: '/hello/:name',
name: 'GetFoo'
}, function respond(req, res, next) {
res.send({
hello: req.params.name
});
next();
});
server.get(
{
path: '/hello/:name',
name: 'GetFoo'
},
function respond(req, res, next) {
res.send({
hello: req.params.name
});
next();
}
);

server.listen(8080, function () {
server.listen(8080, function() {
console.log('listening: %s', server.url);
});
6 changes: 3 additions & 3 deletions examples/jsonp/jsonp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ var restify = require('../../lib');
var srv = restify.createServer();
srv.use(restify.plugins.queryParser());
srv.use(restify.plugins.jsonp());
srv.get('/', function (req, res, next) {
res.send({hello: 'world'});
srv.get('/', function(req, res, next) {
res.send({ hello: 'world' });
next();
});

srv.listen(8080, function () {
srv.listen(8080, function() {
console.log('ready on %s', srv.url);
});
12 changes: 5 additions & 7 deletions examples/sockio/sockio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ var socketio = require('socket.io');

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


///--- Globals

var HTML = '<script src="/socket.io/socket.io.js"></script>\n' +
var HTML =
'<script src="/socket.io/socket.io.js"></script>\n' +
'<script>\n' +
'var socket = io("http://localhost:8080");\n' +
'socket.on("news", function (data) {\n' +
Expand All @@ -16,7 +16,6 @@ var HTML = '<script src="/socket.io/socket.io.js"></script>\n' +
'});\n' +
'</script>';


///--- Mainline

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


io.on('connection', function (socket) {
io.on('connection', function(socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
socket.on('my other event', function(data) {
console.log(data);
});
});

server.listen(8080, function () {
server.listen(8080, function() {
console.log('socket.io server listening at %s', server.url);
});
Loading

0 comments on commit 8f18166

Please sign in to comment.