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

rework linting rule no-param-reassign to have more exceptions and par…

…am object destructuring
  • Loading branch information
IAmThePan committed May 23, 2020
commit 4c564601a0526fd162491755286e79f09c23d1ef
@@ -60,8 +60,15 @@ module.exports = {
props: true,
ignorePropertyModificationsFor: [
'acc', // for reduce accumulators
'document', // for IIFE with window & document params
'c2pFrame', // for mutable iframe c2p element
'trackerEl', // for trackers.forEach()
'categoryEl' // for categories.forEach()
'categoryEl', // for categories.forEach()
'dataEntry', // for data.forEach()
'appEntry', // for apps.forEach()
'sEntry', // for apps.forEach()
'confMutable', // for mutable conf settings
'eventMutable' // for mutable event details objects
]
}],
'no-plusplus': [0],
@@ -40,8 +40,7 @@ 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, doc) {
const document = doc;
(function BlockedRedirectContentScript(window, document) {
/**
* Calculate window height.
* @memberof BlockedRedirectContentScript
@@ -57,12 +57,11 @@ const Click2PlayContentScript = (function(win, doc) {
* @memberof Click2PlayContentScript
* @package
*
* @param {Object} c2pFrameEl iframe DOM element
* @param {Object} c2pFrame iframe DOM element
* @param {Object} c2pAppDef replacement data
* @param {string} html a fragment of html to be used in replacement.
*/
const buildC2P = function(c2pFrameEl, c2pAppDef, html) {
const c2pFrame = c2pFrameEl;
const buildC2P = function(c2pFrame, c2pAppDef, html) {
c2pFrame.addEventListener('load', () => {
const idoc = c2pFrame.contentDocument;
idoc.documentElement.innerHTML = html;
@@ -81,9 +81,8 @@ class StatsGraph extends React.Component {
}

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

let tickAmount;
@@ -523,22 +523,22 @@ class Account {
*
* @return {Promise} user settings json or error
*/
_setConfUserSettings = (s) => {
const settings = s;
log('SET USER SETTINGS', settings);
_setConfUserSettings = (settings) => {
const returnedSettings = { ...settings };
log('SET USER SETTINGS', returnedSettings);
if (IS_CLIQZ) {
settings.enable_human_web = false;
settings.enable_offers = false;
settings.enable_ad_block = false;
settings.enable_anti_tracking = false;
returnedSettings.enable_human_web = false;
returnedSettings.enable_offers = false;
returnedSettings.enable_ad_block = false;
returnedSettings.enable_anti_tracking = false;
}
SYNC_SET.forEach((key) => {
if (settings[key] !== undefined &&
!isEqual(conf[key], settings[key])) {
conf[key] = settings[key];
if (returnedSettings[key] !== undefined &&
!isEqual(conf[key], returnedSettings[key])) {
conf[key] = returnedSettings[key];
}
});
return settings;
return returnedSettings;
}

_removeCookies = () => {
@@ -52,15 +52,14 @@ class CMP {
return getJson(URL).then((data) => {
if (data && (!conf.cmp_version || data.Version > conf.cmp_version)) {
// set default dismiss
data.Campaigns.forEach((c) => {
const campaign = c;
if (campaign.Dismiss === 0) {
campaign.Dismiss = 10;
data.Campaigns.forEach((dataEntry) => {
if (dataEntry.Dismiss === 0) {
dataEntry.Dismiss = 10;
}

// set last campaign run timestamp to avoid running campaigns more than once
if (!conf.last_cmp_date || conf.last_cmp_date < campaign.Timestamp) {
conf.last_cmp_date = campaign.Timestamp;
// set last campaign (dataEntry) run timestamp to avoid running campaigns more than once
if (!conf.last_cmp_date || conf.last_cmp_date < dataEntry.Timestamp) {
conf.last_cmp_date = dataEntry.Timestamp;
}
});
// update Conf and local CMP_DATA
@@ -48,7 +48,7 @@ class ConfData {
*/
init() {
return prefsGet().then((d) => {
const data = d;
const data = { ...d };
const nowTime = Number(new Date().getTime());
const _initProperty = (name, value) => {
if (data[name] === null || typeof (data[name]) === 'undefined') {
@@ -328,13 +328,12 @@ class EventHandlers {
* + Speed this up by making it asynchronous when blocking is disabled?
* + Also speed it up for blocking-whitelisted pages (by delaying isBug scanning)?
*
* @param {Object} d event data
* @return {Object} optionaly return {cancel: true} to force dropping the request
* @param {Object} eventMutable event data
* @return {Object} optionaly return {cancel: true} to force dropping the request
*/
onBeforeRequest(d) {
const details = d;
const tab_id = details.tabId;
const request_id = details.requestId;
onBeforeRequest(eventMutable) {
const tab_id = eventMutable.tabId;
const request_id = eventMutable.requestId;

// -1 indicates the request isn't related to a tab
if (tab_id <= 0) {
@@ -345,8 +344,8 @@ class EventHandlers {
log(`tabInfo not found for tab ${tab_id}, initializing...`);

// create new tabInfo entry
if (details.type === 'main_frame') {
tabInfo.create(tab_id, details.url);
if (eventMutable.type === 'main_frame') {
tabInfo.create(tab_id, eventMutable.url);
} else {
tabInfo.create(tab_id);
}
@@ -362,24 +361,24 @@ class EventHandlers {
});
}

if (!EventHandlers._checkRedirect(details.type, request_id)) {
if (!EventHandlers._checkRedirect(eventMutable.type, request_id)) {
return { cancel: false };
}

const page_protocol = tabInfo.getTabInfo(tab_id, 'protocol');
const from_redirect = globals.REDIRECT_MAP.has(request_id);
const processed = utils.processUrl(details.url);
const processed = utils.processUrl(eventMutable.url);

/* ** SMART BLOCKING - Privacy ** */
// block HTTP request on HTTPS page
if (PolicySmartBlock.isInsecureRequest(tab_id, page_protocol, processed.scheme, processed.hostname)) {
return EventHandlers._blockHelper(details, tab_id, null, null, request_id, from_redirect, true);
return EventHandlers._blockHelper(eventMutable, tab_id, null, null, request_id, from_redirect, true);
}

// TODO fuse this into a single call to improve performance
const page_url = tabInfo.getTabInfo(tab_id, 'url');
const page_domain = tabInfo.getTabInfo(tab_id, 'domain');
const bug_id = (page_url ? isBug(details.url, page_url) : isBug(details.url));
const bug_id = (page_url ? isBug(eventMutable.url, page_url) : isBug(eventMutable.url));

// allow if not a tracker
if (!bug_id) {
@@ -388,8 +387,8 @@ class EventHandlers {
this._throttleButtonUpdate();
return { cancel: false };
}
// add the bugId to the details object. This can then be read by other handlers on this pipeline.
details.ghosteryBug = bug_id;
// add the bugId to the eventMutable object. This can then be read by other handlers on this pipeline.
eventMutable.ghosteryBug = bug_id;

/* ** SMART BLOCKING - Breakage ** */
// allow first party trackers
@@ -405,43 +404,43 @@ class EventHandlers {
const { block, reason } = EventHandlers._checkBlocking(app_id, cat_id, tab_id, tab_host, page_url, request_id);
if (!block && reason === BLOCK_REASON_SS_UNBLOCKED) {
// The way to pass this flag to Cliqz handlers
details.ghosteryWhitelisted = true;
eventMutable.ghosteryWhitelisted = true;
}
// Latency initialization needs to be synchronous to avoid race condition with onCompleted, etc.
// TODO can URLs repeat within a redirect chain? what are the cases of repeating URLs (trackers only, ...)?
if (block === false) {
// Store latency data keyed by URL so that we don't use the wrong latencies in a redirect chain.
latency.latencies[request_id] = latency.latencies[request_id] || {};

latency.latencies[request_id][details.url] = {
start_time: Math.round(details.timeStamp),
latency.latencies[request_id][eventMutable.url] = {
start_time: Math.round(eventMutable.timeStamp),
bug_id,
// these could be undefined
page_url,
incognito
};
}

const smartBlocked = !block ? this.policySmartBlock.shouldBlock(app_id, cat_id, tab_id, page_url, details.type, details.timeStamp) : false;
const smartUnblocked = block ? this.policySmartBlock.shouldUnblock(app_id, cat_id, tab_id, page_url, details.type) : false;
const smartBlocked = !block ? this.policySmartBlock.shouldBlock(app_id, cat_id, tab_id, page_url, eventMutable.type, eventMutable.timeStamp) : false;
const smartUnblocked = block ? this.policySmartBlock.shouldUnblock(app_id, cat_id, tab_id, page_url, eventMutable.type) : false;

// process the tracker asynchronously
// very important to block request processing as little as necessary
setTimeout(() => {
this._processBug({
bug_id,
app_id,
type: details.type,
url: details.url,
type: eventMutable.type,
url: eventMutable.url,
block,
smartBlocked,
tab_id,
from_frame: details.parentFrameId !== -1
from_frame: eventMutable.parentFrameId !== -1
});
}, 1);

if ((block && !smartUnblocked) || smartBlocked) {
return EventHandlers._blockHelper(details, tab_id, app_id, bug_id, request_id, fromRedirect);
return EventHandlers._blockHelper(eventMutable, tab_id, app_id, bug_id, request_id, fromRedirect);
}

return { cancel: false };
@@ -455,7 +454,7 @@ class EventHandlers {
* @return {Object} optionally return headers to send
*/
static onBeforeSendHeaders(d) {
const details = d;
const details = { ...d };
for (let i = 0; i < details.requestHeaders.length; ++i) {
// Fetch requests in Firefox web-extension has a flaw. They attach
// origin: moz-extension//ID , which is specific to a user.
@@ -67,7 +67,7 @@ export default class KordInjector {

_createModuleWrapper(moduleName) {
return new Spanan((m) => {
const message = m;
const message = { ...m };
message.moduleName = moduleName;
ExtMessenger.sendMessage(this.extensionId, message);
});
@@ -424,12 +424,11 @@ class FoundBugs {
*/
_checkForCompatibilityIssues(tab_id, tab_url) {
const { apps, appsMetadata, issueCounts } = this._foundApps[tab_id];
apps.forEach((a) => {
const app = a;
const { id } = app;
apps.forEach((appEntry) => {
const { id } = appEntry;
if (appsMetadata[id].needsCompatibilityCheck) {
app.hasCompatibilityIssue = app.blocked ? compDb.hasIssue(id, tab_url) : false;
if (app.hasCompatibilityIssue) { issueCounts.compatibility++; }
appEntry.hasCompatibilityIssue = appEntry.blocked ? compDb.hasIssue(id, tab_url) : false;
if (appEntry.hasCompatibilityIssue) { issueCounts.compatibility++; }
appsMetadata[id].needsCompatibilityCheck = false;
}
});
@@ -576,7 +576,7 @@ class PanelData {
* @param {Object} d
*/
set(d) {
const data = d;
const data = { ...d };
let syncSetDataChanged = false;

if (IS_CLIQZ) {
@@ -58,7 +58,7 @@ class SurrogateDb extends Updatable {
log('processing surrogates...');

data.mappings.forEach((souragate) => {
This conversation was marked as resolved by wlycdgr

This comment has been minimized.

@wlycdgr

wlycdgr Jun 11, 2020
Member

Heh, heh

6a6140bdeec3de18

This comment has been minimized.

@wlycdgr

wlycdgr Jun 15, 2020
Member

Heh, heh

const s = souragate;
const s = { ...souragate };
s.code = data.surrogates[s.sid];

// convert single values to arrays first
@@ -34,11 +34,10 @@ function _promiseTimeout(timeout) {
* @private
*
* @param {Object} cliqz
* @param {Object} c conf
* @param {Object} confMutable conf
* @return {Promise}
*/
function _runCliqzSettingsImport(cliqz, c) {
const conf = c;
function _runCliqzSettingsImport(cliqz, confMutable) {
log('CliqzSettingsImport: Run Cliqz settings importer');
const inject = new KordInjector();
inject.init();
@@ -68,17 +67,17 @@ function _runCliqzSettingsImport(cliqz, c) {
});

// import site whitelists
const existingSites = new Set(conf.site_whitelist);
const existingSites = new Set(confMutable.site_whitelist);
const newSites = new Set(modules.map(mod => result[mod].whitelistedSites)
.reduce((lst, val) => lst.concat(val), [])
.map(s => s.replace(/^(http[s]?:\/\/)?(www\.)?/, ''))
.filter(s => !existingSites.has(s)));
log('CliqzSettingsImport: add whitelisted sites', [...newSites]);
const whitelist = conf.site_whitelist;
const whitelist = confMutable.site_whitelist;
newSites.forEach((s) => {
whitelist.push(s);
});
conf.site_whitelist = whitelist;
confMutable.site_whitelist = whitelist;
privacyMigration.cleanModuleData();
return Promise.resolve();
}).then(() => {
@@ -91,15 +90,14 @@ function _runCliqzSettingsImport(cliqz, c) {
* @memberOf BackgroundUtils
*
* @param {Object} cliqz
* @param {Object} c conf
* @param {Object} confMutable conf
*/
export default function importCliqzSettings(cliqz, c) {
const conf = c;
log('checking cliqz import', conf.cliqz_import_state);
if (!conf.cliqz_import_state) {
_runCliqzSettingsImport(cliqz, conf).then(() => {
export default function importCliqzSettings(cliqz, confMutable) {
log('checking cliqz import', confMutable.cliqz_import_state);
if (!confMutable.cliqz_import_state) {
_runCliqzSettingsImport(cliqz, confMutable).then(() => {
log('CliqzSettingsImport: cliqz settings import successful');
conf.cliqz_import_state = 1;
confMutable.cliqz_import_state = 1;
}, (e) => {
log('CliqzSettingsImport: cliqz import not available at present', e);
});
ProTip! Use n and p to navigate between commits in a pull request.