Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: switch from closure-linter to eslint #1539

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/punycode.js
91 changes: 91 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
env:
node: true

# enable ECMAScript features
ecmaFeatures:
blockBindings: true
templateStrings: true
octalLiterals: true
binaryLiterals: true

rules:
# Possible Errors
# list: https://github.com/eslint/eslint/tree/master/docs/rules#possible-errors
## check debugger sentence
no-debugger: 2
## check duplicate arguments
no-dupe-args: 2
## check duplicate object keys
no-dupe-keys: 2
## check duplicate switch-case
no-duplicate-case: 2
## disallow assignment of exceptional params
no-ex-assign: 2
## disallow use of reserved words as keys like enum, class
no-reserved-keys: 2
## disallow unreachable code
no-unreachable: 2
## require valid typeof compared string like typeof foo === 'strnig'
valid-typeof: 2

# Best Practices
# list: https://github.com/eslint/eslint/tree/master/docs/rules#best-practices
## require falls through comment on switch-case
no-fallthrough: 2

# Stylistic Issues
# list: https://github.com/eslint/eslint/tree/master/docs/rules#stylistic-issues
## use single quote, we can use double quote when escape chars
quotes:
- 2
- "single"
- "avoid-escape"
## 2 space indentation
indent:
- 2
- 2
## add space after comma
comma-spacing: 2
## put semi-colon
semi: 2
## require spaces operator like var sum = 1 + 1;
space-infix-ops: 2
## require spaces return, throw, case
space-return-throw-case: 2
## require parens for Constructor
new-parens: 2
## max 80 length
max-len:
- 2
- 80
- 2


# Strict Mode
# list: https://github.com/eslint/eslint/tree/master/docs/rules#strict-mode
## 'use strict' on top
strict:
- 2
- "global"

# Global scoped method and vars
globals:
DTRACE_HTTP_CLIENT_REQUEST: true
LTTNG_HTTP_CLIENT_REQUEST: true
COUNTER_HTTP_CLIENT_REQUEST: true
DTRACE_HTTP_CLIENT_RESPONSE: true
LTTNG_HTTP_CLIENT_RESPONSE: true
COUNTER_HTTP_CLIENT_RESPONSE: true
DTRACE_HTTP_SERVER_REQUEST: true
LTTNG_HTTP_SERVER_REQUEST: true
COUNTER_HTTP_SERVER_REQUEST: true
DTRACE_HTTP_SERVER_RESPONSE: true
LTTNG_HTTP_SERVER_RESPONSE: true
COUNTER_HTTP_SERVER_RESPONSE: true
DTRACE_NET_STREAM_END: true
LTTNG_NET_STREAM_END: true
COUNTER_NET_SERVER_CONNECTION_CLOSE: true
DTRACE_NET_SERVER_CONNECTION: true
LTTNG_NET_SERVER_CONNECTION: true
COUNTER_NET_SERVER_CONNECTION: true

5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,8 @@ bench-idle:
sleep 1
./$(NODE_EXE) benchmark/idle_clients.js &

jslintfix:
PYTHONPATH=tools/closure_linter/:tools/gflags/ $(PYTHON) tools/closure_linter/closure_linter/fixjsstyle.py --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js

jslint:
PYTHONPATH=tools/closure_linter/:tools/gflags/ $(PYTHON) tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
./$(NODE_EXE) tools/eslint/bin/eslint.js src/*.js lib/*.js --reset --quiet

CPPLINT_EXCLUDE ?=
CPPLINT_EXCLUDE += src/node_lttng.cc
Expand Down
9 changes: 4 additions & 5 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Protocol.prototype.execute = function(d) {
if (len - this.bodyStartByteIndex < this.contentLength) {
break;
}
// pass thru
// falls through
case 'body':
var resRawByteLength = Buffer.byteLength(res.raw, 'utf8');

Expand All @@ -125,7 +125,6 @@ Protocol.prototype.execute = function(d) {

default:
throw new Error('Unknown state');
break;
}
};

Expand Down Expand Up @@ -262,7 +261,7 @@ Client.prototype.req = function(req, cb) {

Client.prototype.reqVersion = function(cb) {
cb = cb || function() {};
this.req({ command: 'version' } , function(err, body, res) {
this.req({ command: 'version' }, function(err, body, res) {
if (err) return cb(err);
cb(null, res.body.body.V8Version, res.body.running);
});
Expand Down Expand Up @@ -398,7 +397,7 @@ Client.prototype.reqFrameEval = function(expression, frame, cb) {
// reqBacktrace(cb)
// TODO: from, to, bottom
Client.prototype.reqBacktrace = function(cb) {
this.req({ command: 'backtrace', arguments: { inlineRefs: true } } , cb);
this.req({ command: 'backtrace', arguments: { inlineRefs: true } }, cb);
};


Expand Down Expand Up @@ -432,7 +431,7 @@ Client.prototype.reqScripts = function(cb) {
var self = this;
cb = cb || function() {};

this.req({ command: 'scripts' } , function(err, res) {
this.req({ command: 'scripts' }, function(err, res) {
if (err) return cb(err);

for (var i = 0; i < res.length; i++) {
Expand Down
6 changes: 4 additions & 2 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ IncomingMessage.prototype._addHeaderLine = function(field, value, dest) {
}
break;

/* eslint-disable max-len */
// list is taken from:
// https://mxr.mozilla.org/mozilla/source/netwerk/protocol/http/src/nsHttpHeaderArray.cpp
/* eslint-enable max-len */
case 'content-type':
case 'content-length':
case 'user-agent':
Expand All @@ -158,9 +160,9 @@ IncomingMessage.prototype._addHeaderLine = function(field, value, dest) {

default:
// make comma-separated list
if (dest[field] !== undefined)
if (dest[field] !== undefined) {
dest[field] += ', ' + value;
else {
} else {
dest[field] = value;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ OutgoingMessage.prototype.setTimeout = function(msecs, callback) {
this.once('socket', function(socket) {
socket.setTimeout(msecs);
});
} else
} else {
this.socket.setTimeout(msecs);
}
};


Expand Down
2 changes: 2 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,11 @@ function Server(requestListener) {
this.addListener('request', requestListener);
}

/* eslint-disable max-len */
// Similar option to this. Too lazy to write my own docs.
// http://www.squid-cache.org/Doc/config/half_closed_clients/
// http://wiki.squid-cache.org/SquidFaq/InnerWorkings#What_is_a_half-closed_filedescriptor.3F
/* eslint-enable max-len */
this.httpAllowHalfOpen = false;

this.addListener('connection', connectionListener);
Expand Down
5 changes: 3 additions & 2 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ function howMuchToRead(n, state) {
if (!state.ended) {
state.needReadable = true;
return 0;
} else
} else {
return state.length;
}
}

return n;
Expand Down Expand Up @@ -774,7 +775,7 @@ Readable.prototype.wrap = function(stream) {
if (this[i] === undefined && typeof stream[i] === 'function') {
this[i] = function(method) { return function() {
return stream[method].apply(stream, arguments);
}}(i);
}; }(i);
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Writable.WritableState = WritableState;

const util = require('util');
const Stream = require('stream');
const debug = util.debuglog('stream');

util.inherits(Writable, Stream);

Expand Down Expand Up @@ -273,9 +272,9 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) {
} else {
state.bufferedRequest = state.lastBufferedRequest;
}
}
else
} else {
doWrite(stream, state, false, len, chunk, encoding, cb);
}

return ret;
}
Expand Down Expand Up @@ -471,8 +470,9 @@ function finishMaybe(stream, state) {
prefinish(stream, state);
state.finished = true;
stream.emit('finish');
} else
} else {
prefinish(stream, state);
}
}
return need;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/_tls_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ function onnewsession(key, session) {

if (self.ssl)
self.ssl.newSessionDone();
};
}
}


Expand Down
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,4 @@ assert.doesNotThrow = function(block, /*optional*/message) {
_throws.apply(this, [false].concat(pSlice.call(arguments)));
};

assert.ifError = function(err) { if (err) {throw err;}};
assert.ifError = function(err) { if (err) throw err; };
4 changes: 2 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ SocketListSend.prototype._request = function(msg, cmd, callback) {
function onclose() {
self.slave.removeListener('internalMessage', onreply);
callback(new Error('Slave closed before reply'));
};
}

function onreply(msg) {
if (!(msg.cmd === cmd && msg.key === self.key)) return;
self.slave.removeListener('disconnect', onclose);
self.slave.removeListener('internalMessage', onreply);

callback(null, msg);
};
}

this.slave.once('disconnect', onclose);
this.slave.on('internalMessage', onreply);
Expand Down
9 changes: 4 additions & 5 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SCHED_RR = 2;

const uv = process.binding('uv');

const cluster = new EventEmitter;
const cluster = new EventEmitter();
module.exports = cluster;
cluster.Worker = Worker;
cluster.isWorker = ('NODE_UNIQUE_ID' in process.env);
Expand Down Expand Up @@ -127,11 +127,10 @@ RoundRobinHandle.prototype.add = function(worker, send) {
function done() {
if (self.handle.getsockname) {
var out = {};
var err = self.handle.getsockname(out);
self.handle.getsockname(out);
// TODO(bnoordhuis) Check err.
send(null, { sockname: out }, null);
}
else {
} else {
send(null, null, null); // UNIX socket.
}
self.handoff(worker); // In case there are connections pending.
Expand Down Expand Up @@ -196,7 +195,7 @@ else
function masterInit() {
cluster.workers = {};

var intercom = new EventEmitter;
var intercom = new EventEmitter();
cluster.settings = {};

// XXX(bnoordhuis) Fold cluster.schedulingPolicy into cluster.settings?
Expand Down
2 changes: 1 addition & 1 deletion lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Console.prototype.timeEnd = function(label) {
Console.prototype.trace = function trace() {
// TODO probably can to do this better with V8's debug object once that is
// exposed.
var err = new Error;
var err = new Error();
err.name = 'Trace';
err.message = util.format.apply(this, arguments);
Error.captureStackTrace(err, trace);
Expand Down
2 changes: 1 addition & 1 deletion lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function Verify(algorithm, options) {
if (!(this instanceof Verify))
return new Verify(algorithm, options);

this._handle = new binding.Verify;
this._handle = new binding.Verify();
this._handle.init(algorithm);

stream.Writable.call(this, options);
Expand Down
7 changes: 3 additions & 4 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ function lookup6(address, callback) {

function newHandle(type) {
if (type == 'udp4') {
var handle = new UDP;
var handle = new UDP();
handle.lookup = lookup4;
return handle;
}

if (type == 'udp6') {
var handle = new UDP;
var handle = new UDP();
handle.lookup = lookup6;
handle.bind = handle.bind6;
handle.send = handle.send6;
Expand Down Expand Up @@ -301,8 +301,7 @@ Socket.prototype.send = function(buffer,
if (ex) {
if (callback) callback(ex);
self.emit('error', ex);
}
else if (self._handle) {
} else if (self._handle) {
var req = new SendWrap();
req.buffer = buffer; // Keep reference alive.
req.length = length;
Expand Down
2 changes: 1 addition & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function resolver(bindingName) {
if (err) throw errnoException(err, bindingName);
callback.immediately = true;
return req;
}
};
}


Expand Down
3 changes: 2 additions & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,9 @@ EventEmitter.prototype.removeListener =
if (--this._eventsCount === 0) {
this._events = {};
return this;
} else
} else {
delete events[type];
}
} else {
spliceOne(list, position);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function rethrow() {
// Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
// is fairly slow to generate.
if (DEBUG) {
var backtrace = new Error;
var backtrace = new Error();
return function(err) {
if (err) {
backtrace.stack = err.name + ': ' + err.message +
Expand Down
Loading