From 33fb39cca12b507ad6b2a4737db954c9b39b6cee Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 8 Feb 2022 13:24:42 +0100 Subject: [PATCH] Run prettier in CI workflow (#4276) * Run prettier in CI workflow * Fix inproperly formatted files * Update lint configs and run format * Revert matomo.js * Use matomo.js from master --- .github/FUNDING.yml | 2 +- .prettierignore | 76 ++++++++++++++++++- jest_config/__fixtures__/txConfigEIP1559.json | 2 +- package.json | 15 ++-- .../components/RecentTransactionList.test.tsx | 6 +- .../components/AddOrEditNetworkNode.tsx | 50 ++++++------ src/services/ApiService/MembershipApi.test.ts | 28 ++++--- src/services/ApiService/MembershipApi.ts | 15 ++-- .../Store/store/membership.slice.test.ts | 27 +++++-- src/services/Store/store/membership.slice.ts | 12 ++- .../deterministic/__mocks__/customDPaths.json | 2 +- .../__mocks__/customDPathsDone.json | 2 +- .../__mocks__/customDPathsPending.json | 2 +- 13 files changed, 176 insertions(+), 63 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index ceeddd3d690..798b80de1ac 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1 @@ -custom: https://donate.unlock-protocol.com/?r=mycryptohq/mycrypto \ No newline at end of file +custom: https://donate.unlock-protocol.com/?r=mycryptohq/mycrypto diff --git a/.prettierignore b/.prettierignore index feb87f2c7ff..6dfbbe07d0a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,76 @@ -package.json +.idea +# Logs +logs +*.log +npm-debug.log* + +# Build +dist +storybook-static + +# Runtime data +pids +*.pid +*.seed +# Python venv +venv + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# VScode workspace settings +.vscode/ +static/dll.vendor.js +dll +.cache-loader + +# SSL cert stuff +webpack_config/server.key +webpack_config/server.crt +webpack_config/server.csr + + +v8-compile-cache-0/ +package-lock.json + +# Favicon cache +.wwp-cache + +# MacOSX +.DS_Store + +# Ignore js transpiled scripts +node-scripts/**/*.js +/node-scripts/translations/__mocks__/sample.json + +.env +.cache + +# Prettier specific __snapshots__ +static/matomo.js diff --git a/jest_config/__fixtures__/txConfigEIP1559.json b/jest_config/__fixtures__/txConfigEIP1559.json index d36ee0f48b6..b2d7cd2934f 100644 --- a/jest_config/__fixtures__/txConfigEIP1559.json +++ b/jest_config/__fixtures__/txConfigEIP1559.json @@ -126,4 +126,4 @@ }, "from": "0xfE5443FaC29fA621cFc33D41D1927fd0f5E0bB7c", "networkId": "Ropsten" -} \ No newline at end of file +} diff --git a/package.json b/package.json index 7bf430ed20b..0a5812cc80a 100644 --- a/package.json +++ b/package.json @@ -235,20 +235,19 @@ "dev": "cross-env NODE_ENV=development TARGET_ENV=local webpack-dev-server --config webpack_config/development.js", "storybook": "start-storybook -p 3001 --ci", "build:storybook": "build-storybook", - "tscheck": "tsc", + "tscheck": "tsc --noEmit", "start": " yarn run dev", "serve": "ws -d dist/web/ --spa index.html", "prod": "npm run build && npm run serve", "precommit": "lint-staged", - "formatAll": "find ./src/ -name '*.ts*' | xargs prettier --write --config ./.prettierrc --config-precedence file-override", - "prettier:write": "prettier --write --config ./.prettierrc --config-precedence file-override", - "prettier:diff": "prettier --write --config ./.prettierrc --list-different \"src/**/*.ts\" \"src/**/*.tsx\"", + "format": "prettier --write \"**/*.{ts,tsx,js,json,yml,mdx}\"", "update:tokens": "parse-eth-tokens --networks all --output ./src/database/data/tokens --exclude 0x5a276Aeb77bCfDAc8Ac6f31BBC7416AE1A85eEF2,0x0027449Bf0887ca3E431D263FFDeFb244D95b555", "lint:styles": "stylelint ./src/**/*.tsx", "lint:code": "eslint . --ignore-path .gitignore --ext .ts,.tsx,.js,.jsx", + "lint:format": "prettier --check \"**/*.{ts,tsx,js,json,yml,mdx}\"", "node:scripts:tsc": "tsc --project tsconfig.scripts.json", "translations:extract": "npm run node:scripts:tsc && node node-scripts/translations/translations-extract.js", - "validate": "npm-run-all --parallel lint:styles lint:code tscheck", + "validate": "npm-run-all --parallel lint:styles lint:code lint:format tscheck", "validate:codecov": "curl --data-binary @codecov.yml https://codecov.io/validate" }, "resolutions": { @@ -256,12 +255,14 @@ }, "lint-staged": { "**/*.{ts,tsx}": [ - "yarn prettier:write", "yarn lint:styles", "eslint --fix", "git add" ], - "**/*.{js,json}": "yarn prettier:write" + "**/*.{js,jsx,ts,tsx,json,md,mdx}": [ + "prettier --write", + "git add" + ] }, "husky": { "hooks": { diff --git a/src/features/Dashboard/components/RecentTransactionList.test.tsx b/src/features/Dashboard/components/RecentTransactionList.test.tsx index ffe82e98004..780729347a9 100644 --- a/src/features/Dashboard/components/RecentTransactionList.test.tsx +++ b/src/features/Dashboard/components/RecentTransactionList.test.tsx @@ -14,12 +14,12 @@ describe('RecentTransactionList', () => { initialState: mockStore({ storeSlice: { txHistory: { - history: [fTxHistoryAPI as unknown as DeepPartial], + history: [(fTxHistoryAPI as unknown) as DeepPartial], txTypeMeta: fTxTypeMetas } } }) - }) + }); }; test('Can render', () => { @@ -30,7 +30,7 @@ describe('RecentTransactionList', () => { test('Can render transactions', () => { const { getByText } = renderComponent(); - const selector = translateRaw('RECENT_TRANSACTIONS_DATE') + const selector = translateRaw('RECENT_TRANSACTIONS_DATE'); expect(getByText(selector)).toBeInTheDocument(); }); diff --git a/src/features/Settings/components/AddOrEditNetworkNode.tsx b/src/features/Settings/components/AddOrEditNetworkNode.tsx index 3e592edeabe..be77855a223 100644 --- a/src/features/Settings/components/AddOrEditNetworkNode.tsx +++ b/src/features/Settings/components/AddOrEditNetworkNode.tsx @@ -127,7 +127,7 @@ const SError = styled.div` color: ${COLORS.PASTEL_RED}; `; -const DeleteButton = styled(Button) <{ disabled: boolean }>` +const DeleteButton = styled(Button)<{ disabled: boolean }>` ${(props) => !props.disabled && ` @@ -307,31 +307,31 @@ export default function AddOrEditNetworkNode({ const network: Network = !isAddingCustomNetwork ? getNetworkById(selectedNetworkId) : { - id: selectedNetworkId, - name: networkName!, - chainId: parseInt(chainId!, 10), - baseUnit: baseUnit as TTicker, - baseAsset: generateAssetUUID(chainId!), - isCustom: true, - nodes: [node], - dPaths: { - [WalletId.TREZOR]: DEFAULT_ETH, - [WalletId.LEDGER_NANO_S]: DEFAULT_ETH, - default: DEFAULT_ETH - }, - gasPriceSettings: { - min: 1, - max: 100, - initial: 1 - }, - shouldEstimateGasPrice: false, - color: undefined, - selectedNode: node.name, - blockExplorer: makeExplorer({ + id: selectedNetworkId, name: networkName!, - origin: ETHPLORER_URL - }) - }; + chainId: parseInt(chainId!, 10), + baseUnit: baseUnit as TTicker, + baseAsset: generateAssetUUID(chainId!), + isCustom: true, + nodes: [node], + dPaths: { + [WalletId.TREZOR]: DEFAULT_ETH, + [WalletId.LEDGER_NANO_S]: DEFAULT_ETH, + default: DEFAULT_ETH + }, + gasPriceSettings: { + min: 1, + max: 100, + initial: 1 + }, + shouldEstimateGasPrice: false, + color: undefined, + selectedNode: node.name, + blockExplorer: makeExplorer({ + name: networkName!, + origin: ETHPLORER_URL + }) + }; const provider = new ProviderHandler({ ...network, nodes: [node] }, false); await provider.getLatestBlockNumber(); diff --git a/src/services/ApiService/MembershipApi.test.ts b/src/services/ApiService/MembershipApi.test.ts index ed6270acaa0..14bf152f157 100644 --- a/src/services/ApiService/MembershipApi.test.ts +++ b/src/services/ApiService/MembershipApi.test.ts @@ -1,13 +1,19 @@ import { DEFAULT_NETWORK, POLYGON_NETWORK, XDAI_NETWORK } from '@config'; import { IMembershipId, MembershipStatus } from '@features/PurchaseMembership/config'; -import { accountWithMembership, fAccount, fNetwork, fNetworks, membershipApiResponse } from '@fixtures'; +import { + accountWithMembership, + fAccount, + fNetwork, + fNetworks, + membershipApiResponse +} from '@fixtures'; import { StoreAccount, WalletId } from '@types'; import MembershipApi, { formatResponse, getMembershipContracts } from './MembershipApi'; jest.mock('@mycrypto/unlock-scan', () => ({ ...jest.requireActual('@mycrypto/unlock-scan'), - getUnlockTimestamps: jest.fn().mockResolvedValue(Promise.reject("error fetching balances")) + getUnlockTimestamps: jest.fn().mockResolvedValue(Promise.reject('error fetching balances')) })); describe('MembershipApi', () => { @@ -27,7 +33,11 @@ describe('MembershipApi', () => { }); it('getMultiNetworkMemberships(): handles fetch errors', async () => { const accounts = [ - { address: accountWithMembership, networkId: DEFAULT_NETWORK, wallet: WalletId.LEDGER_NANO_S }, + { + address: accountWithMembership, + networkId: DEFAULT_NETWORK, + wallet: WalletId.LEDGER_NANO_S + }, { address: '0xfeac75a09662396283f4bb50f0a9249576a81866', networkId: XDAI_NETWORK }, { ...fAccount, networkId: POLYGON_NETWORK } ] as StoreAccount[]; @@ -42,7 +52,7 @@ describe('MembershipApi', () => { const polygonAccounts = accounts .filter(({ networkId }) => networkId === POLYGON_NETWORK) .map(({ address }) => address); - + const membershipFetchState = [ { accounts: ethereumAccounts, @@ -62,11 +72,11 @@ describe('MembershipApi', () => { xDAI: true, MATIC: true, Ethereum: true - } - const expected = { memberships, errors } - const res = await MembershipApi.getMultiNetworkMemberships(membershipFetchState) - expect(res).toStrictEqual(expected) - }) + }; + const expected = { memberships, errors }; + const res = await MembershipApi.getMultiNetworkMemberships(membershipFetchState); + expect(res).toStrictEqual(expected); + }); }); describe('getMembershipContracts()', () => { diff --git a/src/services/ApiService/MembershipApi.ts b/src/services/ApiService/MembershipApi.ts index 51386b6bf39..eeb15303396 100644 --- a/src/services/ApiService/MembershipApi.ts +++ b/src/services/ApiService/MembershipApi.ts @@ -75,12 +75,15 @@ const MembershipApi = { }); }) ).then((membershipStates) => - membershipStates.reduce((membershipState, acc) => { - return { - memberships: [...acc.memberships, ...membershipState.memberships], - errors: { ...acc.errors, ...membershipState.errors } - }; - }, { memberships: [], errors: {} } as unknown as MembershipFetchResult) + membershipStates.reduce( + (membershipState, acc) => { + return { + memberships: [...acc.memberships, ...membershipState.memberships], + errors: { ...acc.errors, ...membershipState.errors } + }; + }, + ({ memberships: [], errors: {} } as unknown) as MembershipFetchResult + ) ); } }; diff --git a/src/services/Store/store/membership.slice.test.ts b/src/services/Store/store/membership.slice.test.ts index 924b7550f2b..0c0b45778d9 100644 --- a/src/services/Store/store/membership.slice.test.ts +++ b/src/services/Store/store/membership.slice.test.ts @@ -28,7 +28,10 @@ describe('MembershipsSlice', () => { it('setMembershipFetchState(): adds multiple memberships state', () => { const m1 = { address: 'random', networkId: DEFAULT_NETWORK } as MembershipStatus; const m2 = { address: 'random2', networkId: DEFAULT_NETWORK } as MembershipStatus; - const actual = reducer(initialState, setMembershipFetchState({ memberships: [m1, m2], errors: {} as MembershipErrorState})); + const actual = reducer( + initialState, + setMembershipFetchState({ memberships: [m1, m2], errors: {} as MembershipErrorState }) + ); const expected = { ...initialState, record: [m1, m2] }; expect(actual).toEqual(expected); }); @@ -36,7 +39,10 @@ describe('MembershipsSlice', () => { it('setMembershipFetchState(): deduplicates memberships', () => { const m1 = { address: 'random', networkId: DEFAULT_NETWORK } as MembershipStatus; const m2 = { address: 'random2', networkId: DEFAULT_NETWORK } as MembershipStatus; - const actual = reducer({ ...initialState, record: [m1] }, setMembershipFetchState({ memberships: [m1, m2], errors: {} as MembershipErrorState})); + const actual = reducer( + { ...initialState, record: [m1] }, + setMembershipFetchState({ memberships: [m1, m2], errors: {} as MembershipErrorState }) + ); const expected = { ...initialState, record: [m1, m2] }; expect(actual).toEqual(expected); }); @@ -50,7 +56,10 @@ describe('MembershipsSlice', () => { const m2 = { address: 'random2', networkId: DEFAULT_NETWORK } as MembershipStatus; const actual = reducer( { ...initialState, record: [m1] }, - setMembershipFetchState({ memberships: [{ ...m1, memberships: [{ type: 'sixmonths' }] }, m2] as MembershipStatus[], errors: {} as MembershipErrorState}) + setMembershipFetchState({ + memberships: [{ ...m1, memberships: [{ type: 'sixmonths' }] }, m2] as MembershipStatus[], + errors: {} as MembershipErrorState + }) ); const expected = { ...initialState, @@ -84,7 +93,10 @@ describe('MembershipsSlice', () => { xDAI: true, MATIC: false }; - const actual = reducer(initialState, setMembershipFetchState({ memberships: [], errors: errorState })); + const actual = reducer( + initialState, + setMembershipFetchState({ memberships: [], errors: errorState }) + ); const expected = { ...initialState, error: errorState }; expect(actual).toEqual(expected); }); @@ -202,7 +214,12 @@ describe('fetchMembershipsSaga()', () => { } ] ]) - .put(setMembershipFetchState({ memberships: res, errors: { Ethereum: true } as MembershipErrorState })) + .put( + setMembershipFetchState({ + memberships: res, + errors: { Ethereum: true } as MembershipErrorState + }) + ) .dispatch(fetchMemberships()) .silentRun(); }); diff --git a/src/services/Store/store/membership.slice.ts b/src/services/Store/store/membership.slice.ts index f20a89e2e65..917b82e2207 100644 --- a/src/services/Store/store/membership.slice.ts +++ b/src/services/Store/store/membership.slice.ts @@ -31,7 +31,10 @@ const slice = createSlice({ name: 'memberships', initialState, reducers: { - setMembershipFetchState(state, action: PayloadAction<{ memberships: MembershipStatus[], errors: MembershipErrorState }>) { + setMembershipFetchState( + state, + action: PayloadAction<{ memberships: MembershipStatus[]; errors: MembershipErrorState }> + ) { const addresses = new Set(action.payload.memberships.map((item) => item.address)); state.record = [ ...action.payload.memberships, @@ -136,7 +139,12 @@ export function* fetchMembershipsWorker({ payload }: PayloadAction