Skip to content

Commit

Permalink
lib,src: fix block-scoped-var linter errors
Browse files Browse the repository at this point in the history
As per block-scoped-var rule, the variables which were used before
declaration or declared within a block and used outside are trated
as linter errors.

Refer: nodejs#3118
  • Loading branch information
thefourtheye committed Oct 4, 2015
1 parent c99bdb2 commit cd2d641
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 37 deletions.
6 changes: 3 additions & 3 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,8 @@ Interface.prototype.setBreakpoint = function(script, line,

var self = this,
scriptId,
ambiguous;
ambiguous,
req;

// setBreakpoint() should insert breakpoint on current line
if (script === undefined) {
Expand All @@ -1347,7 +1348,7 @@ Interface.prototype.setBreakpoint = function(script, line,

if (/\(\)$/.test(script)) {
// setBreakpoint('functionname()');
var req = {
req = {
type: 'function',
target: script.replace(/\(\)$/, ''),
condition: condition
Expand All @@ -1373,7 +1374,6 @@ Interface.prototype.setBreakpoint = function(script, line,
if (ambiguous) return this.error('Script name is ambiguous');
if (line <= 0) return this.error('Line should be a positive value');

var req;
if (scriptId) {
req = {
type: 'scriptId',
Expand Down
8 changes: 5 additions & 3 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ function ClientRequest(options, cb) {

var port = options.port = options.port || defaultPort || 80;
var host = options.host = options.hostname || options.host || 'localhost';
var setHost;

if (options.setHost === undefined) {
var setHost = true;
setHost = true;
}

self.socketPath = options.socketPath;
Expand Down Expand Up @@ -138,11 +139,12 @@ function ClientRequest(options, cb) {
// No agent, default to Connection:close.
self._last = true;
self.shouldKeepAlive = false;
var conn;
if (options.createConnection) {
var conn = options.createConnection(options);
conn = options.createConnection(options);
} else {
debug('CLIENT use net.createConnection', options);
var conn = net.createConnection(options);
conn = net.createConnection(options);
}
self.onSocket(conn);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,11 @@ Readable.prototype.pause = function() {

function flow(stream) {
var state = stream._readableState;
var chunk;
debug('flow', state.flowing);
if (state.flowing) {
do {
var chunk = stream.read();
chunk = stream.read();
} while (null !== chunk && state.flowing);
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,12 @@ function slowToString(encoding, start, end) {


Buffer.prototype.toString = function() {
var result;

if (arguments.length === 0) {
var result = this.utf8Slice(0, this.length);
result = this.utf8Slice(0, this.length);
} else {
var result = slowToString.apply(this, arguments);
result = slowToString.apply(this, arguments);
}
if (result === undefined)
throw new Error('toString failed');
Expand Down
3 changes: 2 additions & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ exports._createSocketHandle = function(address, port, addressType, fd, flags) {


function Socket(type, listener) {
var options;
EventEmitter.call(this);

if (typeof type === 'object') {
var options = type;
options = type;
type = options.type;
}

Expand Down
7 changes: 4 additions & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1454,9 +1454,9 @@ fs.realpathSync = function realpathSync(p, cache) {

// read the link if it wasn't read before
// dev/ino always return 0 on windows, so skip the check.
var linkTarget = null;
var linkTarget = null, id;
if (!isWindows) {
var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
if (seenLinks.hasOwnProperty(id)) {
linkTarget = seenLinks[id];
}
Expand Down Expand Up @@ -1561,6 +1561,7 @@ fs.realpath = function realpath(p, cache, cb) {
}

function gotStat(err, stat) {
var id;
if (err) return cb(err);

// if not a symlink, skip to the next path part
Expand All @@ -1574,7 +1575,7 @@ fs.realpath = function realpath(p, cache, cb) {
// call gotTarget as soon as the link target is known
// dev/ino always return 0 on windows, so skip the check.
if (!isWindows) {
var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
if (seenLinks.hasOwnProperty(id)) {
return gotTarget(null, seenLinks[id], base);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ function setupChannel(target, channel) {

target._send = function(message, handle, swallowErrors, callback) {
assert(this.connected || this._channel);
var obj;

if (message === undefined)
throw new TypeError('message cannot be undefined');
Expand Down Expand Up @@ -554,7 +555,7 @@ function setupChannel(target, channel) {
return;
}

var obj = handleConversion[message.type];
obj = handleConversion[message.type];

// convert TCP object to native handle object
handle =
Expand Down
9 changes: 6 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const debug = Module._debug;
const packageMainCache = {};

function readPackage(requestPath) {
var pkg;

if (hasOwnProperty(packageMainCache, requestPath)) {
return packageMainCache[requestPath];
}
Expand All @@ -76,7 +78,7 @@ function readPackage(requestPath) {
}

try {
var pkg = packageMainCache[requestPath] = JSON.parse(json).main;
pkg = packageMainCache[requestPath] = JSON.parse(json).main;
} catch (e) {
e.path = jsonPath;
e.message = 'Error parsing ' + jsonPath + ': ' + e.message;
Expand Down Expand Up @@ -469,11 +471,12 @@ Module.runMain = function() {

Module._initPaths = function() {
const isWindows = process.platform === 'win32';
var homeDir;

if (isWindows) {
var homeDir = process.env.USERPROFILE;
homeDir = process.env.USERPROFILE;
} else {
var homeDir = process.env.HOME;
homeDir = process.env.HOME;
}

var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
Expand Down
6 changes: 4 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,9 @@ Server.prototype.getConnections = function(cb) {


Server.prototype.close = function(cb) {
var left;
var self = this;

function onSlaveClose() {
if (--left !== 0) return;

Expand All @@ -1481,8 +1484,7 @@ Server.prototype.close = function(cb) {
}

if (this._usingSlaves) {
var self = this,
left = this._slaves.length;
left = this._slaves.length;

// Increment connections to be sure that, even if all sockets will be closed
// during polling of slaves, `close` event will be emitted only once.
Expand Down
3 changes: 2 additions & 1 deletion lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ function normalizeUNCRoot(device) {
win32.resolve = function() {
var resolvedDevice = '',
resolvedTail = '',
resolvedAbsolute = false;
resolvedAbsolute = false,
isUnc;

for (var i = arguments.length - 1; i >= -1; i--) {
var path;
Expand Down
4 changes: 2 additions & 2 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function charCode(c) {
QueryString.unescapeBuffer = function(s, decodeSpaces) {
var out = new Buffer(s.length);
var state = 'CHAR'; // states: CHAR, HEX0, HEX1
var n, m, hexchar;
var n, m, hexchar, outIndex = 0;

for (var inIndex = 0, outIndex = 0; inIndex <= s.length; inIndex++) {
for (var inIndex = 0; inIndex <= s.length; inIndex++) {
var c = s.charCodeAt(inIndex);
switch (state) {
case 'CHAR':
Expand Down
4 changes: 2 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function REPLServer(prompt,
eval_ = eval_ || defaultEval;

function defaultEval(code, context, file, cb) {
var err, result, retry = false;
var err, result, retry = false, script;
// first, create the Script object to check the syntax
while (true) {
try {
Expand All @@ -134,7 +134,7 @@ function REPLServer(prompt,
// result value for let/const statements.
code = `'use strict'; void 0; ${code}`;
}
var script = vm.createScript(code, {
script = vm.createScript(code, {
filename: file,
displayErrors: false
});
Expand Down
6 changes: 4 additions & 2 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
}

var proto = protocolPattern.exec(rest);
var slashes;
var lowerProto;
if (proto) {
proto = proto[0];
var lowerProto = proto.toLowerCase();
lowerProto = proto.toLowerCase();
this.protocol = lowerProto;
rest = rest.substr(proto.length);
}
Expand All @@ -142,7 +144,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// resolution will treat //foo/bar as host=foo,path=bar because that's
// how the browser resolves relative URLs.
if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
var slashes = rest.substr(0, 2) === '//';
slashes = rest.substr(0, 2) === '//';
if (slashes && !(proto && hostlessProtocol[proto])) {
rest = rest.substr(2);
this.slashes = true;
Expand Down
19 changes: 10 additions & 9 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,11 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
var self = this;

var async = typeof cb === 'function';
var buffers = [];
var nread = 0;

if (!async) {
var buffers = [];
var nread = 0;
var res;

var error;
this.on('error', function(er) {
Expand All @@ -522,13 +523,13 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {

assert(!this._closed, 'zlib binding closed');
do {
var res = this._handle.writeSync(flushFlag,
chunk, // in
inOff, // in_off
availInBefore, // in_len
this._buffer, // out
this._offset, //out_off
availOutBefore); // out_len
res = this._handle.writeSync(flushFlag,
chunk, // in
inOff, // in_off
availInBefore, // in_len
this._buffer, // out
this._offset, //out_off
availOutBefore); // out_len
} while (!this._hadError && callback(res[0], res[1]));

if (this._hadError) {
Expand Down
5 changes: 3 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,15 @@
function evalScript(name) {
var Module = NativeModule.require('module');
var path = NativeModule.require('path');
var cwd;

try {
var cwd = process.cwd();
cwd = process.cwd();
} catch (e) {
// getcwd(3) can fail if the current working directory has been deleted.
// Fall back to the directory name of the (absolute) executable path.
// It's not really correct but what are the alternatives?
var cwd = path.dirname(process.execPath);
cwd = path.dirname(process.execPath);
}

var module = new Module(name);
Expand Down

0 comments on commit cd2d641

Please sign in to comment.