Skip to content

Commit

Permalink
Set eslint no-console to error and change console logs to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa committed Oct 26, 2023
1 parent ff518cb commit 8b4cff4
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
'keyword-spacing': ['warn'],
'linebreak-style': ['warn', 'unix'],
'no-async-promise-executor': ['warn'],
'no-console': ['warn', { 'allow': ['warn', 'error'] }],
'no-console': ['error', { 'allow': ['warn', 'error'] }],
'no-empty': ['warn'],
'no-ex-assign': ['warn'],
'no-extra-semi': ['warn'],
Expand Down
2 changes: 1 addition & 1 deletion lib/agent/https_proxy_ocsp_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function HttpsProxyOcspAgent(opts)

if (!HttpsAgent.secureProxy)
{
console.warn("Warning: connecting to an authenticated proxy server through HTTP. To use HTTPS, set 'proxyProtocol' to 'HTTPS'")
Logger.getInstance().warn("Warning: connecting to an authenticated proxy server through HTTP. To use HTTPS, set 'proxyProtocol' to 'HTTPS'")
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/connection/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const DEFAULT_PARAMS =
'includeRetryReason',
'disableQueryContextCache',
];
const Logger = require('../logger');

function consolidateHostAndAccount(options)
{
Expand Down Expand Up @@ -490,7 +491,7 @@ function ConnectionConfig(options, validateCredentials, qaMode, clientInfo)
if (!DEFAULT_PARAMS.includes(key))
{
const result = levenshtein.closest(key, DEFAULT_PARAMS);
console.error(`"${key}" is an unknown connection parameter. Did you mean "${result}"?`);
Logger.getInstance().error(`"${key}" is an unknown connection parameter. Did you mean "${result}"?`);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function Core(options)
{
if (err)
{
console.error('Unable to connect: ' + err.message);
Logger.getInstance().error('Unable to connect: ' + err.message);
reject(new Error(err.message));
}
else
Expand All @@ -299,7 +299,7 @@ function Core(options)
{
if (err)
{
console.error('Unable to disconnect: ' + err.message);
Logger.getInstance().error('Unable to disconnect: ' + err.message);
}
resolve();
});
Expand Down
3 changes: 2 additions & 1 deletion test/integration/testManualConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const async = require("async");
const assert = require("assert");
const connOption = require("./connectionOptions");
const testUtil = require("./testUtil");
const Logger = require('../../lib/logger');

if (process.env.RUN_MANUAL_TESTS_ONLY == "true") {
describe.only("Run manual tests", function () {
Expand Down Expand Up @@ -321,7 +322,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") {
let time = await executeSingleQuery();
sumWithoutKeepAlive += time;
}
console.log(`Sum of time without keep alive: ${sumWithoutKeepAlive}. Sum of time with keep alive:: ${sumWithKeepAlive}`);
Logger.getInstance().info(`Sum of time without keep alive: ${sumWithoutKeepAlive}. Sum of time with keep alive:: ${sumWithKeepAlive}`);
assert.ok(sumWithoutKeepAlive * 0.66 > sumWithKeepAlive, 'With keep alive the queries should work faster');
});
});
Expand Down
14 changes: 7 additions & 7 deletions test/integration/testMultiStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var async = require('async');
var assert = require('assert');
var testUtil = require('./testUtil');
var Util = require('./../../lib/util');

const Logger = require('../../lib/logger');

describe('Test multi statement', function ()
{
Expand Down Expand Up @@ -41,9 +41,9 @@ describe('Test multi statement', function ()
connection.execute({
sqlText: 'select current_version()',
complete: function (err, stmt, rows) {
console.log('=== driver version = ' + Util.driverVersion);
console.log('=== server version =');
console.log(rows);
Logger.getInstance().info('=== driver version = ' + Util.driverVersion);
Logger.getInstance().info('=== server version =');
Logger.getInstance().info(rows);
callback();
}
});
Expand All @@ -61,14 +61,14 @@ describe('Test multi statement', function ()
testUtil.checkError(err);
});
stream.on('data', function (row) {
console.log(row);
Logger.getInstance().info(row);
count += Object.values(row).length;
if (stmt.hasNext()) {
console.log('==== hasNext');
Logger.getInstance().info('==== hasNext');
stmt.NextResult();
}
else {
console.log('==== close connection');
Logger.getInstance().info('==== close connection');
assert.strictEqual(6, count);
done();
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/testOcsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('OCSP validation', function ()
{
if (!err.hasOwnProperty('code'))
{
console.log(err);
Logger.getInstance().error(err);
}
assert.equal(err['code'], '390100');
}
Expand Down
9 changes: 5 additions & 4 deletions test/integration/testUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const connOptions = require('./connectionOptions');
const assert = require('assert');
const fs = require('fs');
const crypto = require('crypto');
const Logger = require('../../lib/logger');

module.exports.createConnection = function (validConnectionOptionsOverride = {}) {
return snowflake.createConnection({
Expand Down Expand Up @@ -97,7 +98,7 @@ module.exports.dropTablesIgnoringErrorsAsync = async (connection, tableNames) =>
try {
await executeCmdAsync(connection, `DROP TABLE IF EXISTS ${tableName}`);
} catch (e) {
console.warn(`Cannot drop table ${tableName}: ${JSON.stringify(e)}`);
Logger.getInstance().warn(`Cannot drop table ${tableName}: ${JSON.stringify(e)}`);
}
}
};
Expand All @@ -113,7 +114,7 @@ module.exports.dropDBsIgnoringErrorsAsync = async (connection, dbNames) => {
try {
await executeCmdAsync(connection, `DROP DATABASE IF EXISTS ${dbName}`);
} catch (e) {
console.warn(`Cannot drop database ${dbName}: ${JSON.stringify(e)}`);
Logger.getInstance().warn(`Cannot drop database ${dbName}: ${JSON.stringify(e)}`);
}
}
};
Expand Down Expand Up @@ -226,7 +227,7 @@ module.exports.deleteFileSyncIgnoringErrors = function (file) {
fs.closeSync(file.fd);
fs.unlinkSync(file.name);
} catch (e) {
console.warn(`Cannot remove file ${file.name}: ${JSON.stringify(e)}`);
Logger.getInstance().warn(`Cannot remove file ${file.name}: ${JSON.stringify(e)}`);
}
}
};
Expand All @@ -242,7 +243,7 @@ module.exports.deleteFolderSyncIgnoringErrors = function (directory) {
fs.rmdirSync(directory, { recursive: true });
}
} catch (e) {
console.warn(`Cannot delete folder ${directory}: ${JSON.stringify(e)}`);
Logger.getInstance().warn(`Cannot delete folder ${directory}: ${JSON.stringify(e)}`);
}
};

Expand Down

0 comments on commit 8b4cff4

Please sign in to comment.