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

Remove unwanted single returns from arrow functions #12127

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = {
'default-param-last': 'off',
'prefer-object-spread': 'error',
'require-atomic-updates': 'off',
'arrow-body-style': 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use strings instead of numbers here? We've been trying to avoid using numbers so we don't have to remember what they mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried 'error' but for some reason the linting bombed, requesting a number. I'll look into it, it was weird.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: We can't have nice things: MetaMask/eslint-config#205 (comment)


// This is the same as our default config, but for the noted exceptions
'spaced-comment': [
Expand Down
19 changes: 6 additions & 13 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,8 @@ function setupController(initState, initLangCode) {
// platform specific api
platform,
extension,
getRequestAccountTabIds: () => {
return requestAccountTabIds;
},
getOpenMetamaskTabsIds: () => {
return openMetamaskTabsIDs;
},
getRequestAccountTabIds: () => requestAccountTabIds,
getOpenMetamaskTabsIds: () => openMetamaskTabsIDs,
});

setupEnsIpfsResolver({
Expand Down Expand Up @@ -291,13 +287,10 @@ function setupController(initState, initLangCode) {

const metamaskBlockedPorts = ['trezor-connect'];

const isClientOpenStatus = () => {
return (
popupIsOpen ||
Boolean(Object.keys(openMetamaskTabsIDs).length) ||
notificationIsOpen
);
};
const isClientOpenStatus = () =>
popupIsOpen ||
Boolean(Object.keys(openMetamaskTabsIDs).length) ||
notificationIsOpen;

const onCloseEnvironmentInstances = (isClientOpen, environmentType) => {
// if all instances of metamask are closed we call a method on the controller to stop gasFeeController polling
Expand Down
18 changes: 8 additions & 10 deletions app/scripts/controllers/detect-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export default class DetectTokensController {
this.keyringMemStore = keyringMemStore;
this.tokenList = tokenList;
this.selectedAddress = this.preferences?.store.getState().selectedAddress;
this.tokenAddresses = this.tokensController?.state.tokens.map((token) => {
return token.address;
});
this.tokenAddresses = this.tokensController?.state.tokens.map(
(token) => token.address,
);
this.hiddenTokens = this.tokensController?.state.ignoredTokens;

preferences?.store.subscribe(({ selectedAddress, useTokenDetection }) => {
Expand All @@ -49,9 +49,7 @@ export default class DetectTokensController {
}
});
tokensController?.subscribe(({ tokens = [], ignoredTokens = [] }) => {
this.tokenAddresses = tokens.map((token) => {
return token.address;
});
this.tokenAddresses = tokens.map((token) => token.address);
this.hiddenTokens = ignoredTokens;
});
}
Expand Down Expand Up @@ -119,13 +117,13 @@ export default class DetectTokensController {
});

await Promise.all(
tokensWithBalance.map((tokenAddress) => {
return this.tokensController.addToken(
tokensWithBalance.map((tokenAddress) =>
this.tokensController.addToken(
tokenAddress,
tokenList[tokenAddress].symbol,
tokenList[tokenAddress].decimals,
);
}),
),
),
);
}
}
Expand Down
5 changes: 2 additions & 3 deletions app/scripts/controllers/network/createJsonRpcClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { SECOND } from '../../../../shared/constants/time';

const inTest = process.env.IN_TEST === 'true';
const blockTrackerOpts = inTest ? { pollingInterval: SECOND } : {};
const getTestMiddlewares = () => {
return inTest ? [createEstimateGasDelayTestMiddleware()] : [];
};
const getTestMiddlewares = () =>
inTest ? [createEstimateGasDelayTestMiddleware()] : [];

export default function createJsonRpcClient({ rpcUrl, chainId }) {
const fetchMiddleware = createFetchMiddleware({ rpcUrl });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@ const {
EXTRA_ACCOUNT,
} = constants;

const initNotifications = () => {
return Object.values(DOMAINS).reduce((acc, domain) => {
const initNotifications = () =>
Object.values(DOMAINS).reduce((acc, domain) => {
acc[domain.origin] = [];
return acc;
}, {});
};

const initPermController = (notifications = initNotifications()) => {
return new PermissionsController({
const initPermController = (notifications = initNotifications()) =>
new PermissionsController({
...getPermControllerOpts(),
notifyDomain: getNotifyDomain(notifications),
notifyAllDomains: getNotifyAllDomains(notifications),
});
};

describe('permissions controller', function () {
describe('constructor', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ const {

let clock;

const initPermLog = () => {
return new PermissionsLogController({
const initPermLog = () =>
new PermissionsLogController({
store: new ObservableStore(),
restrictedMethods: RESTRICTED_METHODS,
});
};

const mockNext = (handler) => {
if (handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ const { CAVEATS, ERRORS, PERMS, RPC_REQUESTS } = getters;

const { ACCOUNTS, DOMAINS, PERM_NAMES } = constants;

const initPermController = () => {
return new PermissionsController({
const initPermController = () =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like in cases like this, the braces can help with readability.

new PermissionsController({
...getPermControllerOpts(),
});
};

const createApprovalSpies = (permController) => {
sinon.spy(permController.approvals, '_add');
};

const getNextApprovalId = (permController) => {
return permController.approvals._approvals.keys().next().value;
};
const getNextApprovalId = (permController) =>
permController.approvals._approvals.keys().next().value;

const validatePermission = (perm, name, origin, caveats) => {
assert.equal(
Expand Down
45 changes: 18 additions & 27 deletions app/scripts/controllers/permissions/restricted-methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ describe('restricted methods', function () {

it('should handle missing identity for first account when sorting', async function () {
const restrictedMethods = getRestrictedMethods({
getIdentities: () => {
return { '0x7e57e2': {} };
},
getIdentities: () => ({ '0x7e57e2': {} }),
getKeyringAccounts: async () => ['0x7e57e2', '0x7e57e3'],
});
const ethAccountsMethod = pify(restrictedMethods.eth_accounts.method);
Expand All @@ -49,9 +47,7 @@ describe('restricted methods', function () {

it('should handle missing identity for second account when sorting', async function () {
const restrictedMethods = getRestrictedMethods({
getIdentities: () => {
return { '0x7e57e3': {} };
},
getIdentities: () => ({ '0x7e57e3': {} }),
getKeyringAccounts: async () => ['0x7e57e2', '0x7e57e3'],
});
const ethAccountsMethod = pify(restrictedMethods.eth_accounts.method);
Expand All @@ -69,12 +65,11 @@ describe('restricted methods', function () {
it('should return accounts in keyring order when none are selected', async function () {
const keyringAccounts = ['0x7e57e2', '0x7e57e3', '0x7e57e4', '0x7e57e5'];
const restrictedMethods = getRestrictedMethods({
getIdentities: () => {
return keyringAccounts.reduce((identities, address) => {
getIdentities: () =>
keyringAccounts.reduce((identities, address) => {
Copy link
Contributor

@mcmire mcmire Sep 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing with this. It's not impossible to know where the function begins and ends, of course, because of the indentation, but the braces help in being able to spot it more easily.

identities[address] = {};
return identities;
}, {});
},
}, {}),
getKeyringAccounts: async () => [...keyringAccounts],
});
const ethAccountsMethod = pify(restrictedMethods.eth_accounts.method);
Expand All @@ -91,12 +86,11 @@ describe('restricted methods', function () {
it('should return accounts in keyring order when all have same last selected time', async function () {
const keyringAccounts = ['0x7e57e2', '0x7e57e3', '0x7e57e4', '0x7e57e5'];
const restrictedMethods = getRestrictedMethods({
getIdentities: () => {
return keyringAccounts.reduce((identities, address) => {
getIdentities: () =>
keyringAccounts.reduce((identities, address) => {
identities[address] = { lastSelected: 1000 };
return identities;
}, {});
},
}, {}),
getKeyringAccounts: async () => [...keyringAccounts],
});
const ethAccountsMethod = pify(restrictedMethods.eth_accounts.method);
Expand All @@ -114,12 +108,11 @@ describe('restricted methods', function () {
const keyringAccounts = ['0x7e57e2', '0x7e57e3', '0x7e57e4', '0x7e57e5'];
const expectedResult = keyringAccounts.slice().reverse();
const restrictedMethods = getRestrictedMethods({
getIdentities: () => {
return keyringAccounts.reduce((identities, address, index) => {
getIdentities: () =>
keyringAccounts.reduce((identities, address, index) => {
identities[address] = { lastSelected: index * 1000 };
return identities;
}, {});
},
}, {}),
getKeyringAccounts: async () => [...keyringAccounts],
});
const ethAccountsMethod = pify(restrictedMethods.eth_accounts.method);
Expand Down Expand Up @@ -149,15 +142,13 @@ describe('restricted methods', function () {
'0x7e57e6',
];
const restrictedMethods = getRestrictedMethods({
getIdentities: () => {
return {
'0x7e57e2': { lastSelected: 1000 },
'0x7e57e3': {},
'0x7e57e4': { lastSelected: 2000 },
'0x7e57e5': {},
'0x7e57e6': {},
};
},
getIdentities: () => ({
'0x7e57e2': { lastSelected: 1000 },
'0x7e57e3': {},
'0x7e57e4': { lastSelected: 2000 },
'0x7e57e5': {},
'0x7e57e6': {},
}),
getKeyringAccounts: async () => [...keyringAccounts],
});
const ethAccountsMethod = pify(restrictedMethods.eth_accounts.method);
Expand Down
18 changes: 6 additions & 12 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export default class PreferencesController {

this._subscribeToInfuraAvailability();

global.setPreference = (key, value) => {
return this.setFeatureFlag(key, value);
};
global.setPreference = (key, value) => this.setFeatureFlag(key, value);
}
// PUBLIC METHODS

Expand Down Expand Up @@ -336,9 +334,9 @@ export default class PreferencesController {
*/
async updateRpc(newRpcDetails) {
const rpcList = this.getFrequentRpcListDetail();
const index = rpcList.findIndex((element) => {
return element.rpcUrl === newRpcDetails.rpcUrl;
});
const index = rpcList.findIndex(
(element) => element.rpcUrl === newRpcDetails.rpcUrl,
);
if (index > -1) {
const rpcDetail = rpcList[index];
const updatedRpc = { ...rpcDetail, ...newRpcDetails };
Expand Down Expand Up @@ -419,9 +417,7 @@ export default class PreferencesController {
) {
const rpcList = this.getFrequentRpcListDetail();

const index = rpcList.findIndex((element) => {
return element.rpcUrl === rpcUrl;
});
const index = rpcList.findIndex((element) => element.rpcUrl === rpcUrl);
if (index !== -1) {
rpcList.splice(index, 1);
}
Expand All @@ -443,9 +439,7 @@ export default class PreferencesController {
*/
removeFromFrequentRpcList(url) {
const rpcList = this.getFrequentRpcListDetail();
const index = rpcList.findIndex((element) => {
return element.rpcUrl === url;
});
const index = rpcList.findIndex((element) => element.rpcUrl === url);
if (index !== -1) {
rpcList.splice(index, 1);
}
Expand Down
27 changes: 11 additions & 16 deletions app/scripts/controllers/swaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ const MOCK_GET_BUFFERED_GAS_LIMIT = async () => ({
function getMockNetworkController() {
return {
store: {
getState: () => {
return {
network: ROPSTEN_NETWORK_ID,
};
},
getState: () => ({
network: ROPSTEN_NETWORK_ID,
}),
},
on: sinon
.stub()
Expand Down Expand Up @@ -142,20 +140,18 @@ const sandbox = sinon.createSandbox();
const fetchTradesInfoStub = sandbox.stub();
const getCurrentChainIdStub = sandbox.stub();
getCurrentChainIdStub.returns(MAINNET_CHAIN_ID);
const getEIP1559GasFeeEstimatesStub = sandbox.stub(() => {
return {
gasFeeEstimates: {
high: '150',
},
gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY,
};
});
const getEIP1559GasFeeEstimatesStub = sandbox.stub(() => ({
gasFeeEstimates: {
high: '150',
},
gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY,
}));

describe('SwapsController', function () {
let provider;

const getSwapsController = () => {
return new SwapsController({
const getSwapsController = () =>
new SwapsController({
getBufferedGasLimit: MOCK_GET_BUFFERED_GAS_LIMIT,
networkController: getMockNetworkController(),
provider,
Expand All @@ -165,7 +161,6 @@ describe('SwapsController', function () {
getCurrentChainId: getCurrentChainIdStub,
getEIP1559GasFeeEstimates: getEIP1559GasFeeEstimatesStub,
});
};

before(function () {
const providerResultStub = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,10 @@ describe('PendingTransactionTracker', function () {
getTransactionReceipt: sinon.stub(),
},
nonceTracker: {
getGlobalLock: async () => {
return { releaseLock: () => undefined };
},
getGlobalLock: async () => ({ releaseLock: () => undefined }),
},
getPendingTransactions: () => txList,
getCompletedTransactions: () => {
return [];
},
getCompletedTransactions: () => [],
publishTransaction: () => undefined,
confirmTransaction: () => undefined,
});
Expand Down
4 changes: 1 addition & 3 deletions app/scripts/controllers/transactions/tx-gas-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ describe('txUtils', function () {
new Proxy(
{},
{
get: () => {
return () => undefined;
},
get: () => () => undefined,
},
),
);
Expand Down
8 changes: 3 additions & 5 deletions app/scripts/controllers/transactions/tx-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,9 @@ export default class TransactionStateManager extends EventEmitter {
// with the provided value". To conform this object to be only methods, we
// mapValues (lodash) such that every value on the object is a method that
// returns a boolean.
const predicateMethods = mapValues(searchCriteria, (predicate) => {
return typeof predicate === 'function'
? predicate
: (v) => v === predicate;
});
const predicateMethods = mapValues(searchCriteria, (predicate) =>
typeof predicate === 'function' ? predicate : (v) => v === predicate,
);

// If an initial list is provided we need to change it back into an object
// first, so that it matches the shape of our state. This is done by the
Expand Down
Loading