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

Next

add linting for no-param-reassign and fix resulting linting errors

  • Loading branch information
IAmThePan committed Apr 29, 2020
commit 75b00917cde978161b75cc58c5fa205173404577
@@ -56,7 +56,14 @@ module.exports = {
'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 2 }],
'no-mixed-operators': [0],
'no-nested-ternary': [0],
'no-param-reassign': [0], // TODO: enable this check
'no-param-reassign': ['error', {
props: true,
ignorePropertyModificationsFor: [
'acc', // for reduce accumulators
'trackerEl', // for trackers.forEach()
'categoryEl' // for categories.forEach()
]
}],
'no-plusplus': [0],
'no-prototype-builtins': [0], // TODO: enable this check
'no-restricted-syntax': [0], // TODO: enable this check
@@ -40,7 +40,8 @@ const { sendMessage, sendMessageInPromise } = msg;
* but another one, down the chain of redirects - is. It is loaded
* by app/blocked_redirect.html when we navigate browser to it.
*/
(function BlockedRedirectContentScript(window, document) {
(function BlockedRedirectContentScript(window, doc) {
const document = doc;
/**
* Calculate window height.
* @memberof BlockedRedirectContentScript
@@ -59,11 +59,12 @@ const Click2PlayContentScript = (function(win, doc) {
* @memberof Click2PlayContentScript
* @package
*
* @param {Object} c2pFrame iframe DOM element
* @param {Object} c2pFrameEl iframe DOM element
* @param {Object} c2pAppDef replacement data
* @param {string} html a fragment of html to be used in replacement.
*/
const buildC2P = function(c2pFrame, c2pAppDef, html) {
const buildC2P = function(c2pFrameEl, c2pAppDef, html) {
const c2pFrame = c2pFrameEl;
c2pFrame.addEventListener('load', () => {
const idoc = c2pFrame.contentDocument;

@@ -27,7 +27,8 @@ const { sendMessage } = msg;
* Use to call init to initialize functionality
* @var {Object} initialized to an object with init method as its property
*/
const PageInfo = (function(window, document) {
const PageInfo = (function(window, doc) {
const document = doc;
let state = document.readyState;
/**
* Calculate page domain and latency. Send pageInfo to background.js.
@@ -218,30 +218,30 @@ export function blockUnBlockAllTrackers({ actionData, state }) {
const app_ids = [];

if (isSiteTrackers) {
updated_blocking_categories.forEach((category) => {
if (categoryId && category.id !== categoryId) {
updated_blocking_categories.forEach((categoryEl) => {
if (categoryId && categoryEl.id !== categoryId) {
return;
}

const updated_settings_category = updated_settings_categories.find(item => item.id === category.id);
category.num_blocked = 0;
const updated_settings_category = updated_settings_categories.find(item => item.id === categoryEl.id);
categoryEl.num_blocked = 0;
// TODO: change the logic here
category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
tracker.blocked = block;
const key = tracker.id;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
trackerEl.blocked = block;
const key = trackerEl.id;

if (block) {
if (!app_ids.includes(key)) {
app_ids.push(key);
}

tracker.ss_allowed = false;
tracker.ss_blocked = false;
trackerEl.ss_allowed = false;
trackerEl.ss_blocked = false;
}

if (block || tracker.ss_blocked) {
category.num_blocked += 1;
if (block || trackerEl.ss_blocked) {
categoryEl.num_blocked += 1;
updated_app_ids[key] = 1;
} else {
delete updated_app_ids[key];
@@ -258,19 +258,19 @@ export function blockUnBlockAllTrackers({ actionData, state }) {
});
});
} else {
updated_settings_categories.forEach((category) => {
if (categoryId && category.id !== categoryId) {
updated_settings_categories.forEach((categoryEl) => {
if (categoryId && categoryEl.id !== categoryId) {
return;
}

category.num_blocked = 0;
category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
tracker.blocked = block;
const key = tracker.id;
categoryEl.num_blocked = 0;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
trackerEl.blocked = block;
const key = trackerEl.id;

if (block) {
category.num_blocked += 1;
categoryEl.num_blocked += 1;
updated_app_ids[key] = 1;
} else {
delete updated_app_ids[key];
@@ -279,13 +279,13 @@ export function blockUnBlockAllTrackers({ actionData, state }) {
});
});

updated_blocking_categories.forEach((category) => {
category.trackers.forEach((tracker) => {
if (tracker.shouldShow && !tracker.ss_allowed && !tracker.ss_blocked) {
tracker.blocked = block;
updated_blocking_categories.forEach((categoryEl) => {
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow && !trackerEl.ss_allowed && !trackerEl.ss_blocked) {
trackerEl.blocked = block;
}
});
category.num_blocked = category.trackers.filter(tracker => tracker.blocked || tracker.ss_blocked).length;
categoryEl.num_blocked = categoryEl.trackers.filter(trackerEl => trackerEl.blocked || trackerEl.ss_blocked).length;
});
}

@@ -326,24 +326,24 @@ export function resetSettings({ state }) {
const blockingCategories = JSON.parse(JSON.stringify(blocking.categories)) || [];
const settingsCategories = JSON.parse(JSON.stringify(settings.categories)) || [];

blockingCategories.forEach((category) => {
category.num_blocked = 0;
category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
tracker.blocked = false;
tracker.ss_blocked = false;
tracker.ss_allowed = false;
blockingCategories.forEach((categoryEl) => {
categoryEl.num_blocked = 0;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
trackerEl.blocked = false;
trackerEl.ss_blocked = false;
trackerEl.ss_allowed = false;
}
});
});

settingsCategories.forEach((category) => {
category.num_blocked = 0;
category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
tracker.blocked = false;
tracker.ss_blocked = false;
tracker.ss_allowed = false;
settingsCategories.forEach((categoryEl) => {
categoryEl.num_blocked = 0;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
trackerEl.blocked = false;
trackerEl.ss_blocked = false;
trackerEl.ss_allowed = false;
}
});
});
@@ -72,10 +72,9 @@ export function updateGhosteryPaused(data) {
});
if (data.time) {
setTimeout(() => {
data.ghosteryPaused = !data.ghosteryPaused;
dispatch({
type: UPDATE_GHOSTERY_PAUSED,
data
data: { ...data, ghosteryPaused: !data.ghosteryPaused }
});
}, data.time);
}
@@ -95,21 +95,21 @@ class Blocking extends React.Component {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone
const updatedUnknownCategory = JSON.parse(JSON.stringify(this.props.unknownCategory)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
let show = true;

// filter by donut wheel categories
if (filterName !== 'all' && filterName !== category.id) {
if (filterName !== 'all' && filterName !== categoryEl.id) {
show = false;
}

category.trackers.forEach((tracker) => {
tracker.shouldShow = show;
categoryEl.trackers.forEach((trackerEl) => {
trackerEl.shouldShow = show;
count++;
});

category.num_shown = (show) ? count : 0;
categoryEl.num_shown = (show) ? count : 0;
});

updatedUnknownCategory.hide = !(filterName === 'all' || filterName === 'unknown');
@@ -124,18 +124,18 @@ class Blocking extends React.Component {
setBlockedShow() {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
category.trackers.forEach((tracker) => {
const isSbBlocked = this.props.smartBlockActive && tracker.warningSmartBlock;
if ((tracker.blocked && !tracker.ss_allowed) || isSbBlocked || tracker.ss_blocked) {
tracker.shouldShow = true;
categoryEl.trackers.forEach((trackerEl) => {
const isSbBlocked = this.props.smartBlockActive && trackerEl.warningSmartBlock;
if ((trackerEl.blocked && !trackerEl.ss_allowed) || isSbBlocked || trackerEl.ss_blocked) {
trackerEl.shouldShow = true;
count++;
} else {
tracker.shouldShow = false;
trackerEl.shouldShow = false;
}
});
category.num_shown = count;
categoryEl.num_shown = count;
});

this.props.actions.updateCategories(updated_categories);
@@ -148,18 +148,18 @@ class Blocking extends React.Component {
setWarningShow() {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
category.trackers.forEach((tracker) => {
if (tracker.warningCompatibility || tracker.warningInsecure || tracker.warningSlow) {
tracker.shouldShow = true;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.warningCompatibility || trackerEl.warningInsecure || trackerEl.warningSlow) {
trackerEl.shouldShow = true;
count++;
} else {
tracker.shouldShow = false;
trackerEl.shouldShow = false;
}
});

category.num_shown = count;
categoryEl.num_shown = count;
});

this.props.actions.updateCategories(updated_categories);
@@ -172,18 +172,18 @@ class Blocking extends React.Component {
setWarningCompatibilityShow() {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
category.trackers.forEach((tracker) => {
if (tracker.warningCompatibility) {
tracker.shouldShow = true;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.warningCompatibility) {
trackerEl.shouldShow = true;
count++;
} else {
tracker.shouldShow = false;
trackerEl.shouldShow = false;
}
});

category.num_shown = count;
categoryEl.num_shown = count;
});

this.props.actions.updateCategories(updated_categories);
@@ -196,18 +196,18 @@ class Blocking extends React.Component {
setWarningSlowInsecureShow() {
const updated_categories = JSON.parse(JSON.stringify(this.props.categories)); // deep clone

updated_categories.forEach((category) => {
updated_categories.forEach((categoryEl) => {
let count = 0;
category.trackers.forEach((tracker) => {
if (tracker.warningInsecure || tracker.warningSlow) {
tracker.shouldShow = true;
categoryEl.trackers.forEach((trackerEl) => {
if (trackerEl.warningInsecure || trackerEl.warningSlow) {
trackerEl.shouldShow = true;
count++;
} else {
tracker.shouldShow = false;
trackerEl.shouldShow = false;
}
});

category.num_shown = count;
categoryEl.num_shown = count;
});

this.props.actions.updateCategories(updated_categories);
@@ -264,9 +264,11 @@ class DonutGraph extends React.Component {
this._endAngles.set(catId, d.endAngle);

return function(t) {
d.startAngle = lerpStartAngle(t);
d.endAngle = lerpEndAngle(t);
return trackerArc(d);
return trackerArc({
...d,
startAngle: lerpStartAngle(t),
endAngle: lerpEndAngle(t),
});
};
});

@@ -320,8 +322,10 @@ class DonutGraph extends React.Component {

const i = interpolate(d.startAngle, d.endAngle);
return function(t) {
d.endAngle = i(t);
return trackerArc(d);
return trackerArc({
...d,
endAngle: i(t)
});
};
})
.ease(easeLinear);
@@ -79,7 +79,8 @@ class StatsGraph extends React.Component {
}

const data = JSON.parse(JSON.stringify(this.props.data));
data.forEach((entry) => {
data.forEach((e) => {
const entry = e;
entry.date = parseMonth(entry.date);
});

@@ -168,11 +168,11 @@ const _updateTrackerTrustRestrict = (state, action) => {
// update tracker category for site-specific blocking
const updated_category = updated_categories[updated_categories.findIndex(item => item.id === msg.cat_id)];

updated_category.trackers.forEach((tracker) => {
if (tracker.shouldShow) {
if (tracker.id === app_id) {
tracker.ss_allowed = msg.trust;
tracker.ss_blocked = msg.restrict;
updated_category.trackers.forEach((trackerEl) => {
if (trackerEl.shouldShow) {
if (trackerEl.id === app_id) {
trackerEl.ss_allowed = msg.trust;
trackerEl.ss_blocked = msg.restrict;
}
}
});
@@ -242,9 +242,9 @@ const _updateCliqzModuleWhitelist = (state, action) => {
addToWhitelist();
}

updatedUnknownCategory.unknownTrackers.forEach((tracker) => {
if (tracker.name === unknownTracker.name) {
tracker.whitelisted = !tracker.whitelisted;
updatedUnknownCategory.unknownTrackers.forEach((trackerEl) => {
if (trackerEl.name === unknownTracker.name) {
trackerEl.whitelisted = !trackerEl.whitelisted;
}
});

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