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

test: apply no-useless-concat ESLint rule #12613

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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ rules:
no-throw-literal: 2
no-unused-labels: 2
no-useless-call: 2
no-useless-concat: 2
no-useless-escape: 2
no-useless-return: 2
no-void: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ function createTestCmdLine(options) {
testCmd += process.argv[0];

if (options && options.withAbortOnUncaughtException) {
testCmd += ' ' + '--abort-on-uncaught-exception';
testCmd += ' --abort-on-uncaught-exception';
}

testCmd += ' ' + process.argv[1];
testCmd += ' ' + 'child';
testCmd += ` ${process.argv[1]} child`;

return testCmd;
}
4 changes: 2 additions & 2 deletions test/parallel/test-http-server-unconsume-consume.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const http = require('http');

const testServer = http.createServer(common.mustNotCall());
testServer.on('connect', common.mustCall((req, socket, head) => {
socket.write('HTTP/1.1 200 Connection Established' + '\r\n' +
'Proxy-agent: Node-Proxy' + '\r\n' +
socket.write('HTTP/1.1 200 Connection Established\r\n' +
'Proxy-agent: Node-Proxy\r\n' +
Copy link
Contributor

@mscdex mscdex Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why the new eslint rule didn't complain about the next '\r\n' not being included as well? I guess it only considers string literals that are in between two other literals?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't report multiline concatenations because people often use those intentionally (e.g. to avoid long lines).

Related: eslint/eslint#7947

Copy link
Contributor Author

@vsemozhetbyt vsemozhetbyt Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just keeps strings in different lines:

Examples of correct code for this rule... when the string concatenation is multiline

Copy link
Contributor

@not-an-aardvark not-an-aardvark Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and that's why it didn't complain about the next '\r\n'.

I think we're both saying the same thing -- did I misunderstand the question?

edit: Never mind, I didn't read the author of the last reply and thought it was from @mscdex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was writing while your answer did not appear yet)

'\r\n');
// This shouldn't raise an assertion in StreamBase::Consume.
testServer.emit('connection', socket);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-set-trailers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let outstanding_reqs = 0;
const server = http.createServer(function(req, res) {
res.writeHead(200, [['content-type', 'text/plain']]);
res.addTrailers({'x-foo': 'bar'});
res.end('stuff' + '\n');
res.end('stuff\n');
});
server.listen(0);

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-write-connect-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const server = net.createServer(function(socket) {
conn.setEncoding('utf8');
conn.write('before');
conn.on('connect', function() {
conn.write('after');
conn.write(' after');
});
conn.on('data', function(buf) {
received += buf;
conn.end();
});
conn.on('end', common.mustCall(function() {
server.close();
assert.strictEqual(received, 'before' + 'after');
assert.strictEqual(received, 'before after');
}));
}));
6 changes: 3 additions & 3 deletions test/parallel/test-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ interactive.stdin.write('a\n');
interactive.stdin.write('process.exit()\n');

childProcess.exec(
nodeBinary + ' ' + '--require ' + fixture('cluster-preload.js') + ' ' +
`${nodeBinary} --require ${fixture('cluster-preload.js')} ` +
fixture('cluster-preload-test.js'),
function(err, stdout, stderr) {
assert.ifError(err);
Expand All @@ -139,8 +139,8 @@ childProcess.exec(
// https://github.com/nodejs/node/issues/1691
process.chdir(common.fixturesDir);
childProcess.exec(
nodeBinary + ' ' + '--expose_natives_as=v8natives ' + '--require ' +
fixture('cluster-preload.js') + ' ' + 'cluster-preload-test.js',
`${nodeBinary} --expose_natives_as=v8natives --require ` +
`${fixture('cluster-preload.js')} cluster-preload-test.js`,
function(err, stdout, stderr) {
assert.ifError(err);
assert.ok(/worker terminated with code 43/.test(stdout));
Expand Down
14 changes: 7 additions & 7 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,12 @@ function tcp_test() {
{ client: client_tcp, send: '',
expect: prompt_tcp },
{ client: client_tcp, send: 'invoke_me(333)',
expect: ('\'' + 'invoked 333' + '\'\n' + prompt_tcp) },
expect: (`'invoked 333'\n${prompt_tcp}`) },
{ client: client_tcp, send: 'a += 1',
expect: ('12346' + '\n' + prompt_tcp) },
expect: (`12346\n${prompt_tcp}`) },
{ client: client_tcp,
send: 'require(' + JSON.stringify(moduleFilename) + ').number',
expect: ('42' + '\n' + prompt_tcp) }
expect: (`42\n${prompt_tcp}`) }
]);
});

Expand Down Expand Up @@ -511,13 +511,13 @@ function unix_test() {
{ client: client_unix, send: '',
expect: prompt_unix },
{ client: client_unix, send: 'message',
expect: ('\'' + message + '\'\n' + prompt_unix) },
expect: (`'${message}'\n${prompt_unix}`) },
{ client: client_unix, send: 'invoke_me(987)',
expect: ('\'' + 'invoked 987' + '\'\n' + prompt_unix) },
expect: (`'invoked 987'\n${prompt_unix}`) },
{ client: client_unix, send: 'a = 12345',
expect: ('12345' + '\n' + prompt_unix) },
expect: (`12345\n${prompt_unix}`) },
{ client: client_unix, send: '{a:1}',
expect: ('{ a: 1 }' + '\n' + prompt_unix) }
expect: (`{ a: 1 }\n${prompt_unix}`) }
]);
});

Expand Down
7 changes: 2 additions & 5 deletions test/sequential/test-domain-abort-on-uncaught.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,8 @@ if (process.argv[2] === 'child') {
testCmd += 'ulimit -c 0 && ';
}

testCmd += process.argv[0];
testCmd += ' ' + '--abort-on-uncaught-exception';
testCmd += ' ' + process.argv[1];
testCmd += ' ' + 'child';
testCmd += ' ' + testIndex;
testCmd += `${process.argv[0]} --abort-on-uncaught-exception ` +
`${process.argv[1]} child ${testIndex}`;

const child = child_process.exec(testCmd);

Expand Down