Skip to content

Commit 5fa95fa

Browse files
authored
lint changes, cherry picked from #3135 (#3138)
1 parent f37d40e commit 5fa95fa

20 files changed

+92
-116
lines changed

dkim.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,7 @@ class DKIMObject {
302302
}
303303
}
304304
if (!res) return this.result('no key for signature', 'invalid');
305-
for (let record of res) {
306-
// Node 0.11.x compatibility
307-
if (Array.isArray(record)) {
308-
record = record.join('');
309-
}
305+
for (const record of res) {
310306
if (!record.includes('p=')) {
311307
this.debug(`${this.identity}: ignoring TXT record: ${record}`);
312308
continue;

logger.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ logger.log = (level, data, logobj) => {
134134
if (level === 'PROTOCOL') {
135135
data = data.replace(/\n/g, '\\n');
136136
}
137-
data = data.replace(/\r/g, '\\r')
138-
.replace(/\n$/, '');
137+
data = data.replace(/\r/g, '\\r').replace(/\n$/, '');
139138

140139
const item = { level, data, obj: logobj};
141140

@@ -158,18 +157,19 @@ logger.log = (level, data, logobj) => {
158157

159158
logger.log_respond = (retval, msg, data) => {
160159
// any other return code is irrelevant
161-
if (retval !== constants.cont) { return false; }
160+
if (retval !== constants.cont) return false;
161+
162162
let timestamp_string = '';
163-
if (logger.timestamps) {
164-
timestamp_string = `${new Date().toISOString()} `;
165-
}
163+
if (logger.timestamps) timestamp_string = `${new Date().toISOString()} `;
164+
166165
const color = logger.colors[data.level];
167166
if (color && stdout_is_tty) {
168167
process.stdout.write(`${timestamp_string}${logger.colorize(color,data.data)}\n`);
169-
return true;
168+
}
169+
else {
170+
process.stdout.write(`${timestamp_string}${data.data}\n`);
170171
}
171172

172-
process.stdout.write(`${timestamp_string}${data.data}\n`);
173173
return true;
174174
}
175175

@@ -215,7 +215,7 @@ logger._init_loglevel = function () {
215215
}
216216

217217
logger.would_log = level => {
218-
if (logger.loglevel < level) { return false; }
218+
if (logger.loglevel < level) return false;
219219
return true;
220220
}
221221

@@ -229,8 +229,7 @@ logger._init_timestamps = function () {
229229
this._init_timestamps();
230230
});
231231

232-
// If we've already been toggled to true by the cfg, we should respect
233-
// this.
232+
// If we've already been toggled to true by the cfg, we should respect this.
234233
this.set_timestamps(logger.timestamps || _timestamps);
235234
}
236235

@@ -254,9 +253,7 @@ logger.log_if_level = (level, key, plugin) => function () {
254253
// if the object is a connection, add the connection id
255254
if (data instanceof connection.Connection) {
256255
logobj.uuid = data.uuid;
257-
if (data.tran_count > 0) {
258-
logobj.uuid += `.${data.tran_count}`;
259-
}
256+
if (data.tran_count > 0) logobj.uuid += `.${data.tran_count}`;
260257
}
261258
else if (data instanceof plugins.Plugin) {
262259
logobj.origin = data.name;
@@ -267,10 +264,8 @@ logger.log_if_level = (level, key, plugin) => function () {
267264
else if (data instanceof outbound.HMailItem) {
268265
logobj.origin = 'outbound';
269266
if (data.todo) {
270-
if (data.todo.uuid)
271-
logobj.uuid = data.todo.uuid;
272-
if (data.todo.client_uuid) {
273-
// dirty hack
267+
if (data.todo.uuid) logobj.uuid = data.todo.uuid;
268+
if (data.todo.client_uuid) { // dirty hack
274269
logobj.origin = `outbound] [${data.todo.client_uuid}`;
275270
}
276271
}
@@ -294,32 +289,34 @@ logger.log_if_level = (level, key, plugin) => function () {
294289
logobj.message += (util.inspect(data));
295290
}
296291
}
292+
297293
switch (logger.format) {
298294
case logger.formats.LOGFMT:
299295
logger.log(
300296
level,
301297
stringify(logobj)
302298
);
303-
return true;
299+
break
304300
case logger.formats.JSON:
305301
logger.log(
306302
level,
307303
JSON.stringify(logobj)
308304
);
309-
return true;
305+
break
310306
case logger.formats.DEFAULT:
311307
default:
312308
logger.log(
313309
level,
314310
`[${logobj.level}] [${logobj.uuid}] [${logobj.origin}] ${logobj.message}`
315311
);
316-
return true;
317312
}
313+
return true;
318314
}
319315

320316
logger.add_log_methods = (object, plugin) => {
321317
if (!object) return;
322318
if (typeof(object) !== 'object') return;
319+
323320
for (const level in logger.levels) {
324321
const fname = `log${level.toLowerCase()}`;
325322
if (object[fname]) continue; // already added

plugins/auth/auth_proxy.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Proxy AUTH requests selectively by domain
2+
23
const sock = require('./line_socket');
34
const utils = require('haraka-utils');
4-
const smtp_regexp = /^([0-9]{3})([ -])(.*)/;
5+
6+
const smtp_regexp = /^(\d{3})([ -])(.*)/;
57

68
exports.register = function () {
79
this.inherits('auth/auth_base');
@@ -25,8 +27,8 @@ exports.hook_capabilities = (next, connection) => {
2527
}
2628

2729
exports.check_plain_passwd = function (connection, user, passwd, cb) {
28-
let domain;
29-
if ((domain = /@([^@]+)$/.exec(user))) {
30+
let domain = /@([^@]+)$/.exec(user);
31+
if (domain) {
3032
domain = domain[1].toLowerCase();
3133
}
3234
else {
@@ -82,7 +84,6 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
8284
socket.on('error', err => {
8385
connection.logerror(self, `connection failed to host ${host}: ${err}`);
8486
socket.end();
85-
return;
8687
});
8788
socket.send_command = function (cmd, data) {
8889
let line = cmd + (data ? (` ${data}`) : '');
@@ -175,8 +176,8 @@ exports.try_auth_proxy = function (connection, hosts, user, passwd, cb) {
175176
}
176177
if (code.startsWith('5')) {
177178
// Initial attempt failed; strip domain and retry.
178-
let u;
179-
if ((u = /^([^@]+)@.+$/.exec(user))) {
179+
const u = /^([^@]+)@.+$/.exec(user)
180+
if (u) {
180181
user = u[1];
181182
if (methods.includes('PLAIN')) {
182183
socket.send_command('AUTH', `PLAIN ${utils.base64(`\0${user}\0${passwd}`)}`);

plugins/avg.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const fs = require('fs');
77
const path = require('path');
88

99
const sock = require('./line_socket');
10-
const smtp_regexp = /^([0-9]{3})([ -])(.*)/;
10+
11+
const smtp_regexp = /^(\d{3})([ -])(.*)/;
1112

1213
exports.register = function () {
1314

plugins/clamd.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,19 @@ exports.send_clamd_predata = (socket, cb) => {
363363
}
364364

365365
function clamd_connect (socket, host) {
366-
let match;
366+
367367
if (host.match(/^\//)) {
368-
// assume unix socket
369-
socket.connect(host);
370-
}
371-
else if ((match = /^\[([^\] ]+)\](?::(\d+))?/.exec(host))) {
372-
// IPv6 literal
373-
socket.connect((match[2] || 3310), match[1]);
368+
socket.connect(host); // starts with /, unix socket
369+
return
374370
}
375-
else {
376-
// IP:port, hostname:port or hostname
377-
const hostport = host.split(/:/);
378-
socket.connect((hostport[1] || 3310), hostport[0]);
371+
372+
const match = /^\[([^\] ]+)\](?::(\d+))?/.exec(host);
373+
if (match) {
374+
socket.connect((match[2] || 3310), match[1]); // IPv6 literal
375+
return
379376
}
377+
378+
// IP:port, hostname:port or hostname
379+
const hostport = host.split(/:/);
380+
socket.connect((hostport[1] || 3310), hostport[0]);
380381
}

plugins/delay_deny.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ exports.hook_deny = function (next, connection, params) {
9393
// fall through
9494
default:
9595
// No delays
96-
return next();
96+
next();
9797
}
9898
}
9999

@@ -128,7 +128,7 @@ exports.hook_rcpt_ok = function (next, connection, rcpt) {
128128
return next(params[0], params[1]);
129129
}
130130
}
131-
return next();
131+
next();
132132
}
133133

134134
exports.hook_data = (next, connection) => {
@@ -145,5 +145,5 @@ exports.hook_data = (next, connection) => {
145145
}
146146
if (fails.length) transaction.add_header('X-Haraka-Fail-Pre', fails.join(' '));
147147

148-
return next();
148+
next();
149149
}

plugins/esets.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ const virus_re = new RegExp('virus="([^"]+)"');
55

66
exports.hook_data_post = function (next, connection) {
77
const plugin = this;
8-
const txn = connection.transaction;
98
const cfg = this.config.get('esets.ini');
109

1110
// Write message to temporary file
1211
const tmpdir = cfg.main.tmpdir || '/tmp';
13-
const tmpfile = `${tmpdir}/${txn.uuid}.esets`;
12+
const tmpfile = `${tmpdir}/${connection?.transaction?.uuid}.esets`;
1413
const ws = fs.createWriteStream(tmpfile);
1514

1615
ws.once('error', err => {
1716
connection.logerror(plugin, `Error writing temporary file: ${err.message}`);
18-
return next();
17+
next();
1918
});
2019

2120
let start_time;
@@ -39,10 +38,8 @@ exports.hook_data_post = function (next, connection) {
3938
});
4039

4140
// Get virus name
42-
let virus;
43-
if ((virus = virus_re.exec(stdout))) {
44-
virus = virus[1];
45-
}
41+
let virus = virus_re.exec(stdout)
42+
if (virus) virus = virus[1];
4643

4744
// Log a summary
4845
const exit_code = parseInt((error) ? error.code : 0)
@@ -60,7 +57,7 @@ exports.hook_data_post = function (next, connection) {
6057
return next(DENYSOFT, 'Virus scanner error');
6158
}
6259
}
63-
return next();
60+
next();
6461
}
6562

6663
ws.once('close', () => {
@@ -70,5 +67,5 @@ exports.hook_data_post = function (next, connection) {
7067
wsOnClose);
7168
});
7269

73-
txn.message_stream.pipe(ws, { line_endings: '\r\n' });
70+
connection.transaction.message_stream.pipe(ws, { line_endings: '\r\n' });
7471
}

plugins/greylist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ exports.process_skip_rules = function (connection) {
342342
}
343343
}
344344

345-
return false;
345+
return '';
346346
}
347347

348348
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

plugins/messagesniffer.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ exports.hook_connect = function (next, connection) {
8989
default:
9090
// Unknown
9191
connection.logerror(this, `Unknown GBUdb range: ${gbudb.range}`);
92-
return next();
92+
next();
9393
}
9494
}
9595
else {
96-
return next();
96+
next();
9797
}
9898
});
9999
}
@@ -136,7 +136,7 @@ exports.hook_data_post = function (next, connection) {
136136

137137
ws.once('error', err => {
138138
connection.logerror(this, `Error writing temporary file: ${err.message}`);
139-
return next();
139+
next();
140140
});
141141

142142
ws.once('close', () => {
@@ -338,11 +338,11 @@ exports.hook_disconnect = function (next, connection) {
338338
else {
339339
connection.logdebug(this, `GBUdb bad encounter added for ${connection.remote.ip}`);
340340
}
341-
return next();
341+
next();
342342
});
343343
}
344344
else {
345-
return next();
345+
next();
346346
}
347347
}
348348

@@ -352,7 +352,7 @@ function SNFClient (req, cb) {
352352
sock.setTimeout(30 * 1000); // Connection timeout
353353
sock.once('timeout', function () {
354354
this.destroy();
355-
return cb(new Error('connection timed out'));
355+
cb(new Error('connection timed out'));
356356
});
357357
sock.once('error', err => cb(err));
358358
sock.once('connect', function () {
@@ -367,16 +367,14 @@ function SNFClient (req, cb) {
367367
});
368368
sock.once('end', () => {
369369
// Check for result
370+
if (/<result /.exec(result)) return cb(null, result);
371+
370372
let match;
371-
if (/<result /.exec(result)) {
372-
return cb(null, result);
373-
}
374-
else if ((match = /<error message='([^']+)'/.exec(result))) {
373+
if ((match = /<error message='([^']+)'/.exec(result))) {
375374
return cb(new Error(match[1]));
376375
}
377-
else {
378-
return cb(new Error(`unexpected result: ${result}`));
379-
}
376+
377+
cb(new Error(`unexpected result: ${result}`));
380378
});
381379
// Start the sequence
382380
sock.connect(port);

plugins/prevent_credential_leaks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ exports.hook_data_post = (next, connection) => {
2121

2222
let user = connection.notes.auth_user;
2323
let domain;
24-
let idx;
25-
if ((idx = user.indexOf('@'))) {
24+
const idx = user.indexOf('@')
25+
if (idx) {
2626
// If the username is qualified (e.g. user@domain.com)
2727
// then we make the @domain.com part optional in the regexp.
2828
domain = user.substr(idx);

0 commit comments

Comments
 (0)