Skip to content

Commit 1c01073

Browse files
chore: add eslint (#231)
* chore: add eslint * ci: add lint step to ci workflow * chore(eslint): resolve errors Co-authored-by: Dhaiwat Pandya <[email protected]>
1 parent 7058114 commit 1c01073

33 files changed

+502
-289
lines changed

.eslintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:jest/recommended",
6+
"plugin:jest-dom/recommended",
7+
"plugin:prettier/recommended",
8+
"plugin:@typescript-eslint/eslint-recommended",
9+
"plugin:@typescript-eslint/recommended"
10+
],
11+
"env": {
12+
"es6": true,
13+
"browser": true,
14+
"node": true
15+
},
16+
"rules": {
17+
"@typescript-eslint/no-empty-interface": "off",
18+
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
19+
}
20+
}

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
2626
- name: Install Dependencies
2727
run: yarn install
28+
- name: Lint code
29+
run: yarn lint
2830
- name: Test code
2931
run: yarn test
3032
- name: Build

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"prepare": "husky install",
1313
"format": "prettier --write",
1414
"build": "preconstruct build",
15+
"lint": "eslint packages/**/src/ --ext .ts,.tsx --config .eslintrc",
1516
"test": "jest",
1617
"test:watch": "yarn test --watch",
1718
"test:coverage": "jest --coverage --colors",
@@ -33,11 +34,19 @@
3334
"@testing-library/jest-dom": "^5.15.1",
3435
"@testing-library/react": "^12.1.2",
3536
"@testing-library/react-hooks": "^7.0.2",
37+
"@typescript-eslint/eslint-plugin": "^5.9.0",
38+
"@typescript-eslint/parser": "^5.9.0",
3639
"chromatic": "^6.1.0",
40+
"eslint": "^8.6.0",
41+
"eslint-config-prettier": "^8.3.0",
42+
"eslint-plugin-jest": "^25.3.4",
43+
"eslint-plugin-jest-dom": "^4.0.1",
44+
"eslint-plugin-prettier": "^4.0.0",
3745
"husky": "^7.0.4",
3846
"jest": "^26.6.3",
3947
"lint-staged": "^12.1.3",
4048
"msw": "^0.35.0",
49+
"prettier": "^2.5.1",
4150
"ts-jest": "^26.4.4",
4251
"whatwg-fetch": "^3.6.2"
4352
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Button, VStack } from '@chakra-ui/react';
66

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

1212
export const Default = () => <Address value="testaddress.eth" />;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import {
44
render,
55
fireEvent,
66
waitFor,
7-
getByTestId
7+
getByTestId,
88
} from '@testing-library/react';
99

1010
import { Address } from './Address';
1111

1212
/**
1313
* We need to mock the Clipboard API by creating a global navigator object.
1414
*
15-
* We're assigning an empty function to `writeText`
16-
* as we're only testing if it has been called with specific argument.
15+
* We're assigning a mocked jest function to `writeText` as we're only testing
16+
* if it has been called with specific argument.
1717
*/
1818
Object.assign(navigator, {
1919
clipboard: {
20-
writeText: () => {}
21-
}
20+
writeText: jest.fn(),
21+
},
2222
});
2323

2424
describe('Address', () => {
@@ -45,8 +45,6 @@ describe('Address copiable prop true', () => {
4545
const { container } = render(<Address copiable value="taylorswift.eth" />);
4646
const addressContainer = getByTestId(container, 'address-container');
4747

48-
jest.spyOn(navigator.clipboard, 'writeText');
49-
5048
fireEvent.click(addressContainer);
5149

5250
await waitFor(() => {
@@ -60,6 +58,6 @@ describe('Address copiable prop true', () => {
6058
const { container } = render(
6159
<Address value="0x00000000000000" shortened />
6260
);
63-
expect(container.textContent).toContain('0x00...0000');
61+
expect(container).toHaveTextContent('0x00...0000');
6462
});
6563
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Flex,
44
FormControl,
55
FormErrorMessage,
6-
Text
6+
Text,
77
} from '@chakra-ui/react';
88
import { CopyIcon, CheckIcon } from '@chakra-ui/icons';
99
import React, { useState, useEffect } from 'react';
@@ -29,7 +29,7 @@ export interface AddressProps {
2929
export const Address: React.FC<AddressProps> = ({
3030
value,
3131
copiable = false,
32-
shortened = false
32+
shortened = false,
3333
}) => {
3434
const [error, setError] = useState<null | string>(null);
3535
const [copied, setCopied] = useState<boolean>(false);

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

Lines changed: 4 additions & 4 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 = () => {
@@ -21,7 +21,7 @@ const WithUseWallet = () => {
2121
<VStack>
2222
<AddressInput
2323
value={value}
24-
onChange={e => setValue(e)}
24+
onChange={(e) => setValue(e)}
2525
provider={provider!}
2626
/>
2727
<Text>Value: {value}</Text>
@@ -40,7 +40,7 @@ const Component = ({ ...props }) => {
4040
<VStack>
4141
<AddressInput
4242
value={value}
43-
onChange={e => setValue(e)}
43+
onChange={(e) => setValue(e)}
4444
provider={provider}
4545
placeholder="Enter input address"
4646
{...props}

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,7 +38,7 @@ const Component = () => {
3838
return (
3939
<AddressInput
4040
value={value}
41-
onChange={e => setValue(e)}
41+
onChange={(e) => setValue(e)}
4242
provider={provider}
4343
placeholder="Input address"
4444
/>
@@ -48,7 +48,7 @@ const Component = () => {
4848
describe('AddressInput', () => {
4949
it('renders AddressInput correctly', () => {
5050
const { container } = render(<Component />);
51-
expect(container);
51+
expect(container).toBeTruthy();
5252
});
5353

5454
it('changes Input value correctly', () => {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
FormLabel,
44
Input,
55
FormErrorMessage,
6-
InputProps
6+
InputProps,
77
} from '@chakra-ui/react';
88
import React, { useEffect, useState } from 'react';
99
import { ethers } from 'ethers';
@@ -34,7 +34,7 @@ export interface AddressInputProps {
3434
*/
3535
export const AddressInput: React.FC<AddressInputProps & InputProps> = ({
3636
provider,
37-
value,
37+
value: _value,
3838
onChange,
3939
label,
4040
...props
@@ -46,7 +46,7 @@ export const AddressInput: React.FC<AddressInputProps & InputProps> = ({
4646

4747
const getAddressFromEns = async () => {
4848
try {
49-
let address = await provider.resolveName(debouncedValue);
49+
const address = await provider.resolveName(debouncedValue);
5050
if (!address) {
5151
setError('Invalid Input');
5252
}
@@ -67,7 +67,7 @@ export const AddressInput: React.FC<AddressInputProps & InputProps> = ({
6767
debouncedValue.endsWith('.eth') ||
6868
debouncedValue.endsWith('.xyz')
6969
) {
70-
getAddressFromEns().then(address => onChange(address ? address : ''));
70+
getAddressFromEns().then((address) => onChange(address ? address : ''));
7171
}
7272
}
7373
}, [debouncedValue]);
@@ -85,7 +85,7 @@ export const AddressInput: React.FC<AddressInputProps & InputProps> = ({
8585
<Input
8686
isInvalid={!!error}
8787
value={inputValue}
88-
onChange={e => setInputValue(e.target.value)}
88+
onChange={(e) => setInputValue(e.target.value)}
8989
{...props}
9090
/>
9191
<FormErrorMessage>{error ? ' ' + error : ''}</FormErrorMessage>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NFT } from '.';
33

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

99
export const image = () => (

0 commit comments

Comments
 (0)