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

Code Cleanup: Enforce Linting Rules & Update UNSAFE_ React Lifecycle Events #559

Merged
merged 33 commits into from Jun 4, 2020
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
75b0091
add linting for no-param-reassign and fix resulting linting errors
IAmThePan Apr 29, 2020
8d37082
add linting for prefer-object-spread and fix resulting linting errors
IAmThePan Apr 29, 2020
3049bd1
add linting for no-restricted-syntax and fix 1/2 of resulting errors
IAmThePan May 1, 2020
fe03ad7
add linting for no-prototype-builtins and fix resulting linting errors
IAmThePan May 4, 2020
f11bc18
add linting for class-methods-use-this and fix most resulting errors.…
IAmThePan May 5, 2020
5f3471e
finish linting for class-methods-use-this
IAmThePan May 6, 2020
d4d84dc
add linting for no-mixed-operators and fix resulting linting errors
IAmThePan May 6, 2020
17f90ed
add linting for import/prefer-default-export and fix resulting lintin…
IAmThePan May 8, 2020
a77cd1b
add linting for react/no-access-state-in-setstate and fix resulting l…
IAmThePan May 8, 2020
c31dbaf
add linting for react/jsx-props-no-spreading and fix resulting lintin…
IAmThePan May 11, 2020
3d50aff
finish linting errors for no-restricted-syntax. 1 remains: couldn't r…
IAmThePan May 12, 2020
227d012
Merge branch 'develop' into feature/update-linter
IAmThePan May 12, 2020
0988a29
Fix linting errors resulting from the merge with develop
IAmThePan May 12, 2020
b55be21
Refactor UNSAFE_componentWillMount into either constructor or compone…
IAmThePan May 14, 2020
241747c
Refactor UNSAFE_componentWillReceiveProps to componentDidUpdate or ge…
IAmThePan May 18, 2020
eb413fb
re-enable lint exception for no-prototype-builtins and revert calls b…
IAmThePan May 20, 2020
ac0ec93
add single line exception for no-restricted-syntax linting rule
IAmThePan May 20, 2020
fd954eb
add linting for react/destructuring-assignment and fix errors. ToDo: …
IAmThePan May 21, 2020
e815546
Fix minor bugs
IAmThePan May 22, 2020
ae8ffcc
Fix General Settings last updated text
IAmThePan May 22, 2020
4c56460
rework linting rule no-param-reassign to have more exceptions and par…
IAmThePan May 23, 2020
c5ef663
Remove file and line linting exceptions.
IAmThePan May 26, 2020
3ca2402
re-add linting rule react/sort-comp and fix resulting errors
IAmThePan May 26, 2020
4533fd7
remove added linting exception consistent-return and fix resulting er…
IAmThePan May 26, 2020
590aa60
remove added linting expression no-use-before-define and fix resultin…
IAmThePan May 26, 2020
ecb62e8
Fix linting error
IAmThePan May 26, 2020
f634c1d
fix minor bugs
IAmThePan May 26, 2020
ea51432
Code cleanup: fix PromoModal imports
IAmThePan May 26, 2020
75a88cb
Merge with develop. Fix resulting linting errors
IAmThePan May 26, 2020
68493d2
remove unnecessary hasOwnProperty calls after refactored for...in loops
IAmThePan May 28, 2020
6297062
Fix missing strings bug
IAmThePan May 28, 2020
9b4d16c
Fix last remaining string bug
IAmThePan May 28, 2020
2cb47a1
Merge branch 'develop' into feature/cleanup
IAmThePan Jun 4, 2020
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

re-enable lint exception for no-prototype-builtins and revert calls b…

…ack to hasOwnProperty
  • Loading branch information
IAmThePan committed May 20, 2020
commit eb413fbe5807a2bcaf2e2fa4d47edd5872c0d157
@@ -65,7 +65,7 @@ module.exports = {
]
}],
'no-plusplus': [0],
'no-prototype-builtins': [1],
'no-prototype-builtins': [0],
'no-restricted-syntax': [1],
This conversation was marked as resolved by wlycdgr

This comment has been minimized.

@christophertino

christophertino Jun 4, 2020
Member

Remove 'no-restricted-syntax'

This comment has been minimized.

@IAmThePan

IAmThePan Jun 11, 2020
Author Contributor

updated in feature/cleanup-cleanup as this PR was already merged.

This comment has been minimized.

@wlycdgr

wlycdgr Jun 11, 2020
Member

lgtm in feature/cleanup-cleanup

'no-tabs': [0],
'no-underscore-dangle': [0],
@@ -80,7 +80,7 @@ module.exports = {
'import/prefer-default-export': [1],
This conversation was marked as resolved by wlycdgr

This comment has been minimized.

This comment has been minimized.

@IAmThePan

IAmThePan Jun 11, 2020
Author Contributor

updated in feature/cleanup-cleanup as this PR was already merged.

This comment has been minimized.

@wlycdgr

wlycdgr Jun 11, 2020
Member

lgtm in feature/cleanup-cleanup


// Plugin: React
'react/destructuring-assignment': [0],
'react/destructuring-assignment': [0], // ToDo
'react/static-property-placement': [0],
'react/jsx-curly-newline': [0],
'react/jsx-indent': [1, 'tab'],
@@ -164,7 +164,7 @@ const Click2PlayContentScript = (function(win, doc) {
const messageKeys = Object.keys(message);
for (let i = 0; i < messageKeys.length; i++) {
const app_id = messageKeys[i];
if (Object.prototype.hasOwnProperty.call(message, app_id)) {
if (message.hasOwnProperty(app_id)) {
applyC2P(app_id, message[app_id].data, message[app_id].html);
delete message[app_id];
}
@@ -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 (Object.prototype.hasOwnProperty.call(this.antiTrackingData, category)) {
if (this.antiTrackingData.hasOwnProperty(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 (Object.prototype.hasOwnProperty.call(whitelistedUrls, domain)) {
if (whitelistedUrls.hasOwnProperty(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' && Object.prototype.hasOwnProperty.call(updated_needsReload.changes, 'whitelist')) {
if (msg.updated === 'blacklist' && updated_needsReload.changes.hasOwnProperty('whitelist')) {
delete updated_needsReload.changes.whitelist;
} else if (msg.updated === 'whitelist' && Object.prototype.hasOwnProperty.call(updated_needsReload.changes, 'blacklist')) {
} else if (msg.updated === 'whitelist' && updated_needsReload.changes.hasOwnProperty('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 (Object.prototype.hasOwnProperty.call(updated_needsReload.changes, msg.updated)) {
if (updated_needsReload.changes.hasOwnProperty(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 = Object.prototype.hasOwnProperty.call(smartBlock.blocked, trackerEl.id);
const sbUnblocked = Object.prototype.hasOwnProperty.call(smartBlock.unblocked, trackerEl.id);
const sbBlocked = smartBlock.blocked.hasOwnProperty(trackerEl.id);
const sbUnblocked = smartBlock.unblocked.hasOwnProperty(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 = Object.prototype.hasOwnProperty.call(smartBlock.blocked, trackerEl.id);
const sbUnblocked = Object.prototype.hasOwnProperty.call(smartBlock.unblocked, trackerEl.id);
const sbBlocked = smartBlock.blocked.hasOwnProperty(trackerEl.id);
const sbUnblocked = smartBlock.unblocked.hasOwnProperty(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 = Object.prototype.hasOwnProperty.call(smartBlock.blocked, trackerEl.id);
const sbUnblocked = Object.prototype.hasOwnProperty.call(smartBlock.unblocked, trackerEl.id);
const sbBlocked = smartBlock.blocked.hasOwnProperty(trackerEl.id);
const sbUnblocked = smartBlock.unblocked.hasOwnProperty(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 = Object.prototype.hasOwnProperty.call(smartBlock.blocked, trackerEl.id);
const sbUnblocked = Object.prototype.hasOwnProperty.call(smartBlock.unblocked, trackerEl.id);
const sbBlocked = smartBlock.blocked.hasOwnProperty(trackerEl.id);
const sbUnblocked = smartBlock.unblocked.hasOwnProperty(trackerEl.id);

if (trackerEl.shouldShow) {
if (trackerEl.id === action.data.app_id) {
@@ -129,10 +129,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 (Object.prototype.hasOwnProperty.call(bugDb.db.apps, app_id)) {
if (bugDb.db.apps.hasOwnProperty(app_id)) {
const category = bugDb.db.apps[app_id].cat;
if (categoriesBlock.indexOf(category) >= 0 &&
!Object.prototype.hasOwnProperty.call(selected_app_ids, app_id)) {
!selected_app_ids.hasOwnProperty(app_id)) {
selected_app_ids[app_id] = 1;
}
}
@@ -498,7 +498,7 @@ function handleRewards(name, message, callback) {
metrics.ping(message);
break;
case 'setPanelData':
if (Object.prototype.hasOwnProperty.call(message, 'enable_offers')) {
if (message.hasOwnProperty('enable_offers')) {
Rewards.sendSignal(message.signal);
panelData.set({ enable_offers: message.enable_offers });
}
@@ -580,7 +580,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 (!Object.prototype.hasOwnProperty.call(selected_app_ids, app_id)) {
if (!selected_app_ids.hasOwnProperty(app_id)) {
selected_app_ids[app_id] = 1;
}
}
@@ -776,7 +776,7 @@ function onMessageHandler(request, sender, callback) {
const { email, password } = message;
account.login(email, password)
.then((response) => {
if (!Object.prototype.hasOwnProperty.call(response, 'errors')) {
if (!response.hasOwnProperty('errors')) {
metrics.ping('sign_in_success');
}
callback(response);
@@ -793,7 +793,7 @@ function onMessageHandler(request, sender, callback) {
} = message;
account.register(email, confirmEmail, password, firstName, lastName)
.then((response) => {
if (!Object.prototype.hasOwnProperty.call(response, 'errors')) {
if (!response.hasOwnProperty('errors')) {
metrics.ping('create_account_success');
}
callback(response);
@@ -1013,7 +1013,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) => Object.prototype.hasOwnProperty.call(appIds, app_id)));
db.allSelected = (!!num_selected && every(db.apps, (app, app_id) => appIds.hasOwnProperty(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 Object.prototype.hasOwnProperty.call(this.tests, name);
return this.tests.hasOwnProperty(name);
}

/**
@@ -87,20 +87,20 @@ class BugDb extends Updatable {
const appIds = Object.keys(db.apps);
for (let i = 0; i < appIds.length; i++) {
appId = appIds[i];
if (Object.prototype.hasOwnProperty.call(db.apps, appId)) {
if (db.apps.hasOwnProperty(appId)) {
category = db.apps[appId].cat;
if (t(`category_${category}`) === `category_${category}`) {
category = 'uncategorized';
}
blocked = Object.prototype.hasOwnProperty.call(selectedApps, appId);
blocked = selectedApps.hasOwnProperty(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 (Object.prototype.hasOwnProperty.call(categories, category)) {
if (categories.hasOwnProperty(category)) {
categories[category].num_total++;
if (blocked) {
categories[category].num_blocked++;
@@ -131,7 +131,7 @@ class BugDb extends Updatable {
const categoryNames = Object.keys(categories);
for (let i = 0; i < categoryNames.length; i++) {
categoryName = categoryNames[i];
if (Object.prototype.hasOwnProperty.call(categories, categoryName)) {
if (categories.hasOwnProperty(categoryName)) {
const category = categories[categoryName];
if (category.trackers) {
category.trackers.sort((a, b) => {
@@ -186,7 +186,7 @@ class BugDb extends Updatable {
const regexesKeys = Object.keys(regexes);
for (let i = 0; i < regexesKeys.length; i++) {
const id = regexesKeys[i];
if (Object.prototype.hasOwnProperty.call(regexes, id)) {
if (regexes.hasOwnProperty(id)) {
db.patterns.regex[id] = new RegExp(regexes[id], 'i');
}
}
@@ -199,7 +199,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) => Object.prototype.hasOwnProperty.call(conf.selected_app_ids, app_id)));
return (!!num_selected && every(db.apps, (app, app_id) => conf.selected_app_ids.hasOwnProperty(app_id)));
});

log('processed bugdb...');
@@ -210,7 +210,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 (Object.prototype.hasOwnProperty.call(old_bugs, 'version') && bugs.version > old_bugs.version) {
if (old_bugs.hasOwnProperty('version') && bugs.version > old_bugs.version) {
new_app_ids = BugDb.updateNewAppIds(bugs.apps, old_bugs.apps);

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

// pre-trie/legacy db
} else if (Object.prototype.hasOwnProperty.call(old_bugs, 'bugsVersion') && bugs.version !== old_bugs.bugsVersion) {
} else if (old_bugs.hasOwnProperty('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 (!Object.prototype.hasOwnProperty.call(this.allowOnceList, tab_id)) { return; }
if (!this.allowOnceList.hasOwnProperty(tab_id)) { return; }

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

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

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

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

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

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

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

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

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

if (app_id) {
const { appsById } = this._foundApps[tab_id];
if (Object.prototype.hasOwnProperty.call(appsById, app_id)) {
if (appsById.hasOwnProperty(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 (Object.prototype.hasOwnProperty.call(bugs, id)) {
if (bugs.hasOwnProperty(id)) {
aid = db.bugs[id].aid; // eslint-disable-line prefer-destructuring
cid = db.apps[aid].cat;

if (Object.prototype.hasOwnProperty.call(cats_obj, cid)) {
if (cats_obj.hasOwnProperty(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 (Object.prototype.hasOwnProperty.call(cats_obj, cid)) {
if (cats_obj.hasOwnProperty(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 (Object.prototype.hasOwnProperty.call(appsById, aid)) {
if (appsById.hasOwnProperty(aid)) {
const app = apps[appsById[aid]];
if (!app.hasLatencyIssue) {
issueCounts.latency++;
@@ -395,11 +395,11 @@ class FoundBugs {
return false;
}

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

if (!Object.prototype.hasOwnProperty.call(this._foundApps, tab_id)) {
if (!this._foundApps.hasOwnProperty(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 (!Object.prototype.hasOwnProperty.call(this._foundBugs[tab_id], bug_id)) {
if (!this._foundBugs[tab_id].hasOwnProperty(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 (Object.prototype.hasOwnProperty.call(appsById, aid)) {
if (appsById.hasOwnProperty(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 (!Object.prototype.hasOwnProperty.call(this.latencies, request_id)) {
if (!this.latencies.hasOwnProperty(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 (!Object.prototype.hasOwnProperty.call(this.latencies[request_id], details.url)) {
if (!this.latencies[request_id].hasOwnProperty(details.url)) {
return 0;
}

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