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 react/destructuring-assignment and fix errors. ToDo: …

…test code and check for errors
  • Loading branch information
IAmThePan committed May 21, 2020
commit fd954ebbdd321f7642a9cd9f90d6887b5fc4f9d8
@@ -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], // ToDo
'react/destructuring-assignment': [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

'react/static-property-placement': [0],
'react/jsx-curly-newline': [0],
'react/jsx-indent': [1, 'tab'],
@@ -31,7 +31,8 @@ class AppView extends Component {
* Lifecycle Event
*/
componentDidUpdate(prevProps) {
if (prevProps.children !== this.props.children) {
const { children } = this.props;
if (prevProps.children !== children) {
this.mainContent.current.scrollTop = 0;
}
}
@@ -25,7 +25,8 @@ class AppViewContainer extends Component {
* Handle clicking to exit the Toast Message.
*/
_exitToast = () => {
this.props.actions.setToast({
const { actions } = this.props;
actions.setToast({
toastMessage: '',
toastClass: '',
});
@@ -45,7 +45,8 @@ class CreateAccountViewContainer extends Component {
validateInput: false,
};

this.props.actions.setToast({
const { actions } = this.props;
actions.setToast({
toastMessage: '',
toastClass: '',
});
@@ -59,7 +60,8 @@ class CreateAccountViewContainer extends Component {
const { name, value } = event.target;
this.setState({ [name]: value });

if (!this.state.validateInput) {
const { validateInput } = this.state;
if (!validateInput) {
return;
}

@@ -132,20 +134,21 @@ class CreateAccountViewContainer extends Component {
if (!emailIsValid || !confirmIsValid || !legalConsentChecked || !passwordIsValid) {
return;
}
this.props.actions.setToast({
const { actions, history } = this.props;
actions.setToast({
toastMessage: '',
toastClass: ''
});
this.props.actions.register(email, confirmEmail, firstName, lastName, password).then((success) => {
actions.register(email, confirmEmail, firstName, lastName, password).then((success) => {
if (success) {
this.props.actions.getUser();
this.props.actions.setToast({
actions.getUser();
actions.setToast({
toastMessage: t('hub_create_account_toast_success'),
toastClass: 'success'
});
this.props.history.push('/');
history.push('/');
} else {
this.props.actions.setToast({
actions.setToast({
toastMessage: t('hub_create_account_toast_error'),
toastClass: 'alert'
});
@@ -56,8 +56,9 @@ class HomeViewContainer extends Component {
* Function to handle toggling Metrics Opt-In
*/
_handleToggleMetrics = () => {
const enable_metrics = !this.props.home.enable_metrics;
this.props.actions.setMetrics({ enable_metrics });
const { actions, home } = this.props;
const enable_metrics = !home.enable_metrics;
actions.setMetrics({ enable_metrics });
}

/**
@@ -68,7 +69,8 @@ class HomeViewContainer extends Component {
_handlePremiumPromoModalClick = (type = 'basic') => {
// GH-1777
// we want to show the promo modal exactly once per Hub visit
this.props.actions.markPremiumPromoModalShown();
const { actions } = this.props;
actions.markPremiumPromoModalShown();

sendMessage('SET_PREMIUM_PROMO_MODAL_SEEN', {});

@@ -32,7 +32,8 @@ class LogInViewContainer extends Component {
validateInput: false,
};

this.props.actions.setToast({
const { actions } = this.props;
actions.setToast({
toastMessage: '',
toastClass: '',
});
@@ -46,7 +47,8 @@ class LogInViewContainer extends Component {
const { name, value } = event.target;
this.setState({ [name]: value });

if (!this.state.validateInput) {
const { validateInput } = this.state;
if (!validateInput) {
return;
}

@@ -87,28 +89,29 @@ class LogInViewContainer extends Component {
return;
}

this.props.actions.setToast({
const { actions, history } = this.props;
actions.setToast({
toastMessage: '',
toastClass: ''
});
this.props.actions.login(email, password).then((success) => {
actions.login(email, password).then((success) => {
if (success) {
const { origin, pathname, hash } = window.location;
window.history.pushState({}, '', `${origin}${pathname}${hash}`);

this.props.actions.getUser();
this.props.actions.getUserSettings()
actions.getUser();
actions.getUserSettings()
.then((settings) => {
const { current_theme } = settings;
return this.props.actions.getTheme(current_theme);
return actions.getTheme(current_theme);
});
this.props.actions.setToast({
actions.setToast({
toastMessage: t('hub_login_toast_success'),
toastClass: 'success'
});
this.props.history.push('/');
history.push('/');
} else {
this.props.actions.setToast({
actions.setToast({
toastMessage: t('no_such_email_password_combo'),
toastClass: 'alert'
});
@@ -35,17 +35,19 @@ class PlusViewContainer extends Component {
* Sends the necessary ping to background
*/
_sendPlusPing = () => {
this.props.actions.sendPing({ type: 'plus_cta_hub' });
const { actions } = this.props;
actions.sendPing({ type: 'plus_cta_hub' });
}

/**
* React's required render function. Returns JSX
* @return {JSX} JSX for rendering the Plus View of the Hub app
*/
render() {
const { user } = this.props;
return (
<PlusView
isPlus={(this.props.user && this.props.user.subscriptionsPlus) || false}
isPlus={(user && user.subscriptionsPlus) || false}
onPlusClick={this._sendPlusPing}
/>
);
@@ -20,7 +20,7 @@ import PropTypes from 'prop-types';
* @return {JSX} JSX for rendering the Products View
* @memberof HubComponents
*/
const ProductsView = props => (
const ProductsView = ({ onAndroidClick, onIosClick, onLiteClick }) => (
<div className="ProductsView">
<div className="ProductsView--rowPaddingTop row small-up-1 large-up-2 align-center-middle">
<div className="columns text-center">
@@ -44,13 +44,13 @@ const ProductsView = props => (
{t('hub_products_main_promo_description')}
</div>
<div className="ProductsView__storeImageContainer">
<a href="https://itunes.apple.com/us/app/ghostery-privacy-browser/id472789016?mt=8" onClick={props.onIosClick} target="_blank" rel="noopener noreferrer">
<a href="https://itunes.apple.com/us/app/ghostery-privacy-browser/id472789016?mt=8" onClick={onIosClick} target="_blank" rel="noopener noreferrer">
<img
className="ProductsView__imageAppStoreIos"
src="/app/images/hub/products/app_store_badge_us.svg"
/>
</a>
<a href="https://play.google.com/store/apps/details?id=com.ghostery.android.ghostery" onClick={props.onAndroidClick} target="_blank" rel="noopener noreferrer">
<a href="https://play.google.com/store/apps/details?id=com.ghostery.android.ghostery" onClick={onAndroidClick} target="_blank" rel="noopener noreferrer">
<img
className="ProductsView__imagePlayStore"
src="/app/images/hub/products/google-play-badge.png"
@@ -86,7 +86,7 @@ const ProductsView = props => (
{t('hub_products_third_promo_description')}
</div>
<div className="ProductsView__storeImageContainer">
<a href="https://itunes.apple.com/us/app/ghostery-lite/id1436953057" onClick={props.onLiteClick} target="_blank" rel="noopener noreferrer">
<a href="https://itunes.apple.com/us/app/ghostery-lite/id1436953057" onClick={onLiteClick} target="_blank" rel="noopener noreferrer">
<img
className="ProductsView__imageAppStoreMac"
src="/app/images/hub/products/app_store_mac_badge_us.svg"
@@ -34,11 +34,12 @@ class ProductsViewContainer extends Component {
* @return {JSX} JSX for rendering the Products View of the Hub app
*/
render() {
const { actions } = this.props;
return (
<ProductsView
onAndroidClick={() => { this.props.actions.sendPing({ type: 'products_cta_android' }); }}
onIosClick={() => { this.props.actions.sendPing({ type: 'products_cta_ios' }); }}
onLiteClick={() => { this.props.actions.sendPing({ type: 'products_cta_lite' }); }}
onAndroidClick={() => { actions.sendPing({ type: 'products_cta_android' }); }}
onIosClick={() => { actions.sendPing({ type: 'products_cta_ios' }); }}
onLiteClick={() => { actions.sendPing({ type: 'products_cta_lite' }); }}
/>
);
}
@@ -42,16 +42,19 @@ class SetupViewContainer extends Component {
sendMountActions: false,
showModal: false,
};

const { history } = this.props;
if (!props.preventRedirect) {
this.props.history.push('/setup/1');
history.push('/setup/1');
}

const title = t('hub_setup_page_title');
window.document.title = title;

this.props.actions.setSetupStep({ setup_step: 7 });
this.props.actions.initSetupProps(this.props.setup);
this.props.actions.getSetupShowWarningOverride().then((data) => {
const { actions, setup } = this.props;
actions.setSetupStep({ setup_step: 7 });
actions.initSetupProps(setup);
actions.getSetupShowWarningOverride().then((data) => {
const { setup_show_warning_override } = data;
const { justInstalled } = QueryString.parse(window.location.search);
const { user } = props;
@@ -88,8 +91,9 @@ class SetupViewContainer extends Component {
* Function to toggle the Ask Again Checkbox
*/
_toggleCheckbox = () => {
const { setup_show_warning_override } = this.props.setup;
this.props.actions.setSetupShowWarningOverride({
const { actions, setup } = this.props;
const { setup_show_warning_override } = setup;
actions.setSetupShowWarningOverride({
setup_show_warning_override: !setup_show_warning_override,
});
}
@@ -99,21 +103,23 @@ class SetupViewContainer extends Component {
*/
_setDefaultSettings() {
this.setState({ sendMountActions: true });
this.props.actions.setSetupStep({ setup_step: 8 });
this.props.actions.setBlockingPolicy({ blockingPolicy: BLOCKING_POLICY_RECOMMENDED });
this.props.actions.setAntiTracking({ enable_anti_tracking: true });
this.props.actions.setAdBlock({ enable_ad_block: true });
this.props.actions.setSmartBlocking({ enable_smart_block: true });
this.props.actions.setGhosteryRewards({ enable_ghostery_rewards: !IS_FIREFOX });
this.props.actions.setHumanWeb({ enable_human_web: !IS_FIREFOX });
const { actions } = this.props;
actions.setSetupStep({ setup_step: 8 });
actions.setBlockingPolicy({ blockingPolicy: BLOCKING_POLICY_RECOMMENDED });
actions.setAntiTracking({ enable_anti_tracking: true });
actions.setAdBlock({ enable_ad_block: true });
actions.setSmartBlocking({ enable_smart_block: true });
actions.setGhosteryRewards({ enable_ghostery_rewards: !IS_FIREFOX });
actions.setHumanWeb({ enable_human_web: !IS_FIREFOX });
}

/**
* Helper render function for rendering the Modal's Children
* @return {JSX} JSX of the Setup Modal's Children
*/
_renderModalChildren() {
const { setup_show_warning_override } = this.props.setup;
const { setup } = this.props;
const { setup_show_warning_override } = setup;

return (
<div className="SetupModal__content flex-container flex-dir-column align-middle">
@@ -21,10 +21,10 @@ import { ToggleSwitch } from '../../../../shared-components';
* @return {JSX} JSX for rendering the Setup Anti-Suite View of the Hub app
* @memberof HubComponents
*/
const SetupAntiSuiteView = props => (
const SetupAntiSuiteView = ({ features }) => (
<div className="row align-center">
<div className="columns small-12 medium-10 large-8">
{props.features.map((feature) => {
{features.map((feature) => {
const iconClassNames = ClassNames(feature.id, {
SetupAntiSuite__icon: true,
active: feature.enabled,
@@ -62,25 +62,26 @@ class SetupAntiSuiteViewContainer extends Component {
* @param {Object} featureName the name of the feature being toggled
*/
_handleToggle = (featureName) => {
const { actions, setup } = this.props;
switch (featureName) {
case 'anti-tracking': {
const enable_anti_tracking = !this.props.setup.enable_anti_tracking;
this.props.actions.setAntiTracking({ enable_anti_tracking });
const enable_anti_tracking = !setup.enable_anti_tracking;
actions.setAntiTracking({ enable_anti_tracking });
break;
}
case 'ad-block': {
const enable_ad_block = !this.props.setup.enable_ad_block;
this.props.actions.setAdBlock({ enable_ad_block });
const enable_ad_block = !setup.enable_ad_block;
actions.setAdBlock({ enable_ad_block });
break;
}
case 'smart-blocking': {
const enable_smart_block = !this.props.setup.enable_smart_block;
this.props.actions.setSmartBlocking({ enable_smart_block });
const enable_smart_block = !setup.enable_smart_block;
actions.setSmartBlocking({ enable_smart_block });
break;
}
case 'ghostery-rewards': {
const enable_ghostery_rewards = !this.props.setup.enable_ghostery_rewards;
this.props.actions.setGhosteryRewards({ enable_ghostery_rewards });
const enable_ghostery_rewards = !setup.enable_ghostery_rewards;
actions.setGhosteryRewards({ enable_ghostery_rewards });
break;
}
default: break;
@@ -92,12 +93,13 @@ class SetupAntiSuiteViewContainer extends Component {
* @return {JSX} JSX for rendering the Setup Anti-Suite View of the Hub app
*/
render() {
const { setup } = this.props;
const {
enable_anti_tracking,
enable_ad_block,
enable_smart_block,
enable_ghostery_rewards,
} = this.props.setup;
} = setup;

const anti_tracking_enabled = IS_CLIQZ ? false : enable_anti_tracking;
const ad_block_enabled = IS_CLIQZ ? false : enable_ad_block;
@@ -35,17 +35,19 @@ class SetupBlockingDropdownContainer extends Component {
* Function to handle navigating back to the Blocking route
*/
_closeModal = () => {
this.props.history.push('/setup/1');
const { history } = this.props;
history.push('/setup/1');
}

/**
* React's required render function. Returns JSX
* @return {JSX} JSX for rendering the Blocking Dropdown
*/
render() {
const { actions } = this.props;
return (
<Modal show toggle={this._closeModal}>
<SetupBlockingDropdown settingsData={this.props} actions={this.props.actions} handleDoneClick={this._closeModal} />
<SetupBlockingDropdown settingsData={this.props} actions={actions} handleDoneClick={this._closeModal} />
</Modal>
);
}
ProTip! Use n and p to navigate between commits in a pull request.