Skip to content

Commit 60f66c9

Browse files
authored
enable no-console eslint rule for project (#4802)
* add no-console eslint rule for tests directory * remove console logs from onetag tests * update scope of rule to include src files
1 parent a088d66 commit 60f66c9

14 files changed

+20
-21
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = {
3939
"no-throw-literal": "off",
4040
"no-undef": 2,
4141
"no-useless-escape": "off",
42+
"no-console": "error"
4243
},
4344
"overrides": Object.keys(allowedModules).map((key) => ({
4445
"files": key + "/**/*.js",

modules/adxpremiumAnalyticsAdapter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let googletag = window.googletag || {};
6262
googletag.cmd = googletag.cmd || [];
6363
googletag.cmd.push(function() {
6464
googletag.pubads().addEventListener('slotRenderEnded', args => {
65-
console.log(Date.now() + ' GOOGLE SLOT: ' + JSON.stringify(args));
65+
utils.logInfo(Date.now() + ' GOOGLE SLOT: ' + JSON.stringify(args));
6666
});
6767
});
6868

@@ -72,7 +72,7 @@ let bidResponsesMapper = {};
7272
function auctionInit(args) {
7373
completeObject.auction_id = args.auctionId;
7474
completeObject.publisher_id = adxpremiumAnalyticsAdapter.initOptions.pubId;
75-
try { completeObject.referer = args.bidderRequests[0].refererInfo.referer.split('?')[0]; } catch (e) { console.log(e.message); }
75+
try { completeObject.referer = args.bidderRequests[0].refererInfo.referer.split('?')[0]; } catch (e) { utils.logWarn('Could not parse referer, error details:', e.message); }
7676
completeObject.device_type = deviceType();
7777
}
7878
function bidRequested(args) {
@@ -130,11 +130,11 @@ function sendEvent(completeObject) {
130130
let responseEvents = btoa(JSON.stringify(completeObject));
131131
let mutation = `mutation {createEvent(input: {event: {eventData: "${responseEvents}"}}) {event {createTime } } }`;
132132
let dataToSend = JSON.stringify({ query: mutation });
133-
ajax(url, function () { console.log(Date.now() + ' Sending event to adxpremium server.') }, dataToSend, {
133+
ajax(url, function () { utils.logInfo(Date.now() + ' Sending event to adxpremium server.') }, dataToSend, {
134134
contentType: 'application/json',
135135
method: 'POST'
136136
});
137-
} catch (err) { console.log(err) }
137+
} catch (err) { utils.logError('Could not send event, error details:', err) }
138138
}
139139

140140
// save the base class function

modules/nobidBidAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function nobidBuildRequests(bids, bidderRequest) {
9999
var height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
100100
return `${width}x${height}`;
101101
} catch (e) {
102-
console.error(e);
102+
utils.logWarn('Could not parse screen dimensions, error details:', e);
103103
}
104104
}
105105
var state = {};

modules/sharethroughBidAdapter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { registerBidder } from '../src/adapters/bidderFactory.js';
2+
import * as utils from '../src/utils.js';
23

34
const VERSION = '3.2.1';
45
const BIDDER_CODE = 'sharethrough';
@@ -181,7 +182,7 @@ function handleIframe () {
181182
window.document.getElementsByTagName('body')[0].appendChild(sfpIframeBusterJs);
182183
iframeBusterLoaded = true;
183184
} catch (e) {
184-
console.error(e);
185+
utils.logError('Trouble writing frame buster script, error details:', e);
185186
}
186187
}
187188

@@ -199,7 +200,7 @@ function handleIframe () {
199200
window.document.getElementsByTagName('body')[0].appendChild(sfpJs);
200201
}
201202
} catch (e) {
202-
console.error(e);
203+
utils.logError('Trouble writing sfp script, error details:', e);
203204
}
204205
}
205206
}

modules/sovrnBidAdapter.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ export const spec = {
107107
options: {contentType: 'text/plain'}
108108
}
109109
} catch (e) {
110-
console.log('error in build:')
111-
console.log(e)
110+
utils.logError('Could not build bidrequest, error deatils:', e);
112111
}
113112
},
114113

@@ -143,8 +142,7 @@ export const spec = {
143142
}
144143
return sovrnBidResponses
145144
} catch (e) {
146-
console.log('error in interpret:')
147-
console.log(e)
145+
utils.logError('Could not intrepret bidresponse, error deatils:', e);
148146
}
149147
},
150148

src/adapters/analytics/example2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
import { ajax } from '../../../src/ajax.js';
23

34
/**

src/adapters/analytics/libraries/example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
/** @module example */
23

34
window.ExampleAnalyticsGlobalObject = function(hander, type, data) {

src/adapters/analytics/libraries/example2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
/** @module example */
23

34
window.ExampleAnalyticsGlobalObject2 = function(hander, type, data) {

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
import { config } from './config.js';
23
import clone from 'just-clone';
34
import find from 'core-js/library/fn/array/find.js';

test/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ module.exports = {
3535
"no-unused-vars": "off",
3636
"no-use-before-define": "off",
3737
"no-useless-escape": "off",
38-
"one-var": "off",
38+
"one-var": "off"
3939
}
4040
};

test/mock-server/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
const express = require('express');
23
const argv = require('yargs').argv;
34
const app = module.exports = express();

test/spec/modules/onetagBidAdapter_spec.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,14 @@ describe('onetag', function () {
8080
expect(bid.pubId).to.be.a('string');
8181
}
8282
});
83-
} catch (e) {
84-
console.log('Error while parsing');
85-
}
83+
} catch (e) {}
8684
it('Returns empty data if no valid requests are passed', function () {
8785
serverRequest = spec.buildRequests([]);
8886
let dataString = serverRequest.data;
8987
try {
9088
let dataObj = JSON.parse(dataString);
9189
expect(dataObj.bids).to.be.an('array').that.is.empty;
92-
} catch (e) {
93-
console.log('Error while parsing');
94-
}
90+
} catch (e) {}
9591
});
9692
it('should send GDPR consent data', function () {
9793
let consentString = 'consentString';

test/spec/modules/tribeosBidAdapter_spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ describe('tribeosBidAdapter', function() {
7575
expect(bids).to.have.lengthOf(1);
7676
let bid = bids[0];
7777

78-
console.error(JSON.stringify(bid));
79-
8078
expect(bid.cpm).to.equal(1.1);
8179
expect(bid.currency).to.equal('USD');
8280
expect(bid.width).to.equal(300);

test/spec/unit/pbjs_api_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ describe('Unit: Prebid Module', function () {
14571457
try {
14581458
$$PREBID_GLOBAL$$.requestBids({});
14591459
} catch (e) {
1460-
console.log(e);
1460+
console.log(e); // eslint-disable-line
14611461
}
14621462
assert.ok(logMessageSpy.calledWith('No adUnits configured. No bids requested.'), 'expected message was logged');
14631463
});

0 commit comments

Comments
 (0)