From cfec82e3d81da994cb9af56924ceb748d293a9a4 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Thu, 30 Jan 2020 08:44:23 -0500 Subject: [PATCH 1/3] add no-console eslint rule for tests directory --- test/.eslintrc.js | 1 + test/mock-server/index.js | 1 + test/spec/modules/onetagBidAdapter_spec.js | 4 ++-- test/spec/modules/ozoneBidAdapter_spec.js | 1 - test/spec/modules/tribeosBidAdapter_spec.js | 2 -- test/spec/unit/pbjs_api_spec.js | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/.eslintrc.js b/test/.eslintrc.js index 4cd5a854ac4..f1df166774e 100644 --- a/test/.eslintrc.js +++ b/test/.eslintrc.js @@ -36,5 +36,6 @@ module.exports = { "no-use-before-define": "off", "no-useless-escape": "off", "one-var": "off", + "no-console": "error" } }; diff --git a/test/mock-server/index.js b/test/mock-server/index.js index 30ead952fcc..9a97ca5e0a0 100644 --- a/test/mock-server/index.js +++ b/test/mock-server/index.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const express = require('express'); const argv = require('yargs').argv; const app = module.exports = express(); diff --git a/test/spec/modules/onetagBidAdapter_spec.js b/test/spec/modules/onetagBidAdapter_spec.js index 93284566069..330e50e6928 100644 --- a/test/spec/modules/onetagBidAdapter_spec.js +++ b/test/spec/modules/onetagBidAdapter_spec.js @@ -81,7 +81,7 @@ describe('onetag', function () { } }); } catch (e) { - console.log('Error while parsing'); + console.log('onetagBidAdapter tests: Error while parsing'); // eslint-disable-line } it('Returns empty data if no valid requests are passed', function () { serverRequest = spec.buildRequests([]); @@ -90,7 +90,7 @@ describe('onetag', function () { let dataObj = JSON.parse(dataString); expect(dataObj.bids).to.be.an('array').that.is.empty; } catch (e) { - console.log('Error while parsing'); + console.log('onetagBidAdapter tests: Error while parsing'); // eslint-disable-line } }); it('should send GDPR consent data', function () { diff --git a/test/spec/modules/ozoneBidAdapter_spec.js b/test/spec/modules/ozoneBidAdapter_spec.js index 7d7d658351f..6508d9287cd 100644 --- a/test/spec/modules/ozoneBidAdapter_spec.js +++ b/test/spec/modules/ozoneBidAdapter_spec.js @@ -1002,7 +1002,6 @@ describe('ozone Adapter', function () { }); it('should pick up the value of pubcid when built using the pubCommonId module (not userId)', function () { - console.log(validBidRequests[0].crumbs); let bidRequests = validBidRequests; // values from http://prebid.org/dev-docs/modules/userId.html#pubcommon-id bidRequests[0]['userId'] = { diff --git a/test/spec/modules/tribeosBidAdapter_spec.js b/test/spec/modules/tribeosBidAdapter_spec.js index b0e5b5dd487..c8e0ab77d53 100644 --- a/test/spec/modules/tribeosBidAdapter_spec.js +++ b/test/spec/modules/tribeosBidAdapter_spec.js @@ -75,8 +75,6 @@ describe('tribeosBidAdapter', function() { expect(bids).to.have.lengthOf(1); let bid = bids[0]; - console.error(JSON.stringify(bid)); - expect(bid.cpm).to.equal(1.1); expect(bid.currency).to.equal('USD'); expect(bid.width).to.equal(300); diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 6d98830ac42..3984254b4f6 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -1404,7 +1404,7 @@ describe('Unit: Prebid Module', function () { try { $$PREBID_GLOBAL$$.requestBids({}); } catch (e) { - console.log(e); + console.log(e); // eslint-disable-line } assert.ok(logMessageSpy.calledWith('No adUnits configured. No bids requested.'), 'expected message was logged'); }); From 81fa2914af1a0133996c76b7172657e9c4134130 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 11 Feb 2020 08:12:36 -0500 Subject: [PATCH 2/3] remove console logs from onetag tests --- test/spec/modules/onetagBidAdapter_spec.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/spec/modules/onetagBidAdapter_spec.js b/test/spec/modules/onetagBidAdapter_spec.js index 330e50e6928..ee0f385dd9d 100644 --- a/test/spec/modules/onetagBidAdapter_spec.js +++ b/test/spec/modules/onetagBidAdapter_spec.js @@ -80,18 +80,14 @@ describe('onetag', function () { expect(bid.pubId).to.be.a('string'); } }); - } catch (e) { - console.log('onetagBidAdapter tests: Error while parsing'); // eslint-disable-line - } + } catch (e) {} it('Returns empty data if no valid requests are passed', function () { serverRequest = spec.buildRequests([]); let dataString = serverRequest.data; try { let dataObj = JSON.parse(dataString); expect(dataObj.bids).to.be.an('array').that.is.empty; - } catch (e) { - console.log('onetagBidAdapter tests: Error while parsing'); // eslint-disable-line - } + } catch (e) {} }); it('should send GDPR consent data', function () { let consentString = 'consentString'; From d7e405e2c4df2e0a0546f28ee242357e3a961cd2 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Thu, 20 Feb 2020 11:32:48 -0500 Subject: [PATCH 3/3] update scope of rule to include src files --- .eslintrc.js | 1 + modules/adxpremiumAnalyticsAdapter.js | 8 ++++---- modules/nobidBidAdapter.js | 2 +- modules/sharethroughBidAdapter.js | 5 +++-- modules/sovrnBidAdapter.js | 6 ++---- src/adapters/analytics/example2.js | 1 + src/adapters/analytics/libraries/example.js | 1 + src/adapters/analytics/libraries/example2.js | 1 + src/utils.js | 1 + test/.eslintrc.js | 3 +-- 10 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 74948bb8bad..c64ab379c52 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -39,6 +39,7 @@ module.exports = { "no-throw-literal": "off", "no-undef": 2, "no-useless-escape": "off", + "no-console": "error" }, "overrides": Object.keys(allowedModules).map((key) => ({ "files": key + "/**/*.js", diff --git a/modules/adxpremiumAnalyticsAdapter.js b/modules/adxpremiumAnalyticsAdapter.js index 201aab1db03..47b401e2bb4 100644 --- a/modules/adxpremiumAnalyticsAdapter.js +++ b/modules/adxpremiumAnalyticsAdapter.js @@ -62,7 +62,7 @@ let googletag = window.googletag || {}; googletag.cmd = googletag.cmd || []; googletag.cmd.push(function() { googletag.pubads().addEventListener('slotRenderEnded', args => { - console.log(Date.now() + ' GOOGLE SLOT: ' + JSON.stringify(args)); + utils.logInfo(Date.now() + ' GOOGLE SLOT: ' + JSON.stringify(args)); }); }); @@ -72,7 +72,7 @@ let bidResponsesMapper = {}; function auctionInit(args) { completeObject.auction_id = args.auctionId; completeObject.publisher_id = adxpremiumAnalyticsAdapter.initOptions.pubId; - try { completeObject.referer = args.bidderRequests[0].refererInfo.referer.split('?')[0]; } catch (e) { console.log(e.message); } + try { completeObject.referer = args.bidderRequests[0].refererInfo.referer.split('?')[0]; } catch (e) { utils.logWarn('Could not parse referer, error details:', e.message); } completeObject.device_type = deviceType(); } function bidRequested(args) { @@ -130,11 +130,11 @@ function sendEvent(completeObject) { let responseEvents = btoa(JSON.stringify(completeObject)); let mutation = `mutation {createEvent(input: {event: {eventData: "${responseEvents}"}}) {event {createTime } } }`; let dataToSend = JSON.stringify({ query: mutation }); - ajax(url, function () { console.log(Date.now() + ' Sending event to adxpremium server.') }, dataToSend, { + ajax(url, function () { utils.logInfo(Date.now() + ' Sending event to adxpremium server.') }, dataToSend, { contentType: 'application/json', method: 'POST' }); - } catch (err) { console.log(err) } + } catch (err) { utils.logError('Could not send event, error details:', err) } } // save the base class function diff --git a/modules/nobidBidAdapter.js b/modules/nobidBidAdapter.js index cce79efead0..4b8dcc75928 100644 --- a/modules/nobidBidAdapter.js +++ b/modules/nobidBidAdapter.js @@ -83,7 +83,7 @@ function nobidBuildRequests(bids, bidderRequest) { var height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); return `${width}x${height}`; } catch (e) { - console.error(e); + utils.logWarn('Could not parse screen dimensions, error details:', e); } } var state = {}; diff --git a/modules/sharethroughBidAdapter.js b/modules/sharethroughBidAdapter.js index 4c73cb2c28f..e1ff79aa89b 100644 --- a/modules/sharethroughBidAdapter.js +++ b/modules/sharethroughBidAdapter.js @@ -1,4 +1,5 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; const VERSION = '3.2.0'; const BIDDER_CODE = 'sharethrough'; @@ -181,7 +182,7 @@ function handleIframe () { window.document.getElementsByTagName('body')[0].appendChild(sfpIframeBusterJs); iframeBusterLoaded = true; } catch (e) { - console.error(e); + utils.logError('Trouble writing frame buster script, error details:', e); } } @@ -199,7 +200,7 @@ function handleIframe () { window.document.getElementsByTagName('body')[0].appendChild(sfpJs); } } catch (e) { - console.error(e); + utils.logError('Trouble writing sfp script, error details:', e); } } } diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index ee3eba90f04..2566f314018 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -107,8 +107,7 @@ export const spec = { options: {contentType: 'text/plain'} } } catch (e) { - console.log('error in build:') - console.log(e) + utils.logError('Could not build bidrequest, error deatils:', e); } }, @@ -143,8 +142,7 @@ export const spec = { } return sovrnBidResponses } catch (e) { - console.log('error in interpret:') - console.log(e) + utils.logError('Could not intrepret bidresponse, error deatils:', e); } }, diff --git a/src/adapters/analytics/example2.js b/src/adapters/analytics/example2.js index 55d34697b8c..eadf994ce36 100644 --- a/src/adapters/analytics/example2.js +++ b/src/adapters/analytics/example2.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { ajax } from '../../../src/ajax.js'; /** diff --git a/src/adapters/analytics/libraries/example.js b/src/adapters/analytics/libraries/example.js index 55ef2b8ca45..0d758fd5513 100644 --- a/src/adapters/analytics/libraries/example.js +++ b/src/adapters/analytics/libraries/example.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /** @module example */ window.ExampleAnalyticsGlobalObject = function(hander, type, data) { diff --git a/src/adapters/analytics/libraries/example2.js b/src/adapters/analytics/libraries/example2.js index 913f21177d0..68e814b1417 100644 --- a/src/adapters/analytics/libraries/example2.js +++ b/src/adapters/analytics/libraries/example2.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /** @module example */ window.ExampleAnalyticsGlobalObject2 = function(hander, type, data) { diff --git a/src/utils.js b/src/utils.js index b4b37d400bf..737234da69c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { config } from './config.js'; import clone from 'just-clone'; import find from 'core-js/library/fn/array/find.js'; diff --git a/test/.eslintrc.js b/test/.eslintrc.js index f1df166774e..842bccd99b1 100644 --- a/test/.eslintrc.js +++ b/test/.eslintrc.js @@ -35,7 +35,6 @@ module.exports = { "no-unused-vars": "off", "no-use-before-define": "off", "no-useless-escape": "off", - "one-var": "off", - "no-console": "error" + "one-var": "off" } };