From 193468667b84b416cd5c5a9f42bc34deedae858e Mon Sep 17 00:00:00 2001 From: Michaƫl Zasso Date: Sun, 19 Feb 2017 13:45:30 +0100 Subject: tools: enable one-var-declaration-per-line ESLint rule This rule enforces new lines around variable declarations. It is configured to spot only variables that are initialized. PR-URL: https://github.com/nodejs/node/pull/11462 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto Reviewed-By: Gibson Fahnestock Reviewed-By: Luigi Pinca --- .eslintrc.yaml | 1 + benchmark/domain/domain-fn-args.js | 4 ++-- benchmark/es/destructuring-bench.js | 8 ++++---- lib/child_process.js | 3 ++- lib/readline.js | 4 ++-- lib/repl.js | 4 +++- lib/util.js | 4 +++- test/parallel/test-child-process-fork-net2.js | 4 ++-- test/parallel/test-fs-realpath.js | 3 ++- test/parallel/test-http-get-pipeline-problem.js | 3 ++- test/parallel/test-tcp-wrap-listen.js | 3 ++- test/parallel/test-whatwg-url-searchparams.js | 3 ++- test/pummel/test-net-pause.js | 3 ++- 13 files changed, 29 insertions(+), 18 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index feb944f40b..b0337c1525 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -103,6 +103,7 @@ rules: no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}] no-tabs: 2 no-trailing-spaces: 2 + one-var-declaration-per-line: 2 operator-linebreak: [2, after] quotes: [2, single, avoid-escape] semi: 2 diff --git a/benchmark/domain/domain-fn-args.js b/benchmark/domain/domain-fn-args.js index e9b24811c8..20f452d67a 100644 --- a/benchmark/domain/domain-fn-args.js +++ b/benchmark/domain/domain-fn-args.js @@ -12,14 +12,14 @@ var gargs = [1, 2, 3]; function main(conf) { - var args, n = +conf.n; + var n = +conf.n; var myArguments = gargs.slice(0, conf.arguments); bench.start(); bdomain.enter(); for (var i = 0; i < n; i++) { if (myArguments.length >= 2) { - args = Array.prototype.slice.call(myArguments, 1); + const args = Array.prototype.slice.call(myArguments, 1); fn.apply(this, args); } else { fn.call(this); diff --git a/benchmark/es/destructuring-bench.js b/benchmark/es/destructuring-bench.js index 0e9b5e93f3..3288e009a0 100644 --- a/benchmark/es/destructuring-bench.js +++ b/benchmark/es/destructuring-bench.js @@ -9,9 +9,9 @@ const bench = common.createBenchmark(main, { }); function runSwapManual(n) { - var i = 0, x, y, r; + var x, y, r; bench.start(); - for (; i < n; i++) { + for (var i = 0; i < n; i++) { x = 1, y = 2; r = x; x = y; @@ -23,9 +23,9 @@ function runSwapManual(n) { } function runSwapDestructured(n) { - var i = 0, x, y; + var x, y; bench.start(); - for (; i < n; i++) { + for (var i = 0; i < n; i++) { x = 1, y = 2; [x, y] = [y, x]; assert.strictEqual(x, 2); diff --git a/lib/child_process.js b/lib/child_process.js index 3aba06c57b..f98cc3d5c7 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -126,7 +126,8 @@ exports.exec = function(command /*, options, callback*/) { exports.execFile = function(file /*, args, options, callback*/) { - var args = [], callback; + var args = []; + var callback; var options = { encoding: 'utf8', timeout: 0, diff --git a/lib/readline.js b/lib/readline.js index f1b9db46af..a571657a72 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -427,9 +427,9 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) { if (!maxColumns || maxColumns === Infinity) { maxColumns = 1; } - var group = [], c; + var group = []; for (var i = 0, compLen = completions.length; i < compLen; i++) { - c = completions[i]; + var c = completions[i]; if (c === '') { handleGroup(self, group, width, maxColumns); group = []; diff --git a/lib/repl.js b/lib/repl.js index abb593caf1..60b68dc05b 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -266,7 +266,9 @@ function REPLServer(prompt, code = code.replace(/\n$/, ''); code = preprocess(code); - var err, result, retry = false, input = code, wrappedErr; + var retry = false; + var input = code; + var err, result, wrappedErr; // first, create the Script object to check the syntax if (code === '\n') diff --git a/lib/util.js b/lib/util.js index 96a9c70e99..6453727ad8 100644 --- a/lib/util.js +++ b/lib/util.js @@ -413,8 +413,10 @@ function formatValue(ctx, value, recurseTimes) { } } - var base = '', empty = false, braces; + var base = ''; + var empty = false; var formatter = formatObject; + var braces; // We can't compare constructors for various objects using a comparison like // `constructor === Array` because the object could have come from a different diff --git a/test/parallel/test-child-process-fork-net2.js b/test/parallel/test-child-process-fork-net2.js index ef8575385a..5dbae25a01 100644 --- a/test/parallel/test-child-process-fork-net2.js +++ b/test/parallel/test-child-process-fork-net2.js @@ -97,9 +97,9 @@ if (process.argv[2] === 'child') { let disconnected = 0; server.on('listening', function() { - let j = count, client; + let j = count; while (j--) { - client = net.connect(this.address().port, '127.0.0.1'); + const client = net.connect(this.address().port, '127.0.0.1'); client.on('error', function() { // This can happen if we kill the child too early. // The client should still get a close event afterwards. diff --git a/test/parallel/test-fs-realpath.js b/test/parallel/test-fs-realpath.js index aeb48e1edb..331cec5ee8 100644 --- a/test/parallel/test-fs-realpath.js +++ b/test/parallel/test-fs-realpath.js @@ -4,7 +4,8 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); const exec = require('child_process').exec; -let async_completed = 0, async_expected = 0; +let async_completed = 0; +let async_expected = 0; const unlink = []; let skipSymlinks = false; diff --git a/test/parallel/test-http-get-pipeline-problem.js b/test/parallel/test-http-get-pipeline-problem.js index 56bfb33456..e3de0bd16c 100644 --- a/test/parallel/test-http-get-pipeline-problem.js +++ b/test/parallel/test-http-get-pipeline-problem.js @@ -16,7 +16,8 @@ const image = fs.readFileSync(common.fixturesDir + '/person.jpg'); console.log('image.length = ' + image.length); const total = 10; -let requests = 0, responses = 0; +let requests = 0; +let responses = 0; const server = http.Server(function(req, res) { if (++requests === total) { diff --git a/test/parallel/test-tcp-wrap-listen.js b/test/parallel/test-tcp-wrap-listen.js index 7200dac59f..9b9f3a84f1 100644 --- a/test/parallel/test-tcp-wrap-listen.js +++ b/test/parallel/test-tcp-wrap-listen.js @@ -15,7 +15,8 @@ port = port.port; server.listen(128); -let sliceCount = 0, eofCount = 0; +let sliceCount = 0; +let eofCount = 0; let writeCount = 0; let recvCount = 0; diff --git a/test/parallel/test-whatwg-url-searchparams.js b/test/parallel/test-whatwg-url-searchparams.js index d855ccee84..36fac3a230 100644 --- a/test/parallel/test-whatwg-url-searchparams.js +++ b/test/parallel/test-whatwg-url-searchparams.js @@ -36,7 +36,8 @@ assert.strictEqual(m.search, `?${serialized}`); assert.strictEqual(sp[Symbol.iterator], sp.entries); -let key, val, n = 0; +let key, val; +let n = 0; for ([key, val] of sp) { assert.strictEqual(key, 'a'); assert.strictEqual(val, String(values[n++])); diff --git a/test/pummel/test-net-pause.js b/test/pummel/test-net-pause.js index 6a701d5686..b850b1179c 100644 --- a/test/pummel/test-net-pause.js +++ b/test/pummel/test-net-pause.js @@ -4,7 +4,8 @@ const assert = require('assert'); const net = require('net'); const N = 200; -let recv = '', chars_recved = 0; +let recv = ''; +let chars_recved = 0; const server = net.createServer(function(connection) { function write(j) { -- cgit v1.2.3