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

add linting for class-methods-use-this and fix most resulting errors.…

… Add /tools and /tests to linter. Update height in UpgradeBanner
  • Loading branch information
IAmThePan committed May 5, 2020
commit f11bc18abacdc12a4250bcbf6c6cc777fa64370d
@@ -40,7 +40,7 @@ module.exports = {
rules: {
'arrow-parens': [2, 'as-needed', { 'requireForBlockBody': true }],
'camelcase': [0],
'class-methods-use-this': [0], // TODO: enable this check
'class-methods-use-this': [1],
This conversation was marked as resolved by wlycdgr

This comment has been minimized.

@christophertino

christophertino Jun 4, 2020
Member

We can remove this line entirely and let the AirBnB defaults pick it up.

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

'comma-dangle': [2, {
'arrays': 'only-multiline',
'objects': 'only-multiline',
@@ -90,7 +90,7 @@ module.exports = {
'react/no-danger': [0],
'react/prop-types': [0],
'react/jsx-fragments': [1, 'element'],
'react/sort-comp': [2, {
'react/sort-comp': [0, { //TODO: enable this check
order: [
"static-variables",
"instance-variables",
@@ -31,7 +31,7 @@ class Licenses extends React.Component {
* Wrapper function for dangerouslySetInnerHTML. Provides extra security
* @return {Object}
*/
createFooterMarkup() {
static createFooterMarkup() {
return { __html: t('license_footer') };
}

@@ -60,7 +60,7 @@ class Licenses extends React.Component {
<div className="license-list">{ list }</div>
</div>
<div id="footer">
<div className="columns copyright text-center" dangerouslySetInnerHTML={this.createFooterMarkup()} />
<div className="columns copyright text-center" dangerouslySetInnerHTML={Licenses.createFooterMarkup()} />
</div>
</div>
);
@@ -20,11 +20,11 @@ export default class FixedMenu extends React.Component {
super(props);
this.state = {
open: false,
currentMenuItemText: this.defaultHeaderText,
currentMenuItemText: FixedMenu.defaultHeaderText,
};
}

get defaultHeaderText() {
static get defaultHeaderText() {
return 'Enhanced Options';
}

@@ -86,7 +86,7 @@ export default class FixedMenu extends React.Component {
}

updateHeadeText = (text) => {
const textToShow = text || this.defaultHeaderText;
const textToShow = text || FixedMenu.defaultHeaderText;

this.setState({
currentMenuItemText: textToShow,
@@ -42,7 +42,7 @@ export default class Path extends React.Component {
this.props.handler();
}

polarToCartesian(centerX, centerY, radius, angleInDegrees) {
static polarToCartesian(centerX, centerY, radius, angleInDegrees) {
const angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;

return {
@@ -51,9 +51,9 @@ export default class Path extends React.Component {
};
}

describeArc(x, y, radius, startAngle, endAngle) {
const start = this.polarToCartesian(x, y, radius, startAngle);
const end = this.polarToCartesian(x, y, radius, endAngle);
static describeArc(x, y, radius, startAngle, endAngle) {
const start = Path.polarToCartesian(x, y, radius, startAngle);
const end = Path.polarToCartesian(x, y, radius, endAngle);

const largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1';

@@ -71,7 +71,7 @@ export default class Path extends React.Component {
// Fix error for single path
const end = path.end === 360 ? 359.9999 : path.end;

const d = this.describeArc(0, 0, radius, start, end);
const d = Path.describeArc(0, 0, radius, start, end);

return (
<path
@@ -242,14 +242,14 @@ class Tracker extends React.Component {
{(oneOrMoreCookies || oneOrMoreFingerprints) && (
<div className="trk-cliqz-stats-container">
{this._renderCliqzCookiesAndFingerprintsIcon()}
{oneOrMoreCookies && this._renderCliqzCookieStat(cliqzCookieCount)}
{oneOrMoreFingerprints && this._renderCliqzFingerprintStat(cliqzFingerprintCount)}
{oneOrMoreCookies && Tracker._renderCliqzCookieStat(cliqzCookieCount)}
{oneOrMoreFingerprints && Tracker._renderCliqzFingerprintStat(cliqzFingerprintCount)}
</div>
)}
{oneOrMoreAds && (
<div className="trk-cliqz-stats-container">
{this._renderCliqzAdsIcon()}
{this._renderCliqzAdStat(cliqzAdCount)}
{Tracker._renderCliqzAdStat(cliqzAdCount)}
</div>
)}
</div>
@@ -275,13 +275,13 @@ class Tracker extends React.Component {
);
}

_renderCliqzCookieStat(count) { return this._renderCliqzStat(count, 'cookie'); }
static _renderCliqzCookieStat(count) { return Tracker._renderCliqzStat(count, 'cookie'); }

_renderCliqzFingerprintStat(count) { return this._renderCliqzStat(count, 'fingerprint'); }
static _renderCliqzFingerprintStat(count) { return Tracker._renderCliqzStat(count, 'fingerprint'); }

_renderCliqzAdStat(count) { return this._renderCliqzStat(count, 'ad'); }
static _renderCliqzAdStat(count) { return Tracker._renderCliqzStat(count, 'ad'); }

_renderCliqzStat(count, type) {
static _renderCliqzStat(count, type) {
const exactlyOne = count === 1;
const label = exactlyOne ?
t(`${type}`) :
@@ -46,15 +46,15 @@ class CliqzFeature extends React.Component {
clickButton({
feature: `enable_${featureType}`,
status: active,
text: this._getAlertText(active, type),
text: CliqzFeature._getAlertText(active, type),
});
}

_getStatus(active) {
static _getStatus(active) {
return active ? t('on') : t('off');
}

_getTooltipBodyText(active, isTooltipBody, type) {
static _getTooltipBodyText(active, isTooltipBody, type) {
if (!isTooltipBody) return false;

if (active) {
@@ -82,7 +82,7 @@ class CliqzFeature extends React.Component {
}
}

_getTooltipHeaderText(isTooltipHeader, type) {
static _getTooltipHeaderText(isTooltipHeader, type) {
if (!isTooltipHeader) return false;

switch (type) {
@@ -97,7 +97,7 @@ class CliqzFeature extends React.Component {
}
}

_getAlertText(active, type) {
static _getAlertText(active, type) {
return active ?
t(`alert_${type}_off`) :
t(`alert_${type}_on`);
@@ -145,11 +145,11 @@ class CliqzFeature extends React.Component {

return (
<div className={cliqzFeatureClassNames} onClick={this.clickCliqzFeature}>
<div className="CliqzFeature__status">{this._getStatus(active)}</div>
<div className="CliqzFeature__status">{CliqzFeature._getStatus(active)}</div>
<div className={iconClassNames}>
<Tooltip
header={this._getTooltipHeaderText(isTooltipHeader, type)}
body={this._getTooltipBodyText(active, isTooltipBody, type)}
header={CliqzFeature._getTooltipHeaderText(isTooltipHeader, type)}
body={CliqzFeature._getTooltipBodyText(active, isTooltipBody, type)}
position={tooltipPosition}
// className={isTiny ? 'CliqzFeature--tooltipUp' : ''}
/>
@@ -142,14 +142,14 @@ class DonutGraph extends React.Component {
/**
* Helper function that calculates domain value for greyscale / redscale rendering
*/
getTone(catCount, catIndex) {
static getTone(catCount, catIndex) {
return catCount > 1 ? 100 / (catCount - 1) * catIndex * 0.01 : 0;
}

/**
* Helper to retrieve a category's tooltip from the DOM
*/
grabTooltip(d) {
static grabTooltip(d) {
return document.getElementById(`${d.data.id}_tooltip`);
}

@@ -278,10 +278,10 @@ class DonutGraph extends React.Component {
.append('path')
.style('fill', (d, i) => {
if (renderGreyscale) {
return this.colors.greyscale(this.getTone(categoryCount, i));
return this.colors.greyscale(DonutGraph.getTone(categoryCount, i));
}
if (renderRedscale) {
return this.colors.redscale(this.getTone(categoryCount, i));
return this.colors.redscale(DonutGraph.getTone(categoryCount, i));
}
return this.colors.regular(d.data.id);
})
@@ -295,15 +295,15 @@ class DonutGraph extends React.Component {
const centroid = trackerArc.centroid(d);
const pX = centroid[0] + this.donutRadius;
const pY = centroid[1] + this.donutRadius;
const tooltip = this.grabTooltip(d);
const tooltip = DonutGraph.grabTooltip(d);
if (tooltip) {
tooltip.style.left = `${pX - (tooltip.offsetWidth / 2)}px`;
tooltip.style.top = `${pY - (tooltip.offsetHeight + 8)}px`;
tooltip.classList.add('DonutGraph__tooltip--show');
}
})
.on('mouseout', (d) => {
const tooltip = this.grabTooltip(d);
const tooltip = DonutGraph.grabTooltip(d);
if (tooltip) {
tooltip.classList.remove('DonutGraph__tooltip--show');
}
@@ -40,7 +40,7 @@ class GhosteryFeature extends React.Component {
this.props.handleClick(this.props.type);
}

_getButtonText(sitePolicy, showText, type) {
static _getButtonText(sitePolicy, showText, type) {
if (!showText) {
return '';
}
@@ -59,7 +59,7 @@ class GhosteryFeature extends React.Component {
}
}

_getTooltipText(sitePolicy, type) {
static _getTooltipText(sitePolicy, type) {
switch (type) {
case 'trust':
return (sitePolicy === WHITELISTED ?
@@ -74,7 +74,7 @@ class GhosteryFeature extends React.Component {
}
}

_isFeatureActive(type, sitePolicy) {
static _isFeatureActive(type, sitePolicy) {
switch (type) {
case 'trust':
return sitePolicy === WHITELISTED;
@@ -96,7 +96,7 @@ class GhosteryFeature extends React.Component {
type
} = this.props;

const active = this._isFeatureActive(type, sitePolicy);
const active = GhosteryFeature._isFeatureActive(type, sitePolicy);
// TODO Foundation dependency: button
const ghosteryFeatureClassNames = ClassNames(
'button',
@@ -120,10 +120,10 @@ class GhosteryFeature extends React.Component {
<div className={ghosteryFeatureClassNames} onClick={this.handleClick}>
<span className="flex-container align-center-middle full-height">
<span className="GhosteryFeatureButton__text">
{this._getButtonText(sitePolicy, showText, type)}
{GhosteryFeature._getButtonText(sitePolicy, showText, type)}
</span>
</span>
<Tooltip body={this._getTooltipText(sitePolicy, type)} position={tooltipPosition} />
<Tooltip body={GhosteryFeature._getTooltipText(sitePolicy, type)} position={tooltipPosition} />
</div>
);
}
@@ -45,7 +45,6 @@ class Rewards extends React.Component {

// helper render functions
this.renderRewardListComponent = this.renderRewardListComponent.bind(this);
this.handleFaqClick = this.handleFaqClick.bind(this);
this.handlePortMessage = this.handlePortMessage.bind(this);


@@ -141,7 +140,7 @@ class Rewards extends React.Component {
/**
* Handles clicking the learn more button
*/
handleFaqClick() {
static handleFaqClick() {
sendMessage('openNewTab', {
url: 'https://www.ghostery.com/faqs/what-new-ghostery-features-can-we-expect-in-the-future/',
become_active: true,
@@ -202,7 +201,7 @@ class Rewards extends React.Component {
* Helper render function for Reward Icon SVG
* @return {JSX} JSX for the Rewards Icon SVG
*/
renderRewardSvg() {
static renderRewardSvg() {
return (
<svg className="RewardsPanel__reward_icon" viewBox="0 0 18 23" width="50" height="50">
<g strokeWidth=".5" fillRule="evenodd">
@@ -212,35 +211,35 @@ class Rewards extends React.Component {
);
}

renderCLIQZtext() {
static renderCLIQZtext() {
return (
<div className="RewardsPanel__info">
{ this.renderRewardSvg() }
{ Rewards.renderRewardSvg() }
<div>{ t('panel_detail_rewards_cliqz_text') }</div>
<hr />
<div
className="RewardsPanel__learn_more button primary hollow"
onClick={this.handleFaqClick}
onClick={Rewards.handleFaqClick}
>
{ t('panel_detail_learn_more') }
</div>
</div>
);
}

renderRewardsTurnoffText() {
static renderRewardsTurnoffText() {
return (
<div className="RewardsPanel__info">
{ this.renderRewardSvg() }
{ Rewards.renderRewardSvg() }
<div>{ t('panel_detail_rewards_off') }</div>
</div>
);
}

renderRewardsNoneFoundText() {
static renderRewardsNoneFoundText() {
return (
<div className="RewardsPanel__info">
{ this.renderRewardSvg() }
{ Rewards.renderRewardSvg() }
<div>{ t('panel_detail_rewards_none_found') }</div>
</div>
);
@@ -251,17 +250,17 @@ class Rewards extends React.Component {
* @return {JSX} JSX for the Rewards Items List
*/
renderRewardListComponent() {
if (IS_CLIQZ) { return this.renderCLIQZtext(); }
if (IS_CLIQZ) { return Rewards.renderCLIQZtext(); }
const { enable_offers, is_expanded } = this.props;
if (!enable_offers) { return this.renderRewardsTurnoffText(); }
if (!enable_offers) { return Rewards.renderRewardsTurnoffText(); }

const {
shouldHideRewards,
iframeWidth,
iframeHeight,
rewardsCount,
} = this.state;
if (shouldHideRewards) { return this.renderRewardsNoneFoundText(); }
if (shouldHideRewards) { return Rewards.renderRewardsNoneFoundText(); }

const src = chrome.runtime.getURL('cliqz/offers-templates/control-center.html?cross-origin');
const text = t(`panel_rewards_view__reward${rewardsCount === 1 ? '' : 's'}`);
@@ -120,7 +120,7 @@ class TrustAndRestrict extends React.Component {

// Check for Validity
if (pageHost.length >= 2083
|| !this.isValidUrlorWildcard(pageHost)) {
|| !TrustAndRestrict.isValidUrlorWildcard(pageHost)) {
this.showWarning(t('white_black_list_error_invalid_url'));
return;
}
@@ -144,7 +144,7 @@ class TrustAndRestrict extends React.Component {
}
}

isValidUrlorWildcard(pageHost) {
static isValidUrlorWildcard(pageHost) {
// Only allow valid host name characters, ':' for port numbers and '*' for wildcards
const isSafePageHost = /^[a-zA-Z0-9-.:*]*$/;
if (!isSafePageHost.test(pageHost)) { return false; }
ProTip! Use n and p to navigate between commits in a pull request.