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

Update Linter & Remove Unsafe React Lifecycle Events #552

Closed
wants to merge 13 commits into from
Closed
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

add linting for no-prototype-builtins and fix resulting linting errors

  • Loading branch information
IAmThePan committed May 4, 2020
commit fe03ad7a1bea609af11e8dc47aecb8c262efc970
@@ -65,8 +65,8 @@ module.exports = {
]
}],
'no-plusplus': [0],
'no-prototype-builtins': [0], // TODO: enable this check
'no-restricted-syntax': [1],
'no-prototype-builtins': [1],
'no-restricted-syntax': [0], // TODO: enable this check
'no-tabs': [0],
'no-underscore-dangle': [0],
'no-unused-vars': [1],
@@ -184,7 +184,7 @@ const Click2PlayContentScript = (function(win, doc) {
const app_ids = Object.keys(C2P_DATA);
for (let i = 0; i < app_ids.length; i++) {
const app_id = app_ids[i];
if (C2P_DATA.hasOwnProperty(app_id)) {
if (Object.prototype.hasOwnProperty.call(C2P_DATA, app_id)) {
if (C2P_DATA[app_id].length >= 3) {
applyC2P(C2P_DATA[app_id][0], C2P_DATA[app_id][1], C2P_DATA[app_id][2]);
}
@@ -51,7 +51,7 @@ export default class FixedMenu extends React.Component {
const categories = Object.keys(this.antiTrackingData);
for (let i = 0; i < categories.length; i++) {
const category = categories[i];
if (this.antiTrackingData.hasOwnProperty(category)) {
if (Object.prototype.hasOwnProperty.call(this.antiTrackingData, category)) {
const apps = Object.keys(this.antiTrackingData[category]);
for (let j = 0; j < apps.length; j++) {
const app = apps[j];
@@ -206,7 +206,7 @@ const _updateCliqzModuleWhitelist = (state, action) => {

const addToWhitelist = () => {
unknownTracker.domains.forEach((domain) => {
if (whitelistedUrls.hasOwnProperty(domain)) {
if (Object.prototype.hasOwnProperty.call(whitelistedUrls, domain)) {
whitelistedUrls[domain].name = unknownTracker.name;
whitelistedUrls[domain].hosts.push(pageHost);
} else {
@@ -303,14 +303,14 @@ const _showNotification = (state, action) => {
updated_needsReload = { ...state.needsReload, changes: { ...state.needsReload.changes } };

// handle case where user clicks 'whitelist' then 'blacklist', or inverse
if (msg.updated === 'blacklist' && updated_needsReload.changes.hasOwnProperty('whitelist')) {
if (msg.updated === 'blacklist' && Object.prototype.hasOwnProperty.call(updated_needsReload.changes, 'whitelist')) {
delete updated_needsReload.changes.whitelist;
} else if (msg.updated === 'whitelist' && updated_needsReload.changes.hasOwnProperty('blacklist')) {
} else if (msg.updated === 'whitelist' && Object.prototype.hasOwnProperty.call(updated_needsReload.changes, 'blacklist')) {
delete updated_needsReload.changes.blacklist;
}

// update the 'changes' object. if the changed item already exists, remove it to signal a disable has occurred
if (updated_needsReload.changes.hasOwnProperty(msg.updated)) {
if (Object.prototype.hasOwnProperty.call(updated_needsReload.changes, msg.updated)) {
delete updated_needsReload.changes[msg.updated];
} else if (msg.updated !== 'init') { // ignore the 'init' change, which comes from Panel.jsx to persist banners
updated_needsReload.changes[msg.updated] = true;
@@ -33,8 +33,8 @@ export function updateSummaryBlockingCount(categories = [], smartBlock, updateTr
categories.forEach((categoryEl) => {
categoryEl.trackers.forEach((trackerEl) => {
numTotal++;
const sbBlocked = smartBlock.blocked.hasOwnProperty(trackerEl.id);
const sbUnblocked = smartBlock.unblocked.hasOwnProperty(trackerEl.id);
const sbBlocked = Object.prototype.hasOwnProperty.call(smartBlock.blocked, trackerEl.id);
const sbUnblocked = Object.prototype.hasOwnProperty.call(smartBlock.unblocked, trackerEl.id);

if (trackerEl.ss_blocked || sbBlocked || (trackerEl.blocked && !trackerEl.ss_allowed && !sbUnblocked)) {
numTotalBlocked++;
@@ -81,8 +81,8 @@ export function updateBlockAllTrackers(state, action) {
updated_categories.forEach((categoryEl) => {
categoryEl.num_blocked = 0;
categoryEl.trackers.forEach((trackerEl) => {
const sbBlocked = smartBlock.blocked.hasOwnProperty(trackerEl.id);
const sbUnblocked = smartBlock.unblocked.hasOwnProperty(trackerEl.id);
const sbBlocked = Object.prototype.hasOwnProperty.call(smartBlock.blocked, trackerEl.id);
const sbUnblocked = Object.prototype.hasOwnProperty.call(smartBlock.unblocked, trackerEl.id);

if (trackerEl.shouldShow) {
trackerEl.blocked = blocked;
@@ -124,8 +124,8 @@ export function updateCategoryBlocked(state, action) {
const updated_category = updated_categories[catIndex];
updated_category.num_blocked = 0;
updated_category.trackers.forEach((trackerEl) => {
const sbBlocked = smartBlock.blocked.hasOwnProperty(trackerEl.id);
const sbUnblocked = smartBlock.unblocked.hasOwnProperty(trackerEl.id);
const sbBlocked = Object.prototype.hasOwnProperty.call(smartBlock.blocked, trackerEl.id);
const sbUnblocked = Object.prototype.hasOwnProperty.call(smartBlock.unblocked, trackerEl.id);

if (trackerEl.shouldShow) {
trackerEl.blocked = blocked;
@@ -194,8 +194,8 @@ export function updateTrackerBlocked(state, action) {

updated_category.num_blocked = 0;
updated_category.trackers.forEach((trackerEl) => {
const sbBlocked = smartBlock.blocked.hasOwnProperty(trackerEl.id);
const sbUnblocked = smartBlock.unblocked.hasOwnProperty(trackerEl.id);
const sbBlocked = Object.prototype.hasOwnProperty.call(smartBlock.blocked, trackerEl.id);
const sbUnblocked = Object.prototype.hasOwnProperty.call(smartBlock.unblocked, trackerEl.id);

if (trackerEl.shouldShow) {
if (trackerEl.id === action.data.app_id) {
@@ -128,10 +128,10 @@ function setGhosteryDefaultBlocking() {
const app_ids = Object.keys(bugDb.db.apps);
for (let i = 0; i < app_ids.length; i++) {
const app_id = app_ids[i];
if (bugDb.db.apps.hasOwnProperty(app_id)) {
if (Object.prototype.hasOwnProperty.call(bugDb.db.apps, app_id)) {
const category = bugDb.db.apps[app_id].cat;
if (categoriesBlock.indexOf(category) >= 0 &&
!selected_app_ids.hasOwnProperty(app_id)) {
!Object.prototype.hasOwnProperty.call(selected_app_ids, app_id)) {
selected_app_ids[app_id] = 1;
}
}
@@ -497,7 +497,7 @@ function handleRewards(name, message, callback) {
metrics.ping(message);
break;
case 'setPanelData':
if (message.hasOwnProperty('enable_offers')) {
if (Object.prototype.hasOwnProperty.call(message, 'enable_offers')) {
rewards.sendSignal(message.signal);
panelData.set({ enable_offers: message.enable_offers });
}
@@ -579,7 +579,7 @@ function handleGhosteryHub(name, message, callback) {
const app_ids = Object.keys(bugDb.db.apps);
for (let i = 0; i < app_ids.length; i++) {
const app_id = app_ids[i];
if (!selected_app_ids.hasOwnProperty(app_id)) {
if (!Object.prototype.hasOwnProperty.call(selected_app_ids, app_id)) {
selected_app_ids[app_id] = 1;
}
}
@@ -775,7 +775,7 @@ function onMessageHandler(request, sender, callback) {
const { email, password } = message;
account.login(email, password)
.then((response) => {
if (!response.hasOwnProperty('errors')) {
if (!Object.property.hasOwnProperty.call(response, 'errors')) {
metrics.ping('sign_in_success');
}
callback(response);
@@ -792,7 +792,7 @@ function onMessageHandler(request, sender, callback) {
} = message;
account.register(email, confirmEmail, password, firstName, lastName)
.then((response) => {
if (!response.hasOwnProperty('errors')) {
if (!Object.property.hasOwnProperty.call(response, 'errors')) {
metrics.ping('create_account_success');
}
callback(response);
@@ -1012,7 +1012,7 @@ function initializeDispatcher() {
const { db } = bugDb;
db.noneSelected = (num_selected === 0);
// can't simply compare num_selected and size(db.apps) since apps get removed sometimes
db.allSelected = (!!num_selected && every(db.apps, (app, app_id) => appIds.hasOwnProperty(app_id)));
db.allSelected = (!!num_selected && every(db.apps, (app, app_id) => Object.property.hasOwnProperty.call(appIds, app_id)));
});
dispatcher.on('conf.save.site_whitelist', () => {
// TODO debounce with below
@@ -34,7 +34,7 @@ class ABTest {
* @param {string} name test name
*/
hasTest(name) {
return this.tests.hasOwnProperty(name);
return Object.prototype.hasOwnProperty.call(this.tests, name);
}

/**
@@ -85,20 +85,20 @@ class BugDb extends Updatable {
const categories = {};

for (appId in db.apps) {
if (db.apps.hasOwnProperty(appId)) {
if (Object.prototype.hasOwnProperty.call(db.apps, appId)) {
category = db.apps[appId].cat;
if (t(`category_${category}`) === `category_${category}`) {
category = 'uncategorized';
}
blocked = selectedApps.hasOwnProperty(appId);
blocked = Object.prototype.hasOwnProperty.call(selectedApps, appId);

// Because we have two trackers in the DB with the same name
if ((categories[category] && categories[category].trackers[db.apps[appId].name])) {
// eslint-disable-next-line no-continue
continue;
}

if (categories.hasOwnProperty(category)) {
if (Object.prototype.hasOwnProperty.call(categories, category)) {
categories[category].num_total++;
if (blocked) {
categories[category].num_blocked++;
@@ -129,7 +129,7 @@ class BugDb extends Updatable {
const categoryNames = Object.keys(categories);
for (let i = 0; i < categoryNames.length; i++) {
categoryName = categoryNames[i];
if (categories.hasOwnProperty(categoryName)) {
if (Object.prototype.hasOwnProperty.call(categories, categoryName)) {
const category = categories[categoryName];
if (category.trackers) {
category.trackers.sort((a, b) => {
@@ -182,7 +182,7 @@ class BugDb extends Updatable {
log('initializing bugdb regexes...');

for (const id in regexes) {
if (regexes.hasOwnProperty(id)) {
if (Object.prototype.hasOwnProperty.call(regexes, id)) {
db.patterns.regex[id] = new RegExp(regexes[id], 'i');
}
}
@@ -195,7 +195,7 @@ class BugDb extends Updatable {
// since allSelected is slow to eval, make it lazy
defineLazyProperty(db, 'allSelected', () => {
const num_selected = size(conf.selected_app_ids);
return (!!num_selected && every(db.apps, (app, app_id) => conf.selected_app_ids.hasOwnProperty(app_id)));
return (!!num_selected && every(db.apps, (app, app_id) => Object.prototype.hasOwnProperty.call(conf.selected_app_ids, app_id)));
});

log('processed bugdb...');
@@ -206,7 +206,7 @@ class BugDb extends Updatable {
// if there is an older bugs object in storage,
// update newAppIds and apply block-by-default
if (old_bugs) {
if (old_bugs.hasOwnProperty('version') && bugs.version > old_bugs.version) {
if (Object.prototype.hasOwnProperty.call(old_bugs, 'version') && bugs.version > old_bugs.version) {
new_app_ids = this.updateNewAppIds(bugs.apps, old_bugs.apps);

if (new_app_ids.length) {
@@ -215,7 +215,7 @@ class BugDb extends Updatable {
}

// pre-trie/legacy db
} else if (old_bugs.hasOwnProperty('bugsVersion') && bugs.version !== old_bugs.bugsVersion) {
} else if (Object.prototype.hasOwnProperty.call(old_bugs, 'bugsVersion') && bugs.version !== old_bugs.bugsVersion) {
const old_apps = reduce(old_bugs.bugs, (memo, bug) => {
memo[bug.aid] = true;
return memo;
@@ -66,7 +66,7 @@ class Click2PlayDb extends Updatable {

// TODO memory leak when you close tabs before reset() can run?
reset(tab_id) {
if (!this.allowOnceList.hasOwnProperty(tab_id)) { return; }
if (!Object.prototype.hasOwnProperty.call(this.allowOnceList, tab_id)) { return; }

const entries = Object.entries(this.allowOnceList[tab_id]);
let keep = false;
@@ -84,8 +84,8 @@ class Click2PlayDb extends Updatable {

allowedOnce(tab_id, aid) {
return (
this.allowOnceList.hasOwnProperty(tab_id) &&
this.allowOnceList[tab_id].hasOwnProperty(aid) &&
Object.prototype.hasOwnProperty.call(this.allowOnceList, tab_id) &&
Object.prototype.hasOwnProperty.call(this.allowOnceList[tab_id], aid) &&
this.allowOnceList[tab_id][aid] > 0
);
}
@@ -113,7 +113,7 @@ class Click2PlayDb extends Updatable {
let allow;

entries.forEach((entry) => {
if (!apps.hasOwnProperty(entry.aid)) {
if (!Object.prototype.hasOwnProperty.call(apps, entry.aid)) {
apps[entry.aid] = [];
}

@@ -66,7 +66,7 @@ class CompatibilityDb extends Updatable {
* @return {Boolean}
*/
hasIssue(aid, tab_url) {
return this.db.list && this.db.list.hasOwnProperty(aid) && fuzzyUrlMatcher(tab_url, this.db.list[aid]);
return this.db.list && Object.prototype.hasOwnProperty.call(this.db.list, aid) && fuzzyUrlMatcher(tab_url, this.db.list[aid]);
}

/**
@@ -186,12 +186,12 @@ class ConfData {

let lang = window.navigator.language.replace('-', '_');

if (SUPPORTED_LANGUAGES.hasOwnProperty(lang)) {
if (Object.prototype.hasOwnProperty.call(SUPPORTED_LANGUAGES, lang)) {
return lang;
}

lang = lang.slice(0, 2);
if (SUPPORTED_LANGUAGES.hasOwnProperty(lang)) {
if (Object.prototype.hasOwnProperty.call(SUPPORTED_LANGUAGES, lang)) {
return lang;
}

@@ -139,7 +139,7 @@ class FoundBugs {

if (app_id) {
const { appsById } = this._foundApps[tab_id];
if (appsById.hasOwnProperty(app_id)) {
if (Object.prototype.hasOwnProperty.call(appsById, app_id)) {
apps_arr.push(apps[appsById[app_id]]);
}
} else {
@@ -203,11 +203,11 @@ class FoundBugs {
const ids = Object.keys(bugs);
for (let i = 0; i < ids.length; i++) {
id = ids[i];
if (bugs.hasOwnProperty(id)) {
if (Object.prototype.hasOwnProperty.call(bugs, id)) {
aid = db.bugs[id].aid; // eslint-disable-line prefer-destructuring
cid = db.apps[aid].cat;

if (cats_obj.hasOwnProperty(cid)) {
if (Object.prototype.hasOwnProperty.call(cats_obj, cid)) {
if (!cats_obj[cid].appIds.includes(aid)) {
cats_obj[cid].appIds.push(aid);
cats_obj[cid].trackers.push({
@@ -244,7 +244,7 @@ class FoundBugs {
const cids = Object.keys(cats_obj);
for (let i = 0; i < cids.length; i++) {
cid = cids[i];
if (cats_obj.hasOwnProperty(cid)) {
if (Object.prototype.hasOwnProperty.call(cats_obj, cid)) {
cats_arr.push(cats_obj[cid]);
}
}
@@ -364,7 +364,7 @@ class FoundBugs {
const { aid } = bugDb.db.bugs[bug_id];

const { apps, appsById, issueCounts } = this._foundApps[tab_id];
if (appsById.hasOwnProperty(aid)) {
if (Object.prototype.hasOwnProperty.call(appsById, aid)) {
const app = apps[appsById[aid]];
if (!app.hasLatencyIssue) {
issueCounts.latency++;
@@ -395,11 +395,11 @@ class FoundBugs {
return false;
}

if (!this._foundBugs.hasOwnProperty(tab_id)) {
if (!Object.prototype.hasOwnProperty.call(this._foundBugs, tab_id)) {
this._foundBugs[tab_id] = {};
}

if (!this._foundApps.hasOwnProperty(tab_id)) {
if (!Object.prototype.hasOwnProperty.call(this._foundApps, tab_id)) {
this._foundApps[tab_id] = {
apps: [],
appsMetadata: {},
@@ -445,7 +445,7 @@ class FoundBugs {
* @param {string} type
*/
_updateFoundBugs(tab_id, bug_id, src, blocked, type) {
if (!this._foundBugs[tab_id].hasOwnProperty(bug_id)) {
if (!Object.prototype.hasOwnProperty.call(this._foundBugs[tab_id], bug_id)) {
this._foundBugs[tab_id][bug_id] = {
sources: [],
hasLatencyIssue: false,
@@ -487,7 +487,7 @@ class FoundBugs {
apps, appsMetadata, appsById, issueCounts
} = this._foundApps[tab_id];

if (appsById.hasOwnProperty(aid)) {
if (Object.prototype.hasOwnProperty.call(appsById, aid)) {
const app = apps[appsById[aid]];

if (!app.hasLatencyIssue && hasLatencyIssue) { issueCounts.latency++; }
@@ -33,7 +33,7 @@ class Latency {
const request_id = details.requestId;
const tab_id = details.tabId;

if (!this.latencies.hasOwnProperty(request_id)) {
if (!Object.prototype.hasOwnProperty.call(this.latencies, request_id)) {
return 0;
}
// If the latencies object for this request id is empty then this is
@@ -46,7 +46,7 @@ class Latency {
// TRACKER1 --> NON-TRACKER --> TRACKER2
// TRACKER2's onBeforeRequest sync callback could maybe fire before
// NON-TRACKER's onBeforeRedirect async callback
if (!this.latencies[request_id].hasOwnProperty(details.url)) {
if (!Object.prototype.hasOwnProperty.call(this.latencies[request_id], details.url)) {
return 0;
}

ProTip! Use n and p to navigate between commits in a pull request.