Skip to content

Commit c44b39a

Browse files
authored
Lint entire codebase (#158)
1 parent e611ef9 commit c44b39a

21 files changed

+244
-149
lines changed

packages/components/.babelrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44
"@babel/preset-typescript",
55
"@babel/preset-react"
66
],
7-
"plugins": [
8-
"@babel/plugin-transform-runtime"
9-
]
7+
"plugins": ["@babel/plugin-transform-runtime"]
108
}

packages/components/src/components/Address/Address.stories.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import { Button, VStack } from '@chakra-ui/react';
66

77
export default {
88
title: 'Components/Address',
9-
component: Address,
9+
component: Address
1010
};
1111

12-
export const Default = () => <Address value='testaddress.eth' />;
12+
export const Default = () => <Address value="testaddress.eth" />;
1313

14-
export const DefaultShortenedWithENS = () => <Address shortened value='testaddress.eth' />;
14+
export const DefaultShortenedWithENS = () => (
15+
<Address shortened value="testaddress.eth" />
16+
);
1517

1618
export const DefaultShortenedWithHexAddress = () => (
17-
<Address shortened value='0x7Be8076f4EA4A4AD08075C2508e481d6C946D12b' />
19+
<Address shortened value="0x7Be8076f4EA4A4AD08075C2508e481d6C946D12b" />
1820
);
1921

2022
type AddressProps = {
@@ -28,7 +30,11 @@ const AddressUsingProvider = (props: AddressProps) => {
2830
<VStack>
2931
<Address
3032
copiable
31-
value={connected ? connection.ens || connection.userAddress || '' : 'Not connected'}
33+
value={
34+
connected
35+
? connection.ens || connection.userAddress || ''
36+
: 'Not connected'
37+
}
3238
shortened={props.shortened}
3339
/>
3440
<Button onClick={connectWallet}>Connect wallet</Button>
@@ -48,4 +54,4 @@ export const WithWalletShortened = () => (
4854
</Provider>
4955
);
5056

51-
export const CanBeCopied = () => <Address value='0x00000000000000' copiable />;
57+
export const CanBeCopied = () => <Address value="0x00000000000000" copiable />;
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React from 'react';
22
import { jest } from '@jest/globals';
3-
import { render, fireEvent, waitFor, getByTestId } from '@testing-library/react';
3+
import {
4+
render,
5+
fireEvent,
6+
waitFor,
7+
getByTestId
8+
} from '@testing-library/react';
49

510
import { Address } from './Address';
611

@@ -12,45 +17,49 @@ import { Address } from './Address';
1217
*/
1318
Object.assign(navigator, {
1419
clipboard: {
15-
writeText: () => {},
16-
},
20+
writeText: () => {}
21+
}
1722
});
1823

1924
describe('Address', () => {
2025
it('renders without throwing', () => {
21-
const { container } = render(<Address value='taylorswift.eth' />);
26+
const { container } = render(<Address value="taylorswift.eth" />);
2227
expect(container).toBeInTheDocument();
2328
});
2429
});
2530

2631
describe('Address copiable prop true', () => {
2732
it('renders without throwing', () => {
28-
const { container } = render(<Address copiable value='taylorswift.eth' />);
33+
const { container } = render(<Address copiable value="taylorswift.eth" />);
2934
expect(container).toBeInTheDocument();
3035
});
3136

3237
it('renders with icon', () => {
33-
const { container } = render(<Address copiable value='taylorswift.eth' />);
38+
const { container } = render(<Address copiable value="taylorswift.eth" />);
3439
const svg = container.querySelector('svg') as SVGElement;
3540

3641
expect(svg).toBeInTheDocument();
3742
});
3843

3944
it('uses writeText from Clipboard API', async () => {
40-
const { container } = render(<Address copiable value='taylorswift.eth' />);
45+
const { container } = render(<Address copiable value="taylorswift.eth" />);
4146
const addressContainer = getByTestId(container, 'address-container');
4247

4348
jest.spyOn(navigator.clipboard, 'writeText');
4449

4550
fireEvent.click(addressContainer);
4651

4752
await waitFor(() => {
48-
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('taylorswift.eth');
53+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
54+
'taylorswift.eth'
55+
);
4956
});
5057
});
5158

5259
it('checks the length of the address when shortened', () => {
53-
const { container } = render(<Address value='0x00000000000000' shortened />);
60+
const { container } = render(
61+
<Address value="0x00000000000000" shortened />
62+
);
5463
expect(container.textContent).toContain('0x00...0000');
5564
});
5665
});

packages/components/src/components/Address/Address.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Box, Flex, FormControl, FormErrorMessage, Text } from '@chakra-ui/react';
1+
import {
2+
Box,
3+
Flex,
4+
FormControl,
5+
FormErrorMessage,
6+
Text
7+
} from '@chakra-ui/react';
28
import { CopyIcon, CheckIcon } from '@chakra-ui/icons';
39
import React, { useState, useEffect } from 'react';
410

@@ -20,7 +26,11 @@ export interface AddressProps {
2026
/**
2127
* A component to display an address
2228
*/
23-
export const Address: React.FC<AddressProps> = ({ value, copiable = false, shortened = false }) => {
29+
export const Address: React.FC<AddressProps> = ({
30+
value,
31+
copiable = false,
32+
shortened = false
33+
}) => {
2434
const [error, setError] = useState<null | string>(null);
2535
const [copied, setCopied] = useState<boolean>(false);
2636
let feedbackTimeOut: ReturnType<typeof setTimeout>;
@@ -59,15 +69,19 @@ export const Address: React.FC<AddressProps> = ({ value, copiable = false, short
5969
return (
6070
<FormControl isInvalid={!!error}>
6171
<Flex
62-
data-testid='address-container'
63-
alignItems='center'
72+
data-testid="address-container"
73+
alignItems="center"
6474
cursor={copiable ? 'pointer' : 'initial'}
6575
onClick={handleClick}
6676
>
6777
<Text>{displayAddress}</Text>
6878
{copiable && (
69-
<Box ml='auto'>
70-
{copied ? <CheckIcon color='green.500' /> : <CopyIcon color='gray.300' />}
79+
<Box ml="auto">
80+
{copied ? (
81+
<CheckIcon color="green.500" />
82+
) : (
83+
<CopyIcon color="gray.300" />
84+
)}
7185
</Box>
7286
)}
7387
</Flex>

packages/components/src/components/AddressInput/AddressInput.stories.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default {
99
component: AddressInput,
1010
parameters: {
1111
// TODO: Fix window.ethereum is undefined breaking chromatic
12-
chromatic: { disableSnapshot: true },
13-
},
12+
chromatic: { disableSnapshot: true }
13+
}
1414
};
1515

1616
const WithUseWallet = () => {
@@ -19,11 +19,15 @@ const WithUseWallet = () => {
1919

2020
return (
2121
<VStack>
22-
<AddressInput value={value} onChange={e => setValue(e)} provider={provider!} />
22+
<AddressInput
23+
value={value}
24+
onChange={e => setValue(e)}
25+
provider={provider!}
26+
/>
2327
<Text>Value: {value}</Text>
24-
<Text fontSize='sm'>
25-
You need to be connected to the Ethereum mainnet for ENS to work right now. We are working
26-
on adding better support for ENS.
28+
<Text fontSize="sm">
29+
You need to be connected to the Ethereum mainnet for ENS to work right
30+
now. We are working on adding better support for ENS.
2731
</Text>
2832
</VStack>
2933
);
@@ -38,13 +42,13 @@ const Component = ({ ...props }) => {
3842
value={value}
3943
onChange={e => setValue(e)}
4044
provider={provider}
41-
placeholder='Enter input address'
45+
placeholder="Enter input address"
4246
{...props}
4347
/>
4448
<Text>Value: {value}</Text>
45-
<Text fontSize='sm'>
46-
You need to be connected to the Ethereum mainnet for ENS to work right now. We are working
47-
on adding better support for ENS.
49+
<Text fontSize="sm">
50+
You need to be connected to the Ethereum mainnet for ENS to work right
51+
now. We are working on adding better support for ENS.
4852
</Text>
4953
</VStack>
5054
);
@@ -58,4 +62,4 @@ export const UsingWeb3Hooks = () => {
5862
</Provider>
5963
);
6064
};
61-
export const Label = () => <Component label='Address' />;
65+
export const Label = () => <Component label="Address" />;

packages/components/src/components/AddressInput/AddressInput.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ const WINDOW_ETHEREUM = {
1818
}
1919

2020
throw Error(`Unknown request: ${request.method}`);
21-
},
21+
}
2222
};
2323

2424
jest.mock('ethers', () => {
2525
const original = jest.requireActual('ethers');
2626
return {
2727
...original,
2828
ethers: {
29-
...original.ethers,
30-
},
29+
...original.ethers
30+
}
3131
};
3232
});
3333

@@ -38,9 +38,9 @@ const Component = () => {
3838
return (
3939
<AddressInput
4040
value={value}
41-
onChange={(e) => setValue(e)}
41+
onChange={e => setValue(e)}
4242
provider={provider}
43-
placeholder='Input address'
43+
placeholder="Input address"
4444
/>
4545
);
4646
};

packages/components/src/components/AddressInput/AddressInput.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { FormControl, FormLabel, Input, FormErrorMessage, InputProps } from '@chakra-ui/react';
1+
import {
2+
FormControl,
3+
FormLabel,
4+
Input,
5+
FormErrorMessage,
6+
InputProps
7+
} from '@chakra-ui/react';
28
import React, { useEffect, useState } from 'react';
39
import { ethers } from 'ethers';
410
import { useDebounce } from './useDebounce';
@@ -57,7 +63,10 @@ export const AddressInput: React.FC<AddressInputProps & InputProps> = ({
5763
setError(null);
5864
if (regex.test(debouncedValue)) {
5965
onChange(debouncedValue);
60-
} else if (debouncedValue.endsWith('.eth') || debouncedValue.endsWith('.xyz')) {
66+
} else if (
67+
debouncedValue.endsWith('.eth') ||
68+
debouncedValue.endsWith('.xyz')
69+
) {
6170
getAddressFromEns().then(address => onChange(address ? address : ''));
6271
}
6372
}

packages/components/src/components/NFT/NFT.stories.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,43 @@ import { NFT } from '.';
33

44
export default {
55
title: 'Components/NFT',
6-
component: NFT,
6+
component: NFT
77
};
88

99
export const image = () => (
10-
<NFT tokenId='1' contractAddress='0x25ed58c027921e14d86380ea2646e3a1b5c55a8b' />
10+
<NFT
11+
tokenId="1"
12+
contractAddress="0x25ed58c027921e14d86380ea2646e3a1b5c55a8b"
13+
/>
1114
);
1215

1316
export const GIF = () => (
1417
<NFT
15-
contractAddress='0x495f947276749ce646f68ac8c248420045cb7b5e'
16-
tokenId='107788331033457039753851660026809005506934842002275129649229957686061111967745'
18+
contractAddress="0x495f947276749ce646f68ac8c248420045cb7b5e"
19+
tokenId="107788331033457039753851660026809005506934842002275129649229957686061111967745"
1720
/>
1821
);
1922

2023
export const Video = () => (
21-
<NFT contractAddress='0xb932a70a57673d89f4acffbe830e8ed7f75fb9e0' tokenId='29192' />
24+
<NFT
25+
contractAddress="0xb932a70a57673d89f4acffbe830e8ed7f75fb9e0"
26+
tokenId="29192"
27+
/>
2228
);
2329

2430
export const Audio = () => (
25-
<NFT contractAddress='0x0eede4764cfdfcd5dac0e00b3b7f4778c0cc994e' tokenId='1' />
31+
<NFT
32+
contractAddress="0x0eede4764cfdfcd5dac0e00b3b7f4778c0cc994e"
33+
tokenId="1"
34+
/>
2635
);
2736

2837
export const Big = () => (
29-
<NFT contractAddress='0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D' tokenId='1' size='lg' />
38+
<NFT
39+
contractAddress="0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"
40+
tokenId="1"
41+
size="lg"
42+
/>
3043
);
3144

32-
export const Error = () => <NFT contractAddress='abcd' tokenId='1' />;
45+
export const Error = () => <NFT contractAddress="abcd" tokenId="1" />;

packages/components/src/components/NFT/NFT.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { act } from 'react-dom/test-utils';
77
describe('NFT', () => {
88
it('displays an image NFT properly', async () => {
99
act(() => {
10-
render(<NFT tokenId='1' contractAddress='0x25ed58c027921e14d86380ea2646e3a1b5c55a8b' />);
10+
render(
11+
<NFT
12+
tokenId="1"
13+
contractAddress="0x25ed58c027921e14d86380ea2646e3a1b5c55a8b"
14+
/>
15+
);
1116
});
1217
const name = await screen.findByText('Dev #1');
1318
const image = await screen.findByAltText('Dev #1');

packages/components/src/components/NFTGallery/NFTGallery.stories.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { NFTGallery } from '.';
44

55
export default {
66
title: 'Components/NFTGallery',
7-
component: NFTGallery,
7+
component: NFTGallery
88
};
99

1010
export const nftsOwnedByAnAccount = () => (
11-
<NFTGallery address='0x1A16c87927570239FECD343ad2654fD81682725e' gridWidth={2} />
11+
<NFTGallery
12+
address="0x1A16c87927570239FECD343ad2654fD81682725e"
13+
gridWidth={2}
14+
/>
1215
);
1316

1417
const nftsOwnedByAnENSStory = () => {
@@ -23,14 +26,14 @@ const nftsOwnedByAnENSStory = () => {
2326
return <>Loading...</>;
2427
}
2528

26-
return <NFTGallery address='dhaiwat.eth' web3Provider={provider} />;
29+
return <NFTGallery address="dhaiwat.eth" web3Provider={provider} />;
2730
};
2831

2932
export const nftsOwnedByAnENS = nftsOwnedByAnENSStory.bind({});
3033
// @ts-expect-error
3134
nftsOwnedByAnENS.parameters = {
3235
// disables Chromatic's snapshotting on a story level
33-
chromatic: { disableSnapshot: true },
36+
chromatic: { disableSnapshot: true }
3437
};
3538

36-
export const WithAnError = () => <NFTGallery address='bad_address' />;
39+
export const WithAnError = () => <NFTGallery address="bad_address" />;

0 commit comments

Comments
 (0)