Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create test.js #17

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
3b21571
relevatehealthBidAdapter.js: bugfix for storage used without consent
patmmccann Jun 28, 2024
0491a7e
Update index.js
patmmccann Jun 28, 2024
c624d74
Update index.js
patmmccann Jun 28, 2024
b81d4dc
Update index.js
patmmccann Jun 28, 2024
5971e5a
Update index.js
patmmccann Jun 28, 2024
a2cdfa0
Update index.js
patmmccann Jun 28, 2024
847c994
Update index.js
patmmccann Jun 28, 2024
9f494c9
Update index.js
patmmccann Jun 28, 2024
4967683
Update index.js
patmmccann Jun 28, 2024
054fbca
Update relevatehealthBidAdapter.js
patmmccann Jun 28, 2024
78a7623
Update index.js
patmmccann Jun 28, 2024
68b864e
Update index.js
patmmccann Jun 28, 2024
886ebc1
Update index.js
patmmccann Jun 28, 2024
ff8a0be
Update index.js
patmmccann Jun 28, 2024
dbc3aa2
Update index.js
patmmccann Jun 28, 2024
7294b36
Update .eslintrc.js
patmmccann Jun 28, 2024
7e66b62
Update index.js
patmmccann Jun 28, 2024
5fa5a52
Update relevatehealthBidAdapter.js
patmmccann Jun 28, 2024
f885004
Update 33acrossAnalyticsAdapter.js
patmmccann Jun 28, 2024
6c96912
Update index.js
patmmccann Jun 28, 2024
fcdce60
Update index.js
patmmccann Jun 28, 2024
f3d5b01
Update 33acrossAnalyticsAdapter.js
patmmccann Jun 28, 2024
43c76c0
Update index.js
patmmccann Jun 28, 2024
75a3ab4
Update ampliffyBidAdapter.js
patmmccann Jun 28, 2024
383df30
Update index.js
patmmccann Jun 28, 2024
ce78bf0
Update invibesBidAdapter.js
patmmccann Jun 28, 2024
1e70fa5
Update growthCodeAnalyticsAdapter.js
patmmccann Jun 28, 2024
93ae8a1
Update fintezaAnalyticsAdapter.js
patmmccann Jun 28, 2024
28f335e
Update growthCodeAnalyticsAdapter.js
patmmccann Jun 28, 2024
66ec05c
Update etargetBidAdapter.js
patmmccann Jun 28, 2024
768f252
Update dspxBidAdapter.js
patmmccann Jun 28, 2024
88ad007
Update cwireBidAdapter.js
patmmccann Jun 28, 2024
5ad7fe9
Update cwireBidAdapter.js
patmmccann Jun 28, 2024
bbd9533
Update ampliffyBidAdapter.js
patmmccann Jun 28, 2024
193c91f
Update etargetBidAdapter.js
patmmccann Jun 28, 2024
c0f2f99
Update dspxBidAdapter.js
patmmccann Jun 28, 2024
5a7cfa5
Update fintezaAnalyticsAdapter.js
patmmccann Jun 28, 2024
07e187a
Update ampliffyBidAdapter.js
patmmccann Jun 28, 2024
cae7381
Update adlooxAnalyticsAdapter.js
patmmccann Jun 28, 2024
1a9fe34
Update invibesBidAdapter.js
patmmccann Jun 28, 2024
874b7f3
Update fintezaAnalyticsAdapter.js
patmmccann Jun 28, 2024
7bbb643
Update dspxBidAdapter.js
patmmccann Jun 28, 2024
a1b460e
Update connectIdSystem.js
patmmccann Jun 28, 2024
fc40a4a
Update automatadAnalyticsAdapter.js
patmmccann Jun 28, 2024
8cea733
Update sonobiBidAdapter.js
patmmccann Jun 28, 2024
aca39d5
Update contxtfulRtdProvider.js
patmmccann Jun 28, 2024
f55e83f
Update sonobiBidAdapter.js
patmmccann Jun 28, 2024
74f711c
Update contxtfulRtdProvider.js
patmmccann Jun 28, 2024
a29d7d3
Update index.js
patmmccann Jun 28, 2024
bf13e59
Update cleanioRtdProvider.js
patmmccann Jun 28, 2024
d9c6e50
Update connectIdSystem.js
patmmccann Jun 28, 2024
fa6471d
Update geoedgeRtdProvider.js
patmmccann Jun 28, 2024
f8258d4
Update growthCodeRtdProvider.js
patmmccann Jun 28, 2024
01a8f4b
Update sirdataRtdProvider.js
patmmccann Jun 28, 2024
db2e7ba
Update sirdataRtdProvider.js
patmmccann Jun 28, 2024
679e93f
Update contxtfulRtdProvider_spec.js
patmmccann Jun 29, 2024
292bb30
Update contxtfulRtdProvider_spec.js
patmmccann Jun 29, 2024
789e8b4
Update index.js
patmmccann Jun 30, 2024
abcc1b2
Update index.js
patmmccann Jul 1, 2024
5d4f6b2
refactor custom linter rules
dgirardi Jul 1, 2024
c8303aa
Merge branch 'master' into patmmccann-patch-10
dgirardi Jul 1, 2024
5973d8f
use TODO and comments instead of quietly removing rule-breaking code
dgirardi Jul 1, 2024
831ea69
Add linter GH action
dgirardi Jul 1, 2024
44362d8
Fix linter workflow name
dgirardi Jul 1, 2024
e4ece94
Run npm ci on linter check
dgirardi Jul 1, 2024
01f8406
Filter out missing (new) files
dgirardi Jul 1, 2024
bad26d6
Create test.js
dgirardi Jul 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,52 @@ module.exports = {
files: key + '/**/*.js',
rules: {
'prebid/validate-imports': ['error', allowedModules[key]],
'prebid/no-innerText': ['error', allowedModules[key]],
'no-restricted-globals': [
'error',
{
name: 'require',
message: 'use import instead'
}
],
'prebid/no-global': [
'error',
...['localStorage', 'sessionStorage'].map(name => ({name, message: 'use storageManager instead'})),
{
name: 'XMLHttpRequest',
message: 'use ajax.js instead'
},
],
'prebid/no-member': [
'error',
{
name: 'cookie',
target: 'document',
message: 'use storageManager instead'
},
{
name: 'sendBeacon',
target: 'navigator',
message: 'use ajax.js instead'
},
...['outerText', 'innerText'].map(name => ({
name,
message: 'use .textContent instead'
}))
]
}
})).concat([{
// code in other packages (such as plugins/eslint) is not "seen" by babel and its parser will complain.
files: 'plugins/*/**/*.js',
parser: 'esprima'
},
{
}, {
files: '**BidAdapter.js',
rules: {
'no-restricted-imports': [
'error', {
patterns: ["**/src/events.js",
"**/src/adloader.js"]
patterns: [
'**/src/events.js',
'**/src/adloader.js'
]
}
]
}
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Check for linter warnings / exceptions

on:
pull_request_target:
branches:
- master

jobs:
check-linter:
runs-on: ubuntu-latest

steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.base.sha }}

- name: Fetch base and target branches
run: |
git fetch origin +refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}
git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge:refs/remotes/pull/${{ github.event.pull_request.number }}/merge

- name: Install dependencies
run: npm ci

- name: Get the diff
run: git diff --name-only origin/${{ github.event.pull_request.base.ref }}...refs/remotes/pull/${{ github.event.pull_request.number }}/merge > __changed_files.txt

- name: Run linter on base branch
run: npx eslint --no-inline-config --format json $(cat __changed_files.txt | xargs stat --printf '%n\n' 2> /dev/null) > __base.json

- name: Check out PR
run: git checkout ${{ github.event.pull_request.head.sha }}

- name: Run linter on PR
run: npx eslint --no-inline-config --format json $(cat __changed_files.txt | xargs stat --printf '%n\n' 2> /dev/null) > __pr.json

- name: Compare them and post comment if necessary
if: env.filtered_report_exists == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const process = require('process');

function parse(fn) {
return JSON.parse(fs.readFileSync(fn)).reduce((memo, data) => {
const file = path.relative(process.cwd(), data.filePath);
if (!memo.hasOwnProperty(file)) { memo[file] = { errors: 0, warnings: 0} }
data.messages.forEach(({severity}) => {
memo[file][severity > 1 ? 'errors' : 'warnings']++;
});
return memo;
}, {})
}

function mkDiff(old, new_) {
const files = Object.fromEntries(
Object.entries(new_)
.map(([file, {errors, warnings}]) => {
const {errors: oldErrors, warnings: oldWarnings} = old[file] || {};
return [file, {errors: errors - (oldErrors ?? 0), warnings: warnings - (oldWarnings ?? 0)}]
})
.filter(([_, {errors, warnings}]) => errors > 0 || warnings > 0)
)
return Object.values(files).reduce((memo, {warnings, errors}) => {
memo.errors += errors;
memo.warnings += warnings;
return memo;
}, {errors: 0, warnings: 0, files})
}

function mkComment({errors, warnings, files}) {
if (errors === 0 && warnings === 0) return;
const summary = [];
if (errors) summary.push(`**${errors}** linter errors`)
if (warnings) summary.push(`**${warnings}** linter warnings`)
let cm = `This pr adds ${summary.join(' and ')} (possibly disabled through directives):\n\n`;
Object.entries(files).forEach(([file, {errors, warnings}]) => {
const summary = [];
if (errors) summary.push(`+${errors} errors`);
if (warnings) summary.push(`+${warnings} warnings`)
cm += ` * \`${file}\` (${summary.join(', ')})\n`
})
return cm;
}

const [base, pr] = ['__base.json', '__pr.json'].map(parse);
const comment = mkComment(mkDiff(base, pr));

if (comment) {
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}
2 changes: 2 additions & 0 deletions modules/33acrossAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ function setCachedBidStatus(auctionId, bidId, status) {
* @param {string} endpoint URL
*/
function sendReport(report, endpoint) {
// TODO FIX THIS RULES VIOLATION
// eslint-disable-next-line
if (navigator.sendBeacon(endpoint, JSON.stringify(report))) {
log.info(`Analytics report sent to ${endpoint}`, report);

Expand Down
1 change: 1 addition & 0 deletions modules/adlooxAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ analyticsAdapter[`handle_${EVENTS.AUCTION_END}`] = function(auctionDetails) {
link.setAttribute('href', `${uri.protocol}://${uri.host}${uri.pathname}`);
link.setAttribute('rel', 'preload');
link.setAttribute('as', 'script');
// TODO fix rules violation
insertElement(link);
}

Expand Down
2 changes: 2 additions & 0 deletions modules/automatadAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var isLoggingEnabled; var queuePointer = 0; var retryCount = 0; var timer = null

const prettyLog = (level, text, isGroup = false, cb = () => {}) => {
if (self.isLoggingEnabled === undefined) {
// TODO FIX THIS RULES VIOLATION
// eslint-disable-next-line prebid/no-global
if (window.localStorage.getItem('__aggLoggingEnabled')) {
self.isLoggingEnabled = true
} else {
Expand Down
1 change: 1 addition & 0 deletions modules/cleanioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let preloadStatus = 0;
* @param {string} scriptURL The script URL to preload
*/
function pageInitStepPreloadScript(scriptURL) {
// TODO: this bypasses adLoader
const linkElement = document.createElement('link');
linkElement.rel = 'preload';
linkElement.as = 'script';
Expand Down
4 changes: 3 additions & 1 deletion modules/connectIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,13 @@ export const connectIdSubmodule = {

/**
* Utility function that returns a boolean flag indicating if the user
* has opeted out via the Yahoo easy-opt-out mechanism.
* has opted out via the Yahoo easy-opt-out mechanism.
* @returns {Boolean}
*/
userHasOptedOut() {
try {
// TODO FIX THIS RULES VIOLATION
// eslint-disable-next-line
return localStorage.getItem(OVERRIDE_OPT_OUT_KEY) === '1';
} catch {
return false;
Expand Down
5 changes: 4 additions & 1 deletion modules/contxtfulRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function getRxEngineReceptivity(requester) {
}

function loadSessionReceptivity(requester) {
// TODO: commented out because of rule violations
/*
let sessionStorageValue = sessionStorage.getItem(requester);
if (!sessionStorageValue) {
return null;
Expand All @@ -54,7 +56,8 @@ function loadSessionReceptivity(requester) {
} catch {
return null;
}
};
*/
}

/**
* Prepare a receptivity batch
Expand Down
4 changes: 4 additions & 0 deletions modules/cwireBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ export const spec = {
bid: bid
}
}
// TODO FIX THIS RULES VIOLATION
// eslint-disable-next-line prebid/no-member
navigator.sendBeacon(EVENT_ENDPOINT, JSON.stringify(event))
},

Expand All @@ -236,6 +238,8 @@ export const spec = {
bidderRequest: bidderRequest
}
}
// TODO FIX THIS RULES VIOLATION
// eslint-disable-next-line prebid/no-member
navigator.sendBeacon(EVENT_ENDPOINT, JSON.stringify(event))
},

Expand Down
3 changes: 3 additions & 0 deletions modules/debugging/debugging.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function disableDebugging({hook, logger}) {
}
}

// eslint-disable-next-line prebid/no-global
function saveDebuggingConfig(debugConfig, {sessionStorage = window.sessionStorage, DEBUG_KEY} = {}) {
if (!debugConfig.enabled) {
try {
Expand All @@ -49,6 +50,7 @@ function saveDebuggingConfig(debugConfig, {sessionStorage = window.sessionStorag
}
}

// eslint-disable-next-line prebid/no-global
export function getConfig(debugging, {getStorage = () => window.sessionStorage, DEBUG_KEY, config, hook, logger} = {}) {
if (debugging == null) return;
let sessionStorage;
Expand All @@ -70,6 +72,7 @@ export function getConfig(debugging, {getStorage = () => window.sessionStorage,
export function sessionLoader({DEBUG_KEY, storage, config, hook, logger}) {
let overrides;
try {
// eslint-disable-next-line prebid/no-global
storage = storage || window.sessionStorage;
overrides = JSON.parse(storage.getItem(DEBUG_KEY));
} catch (e) {
Expand Down
2 changes: 2 additions & 0 deletions modules/dgkeywordRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export function getProfileApiUrl(customeUrl, enableReadFpid) {

export function readFpidFromLocalStrage() {
try {
// TODO: use storageManager
// eslint-disable-next-line prebid/no-global
const fpid = window.localStorage.getItem('ope_fpid');
if (fpid) {
return fpid;
Expand Down
13 changes: 9 additions & 4 deletions modules/fintezaAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function initFirstVisit() {
let cookies;

try {
cookies = parseCookies(document.cookie);
// TODO: commented out because of rule violations
cookies = {} // parseCookies(document.cookie);
} catch (a) {
cookies = {};
}
Expand All @@ -91,7 +92,8 @@ function initFirstVisit() {

return visitDate;
}

// TODO: commented out because of rule violations
/*
function trim(string) {
if (string.trim) {
return string.trim();
Expand Down Expand Up @@ -130,6 +132,7 @@ function parseCookies(cookie) {

return values;
}
*/

function getRandAsStr(digits) {
let str = '';
Expand Down Expand Up @@ -172,7 +175,8 @@ function initSession() {
let isNew = false;

try {
cookies = parseCookies(document.cookie);
// TODO: commented out because of rule violations
cookies = {} // parseCookies(document.cookie);
} catch (a) {
cookies = {};
}
Expand Down Expand Up @@ -263,7 +267,8 @@ function getTrackRequestLastTime() {
);
}

cookie = parseCookies(document.cookie);
// TODO: commented out because of rule violations
cookie = {} // parseCookies(document.cookie);
cookie = cookie[ TRACK_TIME_KEY ];
if (cookie) {
return parseInt(cookie, 10);
Expand Down
2 changes: 1 addition & 1 deletion modules/growthCodeAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function logToServer() {
if (pid === DEFAULT_PID) return;
if (eventQueue.length >= 1) {
// Get the correct GCID
let gcid = localStorage.getItem('gcid')
let gcid = storage.getDataFromLocalStorage('gcid');

let data = {
session: sessionId,
Expand Down
2 changes: 1 addition & 1 deletion modules/growthCodeRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function callServer(configParams, items, expiresAt, userConsent) {
storage.removeDataFromLocalStorage(RTD_EXPIRE_KEY, null)
}
if ((items === null) && (isNaN(expiresAt))) {
let gcid = localStorage.getItem('gcid')
let gcid = storage.getDataFromLocalStorage('gcid')

let url = configParams.url ? configParams.url : ENDPOINT_URL;
url = tryAppendQueryString(url, 'pid', configParams.pid);
Expand Down
3 changes: 2 additions & 1 deletion modules/relevatehealthBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ function buildUser(bid) {
if (bid && bid.params) {
return {
id: bid.params.user_id && typeof bid.params.user_id == 'string' ? bid.params.user_id : '',
buyeruid: localStorage.getItem('adx_profile_guid') ? localStorage.getItem('adx_profile_guid') : '',
// TODO: commented out because of rule violations
buyeruid: '', // localStorage.getItem('adx_profile_guid') ? localStorage.getItem('adx_profile_guid') : '',
keywords: bid.params.keywords && typeof bid.params.keywords == 'string' ? bid.params.keywords : '',
customdata: bid.params.customdata && typeof bid.params.customdata == 'string' ? bid.params.customdata : ''
};
Expand Down
2 changes: 2 additions & 0 deletions modules/sirdataRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export function postContentForSemanticAnalysis(postContentToken, actualUrl) {

// Use the Beacon API if supported to send the payload
if ('sendBeacon' in navigator) {
// TODO FIX RULES VIOLATION
// eslint-disable-next-line prebid/no-member
navigator.sendBeacon(url, payload);
} else {
// Fallback to using AJAX if Beacon API is not supported
Expand Down
Loading
Loading