Skip to content

Commit

Permalink
Run prettier in CI workflow (#4276)
Browse files Browse the repository at this point in the history
* Run prettier in CI workflow

* Fix inproperly formatted files

* Update lint configs and run format

* Revert matomo.js

* Use matomo.js from master
  • Loading branch information
Mrtenz authored Feb 8, 2022
1 parent eab9fa1 commit 33fb39c
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
custom: https://donate.unlock-protocol.com/?r=mycryptohq/mycrypto
custom: https://donate.unlock-protocol.com/?r=mycryptohq/mycrypto
76 changes: 75 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion jest_config/__fixtures__/txConfigEIP1559.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@
},
"from": "0xfE5443FaC29fA621cFc33D41D1927fd0f5E0bB7c",
"networkId": "Ropsten"
}
}
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,33 +235,34 @@
"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": {
"@storybook/**/@emotion/sheet": "1.0.1"
},
"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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ describe('RecentTransactionList', () => {
initialState: mockStore({
storeSlice: {
txHistory: {
history: [fTxHistoryAPI as unknown as DeepPartial<ITxHistoryApiResponse>],
history: [(fTxHistoryAPI as unknown) as DeepPartial<ITxHistoryApiResponse>],
txTypeMeta: fTxTypeMetas
}
}
})
})
});
};

test('Can render', () => {
Expand All @@ -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();
});

Expand Down
50 changes: 25 additions & 25 deletions src/features/Settings/components/AddOrEditNetworkNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
`
Expand Down Expand Up @@ -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();

Expand Down
28 changes: 19 additions & 9 deletions src/services/ApiService/MembershipApi.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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[];
Expand All @@ -42,7 +52,7 @@ describe('MembershipApi', () => {
const polygonAccounts = accounts
.filter(({ networkId }) => networkId === POLYGON_NETWORK)
.map(({ address }) => address);

const membershipFetchState = [
{
accounts: ethereumAccounts,
Expand All @@ -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()', () => {
Expand Down
15 changes: 9 additions & 6 deletions src/services/ApiService/MembershipApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
};
Expand Down
27 changes: 22 additions & 5 deletions src/services/Store/store/membership.slice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ 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);
});

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);
});
Expand All @@ -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,
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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();
});
Expand Down
12 changes: 10 additions & 2 deletions src/services/Store/store/membership.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -136,7 +139,12 @@ export function* fetchMembershipsWorker({ payload }: PayloadAction<IAccount[] |
MembershipApi.getMultiNetworkMemberships,
membershipFetchConfig
);
yield put(slice.actions.setMembershipFetchState({ memberships: membershipState.memberships, errors: membershipState.errors }));
yield put(
slice.actions.setMembershipFetchState({
memberships: membershipState.memberships,
errors: membershipState.errors
})
);
}

export const { setMembershipFetchState, setMembership, deleteMembership } = slice.actions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"offset": 0,
"numOfAddresses": 5
}
]
]
Loading

0 comments on commit 33fb39c

Please sign in to comment.