Skip to content

Commit eea2eb9

Browse files
targosaddaleax
authored andcommitted
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: #11462 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 34220b7 commit eea2eb9

13 files changed

+29
-18
lines changed

.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ rules:
103103
no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}]
104104
no-tabs: 2
105105
no-trailing-spaces: 2
106+
one-var-declaration-per-line: 2
106107
operator-linebreak: [2, after]
107108
quotes: [2, single, avoid-escape]
108109
semi: 2

benchmark/domain/domain-fn-args.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ var gargs = [1, 2, 3];
1212

1313
function main(conf) {
1414

15-
var args, n = +conf.n;
15+
var n = +conf.n;
1616
var myArguments = gargs.slice(0, conf.arguments);
1717
bench.start();
1818

1919
bdomain.enter();
2020
for (var i = 0; i < n; i++) {
2121
if (myArguments.length >= 2) {
22-
args = Array.prototype.slice.call(myArguments, 1);
22+
const args = Array.prototype.slice.call(myArguments, 1);
2323
fn.apply(this, args);
2424
} else {
2525
fn.call(this);

benchmark/es/destructuring-bench.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const bench = common.createBenchmark(main, {
99
});
1010

1111
function runSwapManual(n) {
12-
var i = 0, x, y, r;
12+
var x, y, r;
1313
bench.start();
14-
for (; i < n; i++) {
14+
for (var i = 0; i < n; i++) {
1515
x = 1, y = 2;
1616
r = x;
1717
x = y;
@@ -23,9 +23,9 @@ function runSwapManual(n) {
2323
}
2424

2525
function runSwapDestructured(n) {
26-
var i = 0, x, y;
26+
var x, y;
2727
bench.start();
28-
for (; i < n; i++) {
28+
for (var i = 0; i < n; i++) {
2929
x = 1, y = 2;
3030
[x, y] = [y, x];
3131
assert.strictEqual(x, 2);

lib/child_process.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ exports.exec = function(command /*, options, callback*/) {
112112

113113

114114
exports.execFile = function(file /*, args, options, callback*/) {
115-
var args = [], callback;
115+
var args = [];
116+
var callback;
116117
var options = {
117118
encoding: 'utf8',
118119
timeout: 0,

lib/readline.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
427427
if (!maxColumns || maxColumns === Infinity) {
428428
maxColumns = 1;
429429
}
430-
var group = [], c;
430+
var group = [];
431431
for (var i = 0, compLen = completions.length; i < compLen; i++) {
432-
c = completions[i];
432+
var c = completions[i];
433433
if (c === '') {
434434
handleGroup(self, group, width, maxColumns);
435435
group = [];

lib/repl.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ function REPLServer(prompt,
266266
code = code.replace(/\n$/, '');
267267
code = preprocess(code);
268268

269-
var err, result, retry = false, input = code, wrappedErr;
269+
var retry = false;
270+
var input = code;
271+
var err, result, wrappedErr;
270272
// first, create the Script object to check the syntax
271273

272274
if (code === '\n')

lib/util.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,10 @@ function formatValue(ctx, value, recurseTimes) {
449449
}
450450
}
451451

452-
var base = '', empty = false, braces;
452+
var base = '';
453+
var empty = false;
453454
var formatter = formatObject;
455+
var braces;
454456

455457
// We can't compare constructors for various objects using a comparison like
456458
// `constructor === Array` because the object could have come from a different

test/parallel/test-child-process-fork-net2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ if (process.argv[2] === 'child') {
9797
let disconnected = 0;
9898
server.on('listening', function() {
9999

100-
let j = count, client;
100+
let j = count;
101101
while (j--) {
102-
client = net.connect(this.address().port, '127.0.0.1');
102+
const client = net.connect(this.address().port, '127.0.0.1');
103103
client.on('error', function() {
104104
// This can happen if we kill the child too early.
105105
// The client should still get a close event afterwards.

test/parallel/test-fs-realpath.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const assert = require('assert');
44
const fs = require('fs');
55
const path = require('path');
66
const exec = require('child_process').exec;
7-
let async_completed = 0, async_expected = 0;
7+
let async_completed = 0;
8+
let async_expected = 0;
89
const unlink = [];
910
let skipSymlinks = false;
1011

test/parallel/test-http-get-pipeline-problem.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const image = fs.readFileSync(common.fixturesDir + '/person.jpg');
1616
console.log('image.length = ' + image.length);
1717

1818
const total = 10;
19-
let requests = 0, responses = 0;
19+
let requests = 0;
20+
let responses = 0;
2021

2122
const server = http.Server(function(req, res) {
2223
if (++requests === total) {

test/parallel/test-tcp-wrap-listen.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ port = port.port;
1515

1616
server.listen(128);
1717

18-
let sliceCount = 0, eofCount = 0;
18+
let sliceCount = 0;
19+
let eofCount = 0;
1920

2021
let writeCount = 0;
2122
let recvCount = 0;

test/parallel/test-whatwg-url-searchparams.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ assert.strictEqual(m.search, `?${serialized}`);
3636

3737
assert.strictEqual(sp[Symbol.iterator], sp.entries);
3838

39-
let key, val, n = 0;
39+
let key, val;
40+
let n = 0;
4041
for ([key, val] of sp) {
4142
assert.strictEqual(key, 'a');
4243
assert.strictEqual(val, String(values[n++]));

test/pummel/test-net-pause.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const assert = require('assert');
44
const net = require('net');
55

66
const N = 200;
7-
let recv = '', chars_recved = 0;
7+
let recv = '';
8+
let chars_recved = 0;
89

910
const server = net.createServer(function(connection) {
1011
function write(j) {

0 commit comments

Comments
 (0)