Skip to content

Commit

Permalink
test: enable linting for tests
Browse files Browse the repository at this point in the history
Enable linting for the test directory. A number of changes was made so
all tests conform the current rules used by lib and src directories. The
only exception for tests is that unreachable (dead) code is allowed.

test-fs-non-number-arguments-throw had to be excluded from the changes
because of a weird issue on Windows CI.

PR-URL: #1721
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
silverwind committed May 19, 2015
1 parent 85d9983 commit f29762f
Show file tree
Hide file tree
Showing 985 changed files with 2,278 additions and 1,125 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
lib/punycode.js
test/fixtures
test/**/node_modules
test/parallel/test-fs-non-number-arguments-throw.js
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ecmaFeatures:
octalLiterals: true
binaryLiterals: true
generators: true
forOf: true

rules:
# Possible Errors
Expand Down Expand Up @@ -54,6 +55,10 @@ rules:
space-infix-ops: 2
## require spaces return, throw, case
space-return-throw-case: 2
## no space before function, eg. 'function()'
space-before-function-paren: [2, "never"]
## require space before blocks, eg 'function() {'
space-before-blocks: [2, "always"]
## require parens for Constructor
new-parens: 2
## max 80 length
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ bench-idle:
./$(NODE_EXE) benchmark/idle_clients.js &

jslint:
./$(NODE_EXE) tools/eslint/bin/eslint.js src lib --reset --quiet
./$(NODE_EXE) tools/eslint/bin/eslint.js src lib test --reset --quiet

CPPLINT_EXCLUDE ?=
CPPLINT_EXCLUDE += src/node_lttng.cc
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Test-specific linter rules

rules:
## allow unreachable code
no-unreachable: 0
7 changes: 4 additions & 3 deletions test/addons/async-hello-world/test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use strict';
var assert = require('assert');
var binding = require('./build/Release/binding');
var called = false;

process.on('exit', function () {
process.on('exit', function() {
assert(called);
});

binding(5, function (err, val) {
binding(5, function(err, val) {
assert.equal(null, err);
assert.equal(10, val);
process.nextTick(function () {
process.nextTick(function() {
called = true;
});
});
1 change: 1 addition & 0 deletions test/addons/at-exit/test.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
var binding = require('./build/Release/binding');
1 change: 1 addition & 0 deletions test/addons/hello-world-function-export/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var assert = require('assert');
var binding = require('./build/Release/binding');
assert.equal('world', binding());
Expand Down
1 change: 1 addition & 0 deletions test/addons/hello-world/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var assert = require('assert');
var binding = require('./build/Release/binding');
assert.equal('world', binding.hello());
Expand Down
1 change: 1 addition & 0 deletions test/addons/repl-domain-abort/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var assert = require('assert');
var repl = require('repl');
var stream = require('stream');
Expand Down
1 change: 1 addition & 0 deletions test/addons/smalloc-alloc/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var assert = require('assert');
var binding = require('./build/Release/binding');
var obj = binding.alloc(16);
Expand Down
23 changes: 12 additions & 11 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var path = require('path');
var fs = require('fs');
var assert = require('assert');
Expand Down Expand Up @@ -107,8 +108,8 @@ if (process.env.NODE_COMMON_PIPE) {
if (process.platform === 'win32') {
exports.faketimeCli = false;
} else {
exports.faketimeCli = path.join(__dirname, "..", "tools", "faketime", "src",
"faketime");
exports.faketimeCli = path.join(__dirname, '..', 'tools', 'faketime', 'src',
'faketime');
}

var ifaces = os.networkInterfaces();
Expand Down Expand Up @@ -307,7 +308,7 @@ exports.mustCall = function(fn, expected) {
var context = {
expected: expected,
actual: 0,
stack: (new Error).stack,
stack: (new Error()).stack,
name: fn.name || '<anonymous>'
};

Expand Down Expand Up @@ -345,11 +346,11 @@ if (process.platform === 'win32') {
*/
exports.getServiceName = function getServiceName(port, protocol) {
if (port == null) {
throw new Error("Missing port number");
throw new Error('Missing port number');
}

if (typeof protocol !== 'string') {
throw new Error("Protocol must be a string");
throw new Error('Protocol must be a string');
}

/*
Expand All @@ -360,10 +361,10 @@ exports.getServiceName = function getServiceName(port, protocol) {

try {
/*
* I'm not a big fan of readFileSync, but reading /etc/services asynchronously
* here would require implementing a simple line parser, which seems overkill
* for a simple utility function that is not running concurrently with any
* other one.
* I'm not a big fan of readFileSync, but reading /etc/services
* asynchronously here would require implementing a simple line parser,
* which seems overkill for a simple utility function that is not running
* concurrently with any other one.
*/
var servicesContent = fs.readFileSync(etcServicesFileName,
{ encoding: 'utf8'});
Expand All @@ -380,7 +381,7 @@ exports.getServiceName = function getServiceName(port, protocol) {
}

return serviceName;
}
};

exports.hasMultiLocalhost = function hasMultiLocalhost() {
var TCP = process.binding('tcp_wrap').TCP;
Expand All @@ -397,7 +398,7 @@ exports.isValidHostname = function(str) {
'(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*$');

return !!str.match(re) && str.length <= 255;
}
};

exports.fileExists = function(pathname) {
try {
Expand Down
3 changes: 2 additions & 1 deletion test/debugger/helper-debugger-repl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var common = require('../common');
var assert = require('assert');
Expand Down Expand Up @@ -55,7 +56,7 @@ function startDebugger(scriptToDebug) {
quitCalled = true;
child.stdin.write('quit');
child.kill('SIGTERM');
}
};

setTimeout(function() {
console.error('dying badly buffer=%j', buffer);
Expand Down
3 changes: 2 additions & 1 deletion test/debugger/test-debug-break-on-uncaught.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var path = require('path');
var assert = require('assert');
var spawn = require('child_process').spawn;
Expand Down Expand Up @@ -44,7 +45,7 @@ function runScenario(scriptName, throwsInFile, throwsOnLine, next) {
child.on('close', function() {
assert(asserted, 'debugger did not pause on exception');
if (next) next();
})
});

var exceptions = [];

Expand Down
7 changes: 4 additions & 3 deletions test/debugger/test-debugger-client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var common = require('../common');
var assert = require('assert');
Expand Down Expand Up @@ -66,7 +67,7 @@ var d = 'Content-Length: 466\r\n\r\n' +
'{"seq":10,"type":"event","event":"afterCompile","success":true,' +
'"body":{"script":{"handle":1,"type":"script","name":"dns.js",' +
'"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' +
'"sourceStart":"(function (module, exports, require) {' +
'"sourceStart":"(function(module, exports, require) {' +
'var dns = process.binding(\'cares\')' +
';\\nvar ne","sourceLength":6137,"scriptType":2,"compilationType":0,' +
'"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' +
Expand Down Expand Up @@ -127,8 +128,8 @@ addTest(function(client, done) {


var connectCount = 0;
var script = 'setTimeout(function () { console.log("blah"); });' +
'setInterval(function () {}, 1000000);';
var script = 'setTimeout(function() { console.log("blah"); });' +
'setInterval(function() {}, 1000000);';

var nodeProcess;

Expand Down
1 change: 1 addition & 0 deletions test/debugger/test-debugger-debug-brk.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
Expand Down
1 change: 1 addition & 0 deletions test/debugger/test-debugger-remote.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
Expand Down
1 change: 1 addition & 0 deletions test/debugger/test-debugger-repl-break-in-module.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var repl = require('./helper-debugger-repl.js');

repl.startDebugger('break-in-module/main.js');
Expand Down
3 changes: 2 additions & 1 deletion test/debugger/test-debugger-repl-restart.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var repl = require('./helper-debugger-repl.js');

repl.startDebugger('breakpoints.js');
Expand All @@ -7,7 +8,7 @@ var linesWithBreakpoint = [
// We slice here, because addTest will change the given array.
repl.addTest('sb(6)', linesWithBreakpoint.slice());

var initialLines = repl.initialLines.slice()
var initialLines = repl.initialLines.slice();
initialLines.splice(2, 0, /Restoring/, /Warning/);

// Restart the debugged script
Expand Down
1 change: 1 addition & 0 deletions test/debugger/test-debugger-repl-term.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
process.env.NODE_FORCE_READLINE = 1;

var repl = require('./helper-debugger-repl.js');
Expand Down
1 change: 1 addition & 0 deletions test/debugger/test-debugger-repl-utf8.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var script = common.fixturesDir + '/breakpoints_utf8.js';
process.env.NODE_DEBUGGER_TEST_SCRIPT = script;
Expand Down
1 change: 1 addition & 0 deletions test/debugger/test-debugger-repl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var repl = require('./helper-debugger-repl.js');

repl.startDebugger('breakpoints.js');
Expand Down
1 change: 1 addition & 0 deletions test/disabled/GH-670.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var https = require('https');
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-cat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common.js');
var assert = require('assert');
var http = require('http');
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-child-process-custom-fds.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-child-process-customfd-bounded.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');

var bigish = Array(200);
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-child-process-uid-gid.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-debug-brk-file.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-debug-brk-no-arg.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-dgram-multicast.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-dgram-send-error.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
// Some operating systems report errors when an UDP message is sent to an
// unreachable host. This error can be reported by sendto() and even by
// recvfrom(). Node should not propagate this error to the user.
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-dgram-unix-anon.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-dgram-unix.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down
3 changes: 2 additions & 1 deletion test/disabled/test-eio-race.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down Expand Up @@ -36,7 +37,7 @@ function tryToKillEventLoop() {

// Generate a lot of thread pool events
var pos = 0;
fs.open(filename, 'r', 0666, function(err, fd) {
fs.open(filename, 'r', 0o666, function(err, fd) {
if (err) throw err;

function readChunk() {
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-eio-race2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path');
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-eio-race3.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/* XXX Can this test be modified to not call the now-removed wait()? */

var common = require('../common');
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-eio-race4.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-fs-largefile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path'),
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-http-abort-stream-end.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-http-agent2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var http = require('http');
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-http-big-proxy-responses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var util = require('util'),
Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-http-head-request.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-http-stress.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down
1 change: 1 addition & 0 deletions test/disabled/test-http-tls.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var common = require('../common');
var assert = require('assert');

Expand Down
Loading

0 comments on commit f29762f

Please sign in to comment.