diff --git a/.eslintrc.js b/.eslintrc.js index 0030bf492..abc089fe6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,9 +12,15 @@ module.exports = { 'ecmaVersion': 'latest' }, 'rules': { + 'array-bracket-spacing': ['warn'], + 'arrow-spacing': ['warn'], + 'block-spacing': ['warn'], 'brace-style': ['warn', '1tbs'], + 'comma-spacing': ['warn'], 'curly': ['warn', 'all'], 'indent': ['warn', 2], + 'key-spacing': ['warn'], + 'keyword-spacing': ['warn'], 'linebreak-style': ['warn', 'unix'], 'no-async-promise-executor': ['warn'], 'no-console': ['warn', { 'allow': ['warn', 'error'] }], @@ -31,8 +37,16 @@ module.exports = { 'no-useless-catch': ['warn'], 'no-useless-escape': ['warn'], 'no-var': ['warn'], + 'object-curly-spacing': ['warn', 'always'], 'prefer-const': ['warn'], 'quotes': ['warn', 'single'], - 'semi': ['warn', 'always'] + 'semi': ['warn', 'always'], + 'semi-spacing': ['warn'], + 'space-before-function-paren': ['warn', { + 'anonymous': 'always', + 'named': 'never', + 'asyncArrow': 'always', + }], + 'space-infix-ops': ['warn'], } }; diff --git a/lib/queryContextCache.js b/lib/queryContextCache.js index 430e3a0e6..ef3d1ba44 100644 --- a/lib/queryContextCache.js +++ b/lib/queryContextCache.js @@ -11,7 +11,7 @@ const Logger = require('./logger'); * @param {Number} priority * @param {String} context */ -function QueryContextElement (id,timestamp,priority,context) { +function QueryContextElement(id, timestamp, priority, context) { this.id = id; this.timestamp = timestamp; this.priority = priority; @@ -25,7 +25,7 @@ function QueryContextElement (id,timestamp,priority,context) { /** * @param {Number} capacity Maximum capacity of the cache. */ -function QueryContextCache (capacity) { +function QueryContextCache(capacity) { this.capacity = capacity; this.idMap = new Map(); // Map for id and QCC this.treeSet = new Set(); // Order data as per priority @@ -33,12 +33,12 @@ function QueryContextCache (capacity) { } QueryContextCache.prototype.sortTreeSet = function () { - this.treeSet = new Set(Array.from(this.treeSet).sort((a,b)=>a.priority-b.priority)); + this.treeSet = new Set(Array.from(this.treeSet).sort((a, b) => a.priority - b.priority)); }; -QueryContextCache.prototype.addQCE= function (qce) { - this.idMap.set(qce.id,qce); - this.priorityMap.set(qce.priority,qce); +QueryContextCache.prototype.addQCE = function (qce) { + this.idMap.set(qce.id, qce); + this.priorityMap.set(qce.priority, qce); this.treeSet.add(qce); this.sortTreeSet(); }; @@ -114,7 +114,7 @@ QueryContextCache.prototype.merge = function (newQCE) { // new priority // Add new element in the cache - this.addQCE(newQCE,newQCE); + this.addQCE(newQCE, newQCE); } } }; @@ -156,7 +156,7 @@ QueryContextCache.prototype.getElements = function () { QueryContextCache.prototype.deserializeQueryContext = function (data) { const stringifyData = JSON.stringify(data); Logger.getInstance().debug(`deserializeQueryContext() called: data from server: ${stringifyData}`); - if (!data || stringifyData ==='{}' || data.entries === null) { + if (!data || stringifyData === '{}' || data.entries === null) { this.clearCache(); Logger.getInstance().debug('deserializeQueryContext() returns'); @@ -214,10 +214,10 @@ QueryContextCache.prototype.deserializeQueryContext = function (data) { }; QueryContextCache.prototype.deserializeQueryContextElement = function (node) { - const {id, timestamp, priority, context} = node; + const { id, timestamp, priority, context } = node; const entry = new QueryContextElement (id, timestamp, priority, null); - if(typeof context === 'string'){ + if (typeof context === 'string'){ entry.context = context; } else if (context === null || context === undefined) { entry.context = null; @@ -232,23 +232,23 @@ QueryContextCache.prototype.deserializeQueryContextElement = function (node) { QueryContextCache.prototype.logCacheEntries = function () { - this.treeSet.forEach(function(elem) { + this.treeSet.forEach(function (elem) { Logger.getInstance().debug( `Cache Entry: id: ${elem.id} timestamp: ${elem.timestamp} priority: ${elem.priority}`, ); }); }; -QueryContextCache.prototype.getSize = function() { +QueryContextCache.prototype.getSize = function () { return this.treeSet.size; }; QueryContextCache.prototype.getQueryContextDTO = function () { const arr = []; - const querycontexts =Array.from(this.getElements()); + const querycontexts = Array.from(this.getElements()); for (let i = 0; i < this.treeSet.size; i++) { - arr.push({id:querycontexts[i].id, timestamp:querycontexts[i].timestamp, - priority:querycontexts[i].priority, context:{base64Data:querycontexts[i].context}||null}); + arr.push({ id: querycontexts[i].id, timestamp: querycontexts[i].timestamp, + priority: querycontexts[i].priority, context: { base64Data: querycontexts[i].context } || null }); } return { entries: arr @@ -257,9 +257,9 @@ QueryContextCache.prototype.getQueryContextDTO = function () { QueryContextCache.prototype.getSerializeQueryContext = function () { const arr = []; - const querycontexts =Array.from(this.getElements()); + const querycontexts = Array.from(this.getElements()); for (let i = 0; i < this.treeSet.size; i++) { - arr.push({id:querycontexts[i].id,timestamp:querycontexts[i].timestamp,priority:querycontexts[i].priority,context:querycontexts[i].context||null}); + arr.push({ id: querycontexts[i].id, timestamp: querycontexts[i].timestamp, priority: querycontexts[i].priority, context: querycontexts[i].context || null }); } return { diff --git a/test/integration/testHTAP.js b/test/integration/testHTAP.js index 9a1f593c2..fb412747a 100644 --- a/test/integration/testHTAP.js +++ b/test/integration/testHTAP.js @@ -23,61 +23,61 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { const querySet = [ { - sqlTexts:[ + sqlTexts: [ 'create or replace database db1', 'create or replace hybrid table t1 (a int primary key, b int)', 'insert into t1 values (1, 2), (2, 3), (3, 4)' ], - QccSize:2, + QccSize: 2, }, { - sqlTexts:[ + sqlTexts: [ 'create or replace database db2', 'create or replace hybrid table t2 (a int primary key, b int)', 'insert into t2 values (1, 2), (2, 3), (3, 4)' ], - QccSize:3, + QccSize: 3, }, { - sqlTexts:[ + sqlTexts: [ 'create or replace database db3', 'create or replace hybrid table t3 (a int primary key, b int)', 'insert into t3 values (1, 2), (2, 3), (3, 4)' ], - QccSize:4, + QccSize: 4, }, { - sqlTexts:[ + sqlTexts: [ 'select * from db1.public.t1 x, db2.public.t2 y, db3.public.t3 z where x.a = y.a and y.a = z.a;', 'select * from db1.public.t1 x, db2.public.t2 y where x.a = y.a;', 'select * from db2.public.t2 y, db3.public.t3 z where y.a = z.a;' ], - QccSize:4, + QccSize: 4, }, ]; - function createQueryTest () { + function createQueryTest() { const testingSet = []; let testingfunction; - for(let i = 0; i < querySet.length; i++) { - const {sqlTexts,QccSize} = querySet[i]; - for(let k = 0; k < sqlTexts.length; k++){ - if(k!==sqlTexts.length-1){ - testingfunction = function(callback) { + for (let i = 0; i < querySet.length; i++) { + const { sqlTexts, QccSize } = querySet[i]; + for (let k = 0; k < sqlTexts.length; k++){ + if (k !== sqlTexts.length - 1){ + testingfunction = function (callback) { connection.execute({ sqlText: sqlTexts[k], complete: function (err) { - assert.ok(!err,'There should be no error!'); + assert.ok(!err, 'There should be no error!'); callback(); } }); }; - } else{ - testingfunction = function(callback) { + } else { + testingfunction = function (callback) { connection.execute({ sqlText: sqlTexts[k], complete: function (err, stmt) { - assert.ok(!err,'There should be no error!'); + assert.ok(!err, 'There should be no error!'); assert.strictEqual(stmt.getQueryContextCacheSize(), QccSize); assert.strictEqual(stmt.getQueryContextDTOSize(), QccSize); callback();