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

fix: Linting rules (no-async-promise-executor, no-misused-promises, no-unnecessary-type-contraint, ...) #2182

Merged
merged 6 commits into from
Mar 12, 2024
Merged
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
5 changes: 0 additions & 5 deletions webapp/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
rules: {
'@typescript-eslint/no-unsafe-declaration-merging': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-declaration-merging
'@typescript-eslint/no-redundant-type-constituents': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-redundant-type-constituents
'@typescript-eslint/require-await': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/require-await
'@typescript-eslint/no-floating-promises': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-floating-promises
'@typescript-eslint/no-unsafe-return': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-return
'@typescript-eslint/naming-convention': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/naming-convention/
Expand All @@ -24,17 +23,13 @@ module.exports = {
'@typescript-eslint/ban-types': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/ban-types
'@typescript-eslint/unbound-method': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/unbound-method
'@typescript-eslint/ban-ts-comment': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/ban-ts-comment
'no-prototype-builtins': 'off', // TODO: migrate code progressively to remove this line. https://eslint.org/docs/rules/no-prototype-builtins
'@typescript-eslint/no-unsafe-assignment': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-assignment/
'@typescript-eslint/no-unsafe-call': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-call/
'@typescript-eslint/no-unsafe-member-access': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-member-access/
'@typescript-eslint/no-unsafe-argument': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-argument/
'@typescript-eslint/no-explicit-any': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-explicit-any
'@typescript-eslint/no-non-null-assertion': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-non-null-assertion
'no-async-promise-executor': 'off', // TODO: migrate code progressively to remove this line. https://eslint.org/docs/rules/no-async-promise-executor
'@typescript-eslint/await-thenable': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/await-thenable
'@typescript-eslint/no-unnecessary-type-constraint': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unnecessary-type-constraint
'@typescript-eslint/no-misused-promises': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-misused-promises
'import/order': 'off', // TODO: migrate code progressively to remove this line.
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain
'@typescript-eslint/no-unsafe-enum-comparison': 'off'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Bid, ChainId, Item, ListingStatus, Network, NFTCategory, Order, Rarity } from '@dcl/schemas'
import React, { RefObject } from 'react'
import { createRef, RefObject } from 'react'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'

import * as bidAPI from '../../../modules/vendor/decentraland/bid/api'
Expand Down Expand Up @@ -95,15 +95,15 @@ describe('Best Buying Option', () => {
})

describe('Mint option', () => {
it('should render the mint option', async () => {
const reference: RefObject<HTMLDivElement> = React.createRef()
it('should render the mint option', () => {
const reference: RefObject<HTMLDivElement> = createRef()
const { getByText } = renderWithProviders(<BestBuyingOption asset={asset} tableRef={reference} />)

expect(getByText(t('best_buying_option.minting.title'))).toBeInTheDocument()
})

it('should render the mint price', async () => {
const reference: RefObject<HTMLDivElement> = React.createRef()
it('should render the mint price', () => {
const reference: RefObject<HTMLDivElement> = createRef()
const { getByText } = renderWithProviders(<BestBuyingOption asset={asset} tableRef={reference} />)

const price = formatWeiMANA(asset.price)
Expand All @@ -127,7 +127,7 @@ describe('Best Buying Option', () => {
})

it('should render the listing option', async () => {
const reference: RefObject<HTMLDivElement> = React.createRef()
const reference: RefObject<HTMLDivElement> = createRef()
const { findByTestId, findByText } = renderWithProviders(<BestBuyingOption asset={asset} tableRef={reference} />)

await findByTestId('best-buying-option-container')
Expand All @@ -140,7 +140,7 @@ describe('Best Buying Option', () => {
})

it('should render the listing price and de highest offer for that NFT', async () => {
const reference: RefObject<HTMLDivElement> = React.createRef()
const reference: RefObject<HTMLDivElement> = createRef()
const { getByText, findByTestId } = renderWithProviders(<BestBuyingOption asset={asset} tableRef={reference} />)

await findByTestId('best-buying-option-container')
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('Best Buying Option', () => {
})

it('should render no options available', async () => {
const reference: RefObject<HTMLDivElement> = React.createRef()
const reference: RefObject<HTMLDivElement> = createRef()
const { getByText, findByTestId } = renderWithProviders(<BestBuyingOption asset={asset} tableRef={reference} />)

await findByTestId('best-buying-option-container')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,59 +179,61 @@ describe('SearchBarDropdown', () => {
})
})

it('should render the results', async () => {
it('should render the results', () => {
const { getByText } = renderSearchDropBarDropdown(props)
await waitFor(() => {

return waitFor(() => {
expect(getByText(MOCKED_ITEM.name)).toBeInTheDocument()
})
})

it('should have the correct asset url in the result rendered', async () => {
it('should have the correct asset url in the result rendered', () => {
const { container } = renderSearchDropBarDropdown(props)
await waitFor(async () => {

return waitFor(() => {
expect(within(container).getByRole('link')).toHaveAttribute('href', getAssetUrl(MOCKED_ITEM as Asset))
})
})

it('should save the result in the recent searches on the click event', async () => {
it('should save the result in the recent searches on the click event', () => {
const { container } = renderSearchDropBarDropdown(props)
await waitFor(async () => {
return waitFor(() => {
const link = within(container).getByRole('link')
await fireEvent.click(link)
fireEvent.click(link)
expect(localStorage.getItem(LOCAL_STORAGE_RECENT_SEARCHES_KEY)).toBe(JSON.stringify([MOCKED_ITEM]))
})
})

it('should render the see all button', async () => {
it('should render the see all button', () => {
const { getByTestId } = renderSearchDropBarDropdown(props)
await waitFor(async () => {
return waitFor(() => {
expect(getByTestId(SEE_ALL_COLLECTIBLES_DATA_TEST_ID)).toBeInTheDocument()
})
})

it('should call the onSearch handler when clicking the see all button', async () => {
it('should call the onSearch handler when clicking the see all button', () => {
const onSearch = jest.fn()
const { getByTestId } = renderSearchDropBarDropdown({
...props,
onSearch
})
await waitFor(async () => {
return waitFor(() => {
const button = getByTestId(SEE_ALL_COLLECTIBLES_DATA_TEST_ID)
await fireEvent.click(button)
fireEvent.click(button)
expect(onSearch).toHaveBeenCalledWith({
value: props.searchTerm
})
})
})

it('should call the onSearch handler when hitting enter', async () => {
it('should call the onSearch handler when hitting enter', () => {
const onSearch = jest.fn()
renderSearchDropBarDropdown({
...props,
onSearch
})
await waitFor(async () => {
await fireEvent.keyDown(document, { key: 'Enter' })
return waitFor(() => {
fireEvent.keyDown(document, { key: 'Enter' })
expect(onSearch).toHaveBeenCalledWith({
value: props.searchTerm
})
Expand All @@ -245,10 +247,11 @@ describe('SearchBarDropdown', () => {
data: []
})
})
it('should render the no results text', async () => {

it('should render the no results text', () => {
const { getByTestId } = renderSearchDropBarDropdown(props)

await waitFor(async () => {
return waitFor(() => {
expect(getByTestId(NO_RESULTS_DATA_TEST_ID)).toBeInTheDocument()
})
})
Expand Down Expand Up @@ -294,7 +297,8 @@ describe('SearchBarDropdown', () => {
...props,
onSearch
})
await waitFor(async () => {

await waitFor(() => {
expect(within(container).getByRole('link')).toHaveAttribute(
'href',
locations.account(MOCKED_CREATOR.address, {
Expand All @@ -314,16 +318,18 @@ describe('SearchBarDropdown', () => {
...props,
onSearch
})
await waitFor(async () => {

await waitFor(() => {
const link = within(container).getByRole('link')
await fireEvent.click(link)
fireEvent.click(link)
expect(localStorage.getItem(LOCAL_STORAGE_RECENT_SEARCHES_KEY)).toBe(JSON.stringify([MOCKED_CREATOR]))
})
})

it('should not render the see all button', async () => {
const { queryByTestId } = await renderAndSelectCreatorsTab(props)
await waitFor(async () => {

await waitFor(() => {
expect(queryByTestId(SEE_ALL_COLLECTIBLES_DATA_TEST_ID)).not.toBeInTheDocument()
})
})
Expand All @@ -335,10 +341,11 @@ describe('SearchBarDropdown', () => {
data: []
})
})
it('should render the no results text', async () => {

it('should render the no results text', () => {
const { getByTestId } = renderSearchDropBarDropdown(props)

await waitFor(async () => {
return waitFor(() => {
expect(getByTestId(NO_RESULTS_DATA_TEST_ID)).toBeInTheDocument()
})
})
Expand Down Expand Up @@ -381,9 +388,10 @@ describe('SearchBarDropdown', () => {
...props,
onSearch
})
await waitFor(async () => {

await waitFor(() => {
const collectionRow = within(container).getByTestId(`${COLLECTION_ROW_DATA_TEST_ID}-${MOCKED_COLLECTION.name}`)
await fireEvent.click(collectionRow)
fireEvent.click(collectionRow)
expect(onSearch).toHaveBeenCalledWith({
contractAddresses: [MOCKED_COLLECTION.contract_address]
})
Expand All @@ -397,17 +405,19 @@ describe('SearchBarDropdown', () => {
...props,
onSearch
})
await waitFor(async () => {

await waitFor(() => {
const collectionRow = within(container).getByTestId(`${COLLECTION_ROW_DATA_TEST_ID}-${MOCKED_COLLECTION.name}`)
await fireEvent.click(collectionRow)
fireEvent.click(collectionRow)
expect(localStorage.getItem(LOCAL_STORAGE_RECENT_SEARCHES_KEY)).toBe(JSON.stringify([MOCKED_COLLECTION]))
})
})
})

it('should not render the see all button', async () => {
const { queryByTestId } = await renderAndSelectCollectionsTab(props)
await waitFor(async () => {

await waitFor(() => {
expect(queryByTestId(SEE_ALL_COLLECTIBLES_DATA_TEST_ID)).not.toBeInTheDocument()
})
})
Expand All @@ -418,8 +428,9 @@ describe('SearchBarDropdown', () => {
...props,
onSearch
})
await waitFor(async () => {
await fireEvent.keyDown(document, { key: 'Enter' })

return waitFor(() => {
fireEvent.keyDown(document, { key: 'Enter' })
expect(onSearch).toHaveBeenCalledWith({
contractAddresses: [MOCKED_COLLECTION.contract_address],
value: ''
Expand All @@ -434,10 +445,11 @@ describe('SearchBarDropdown', () => {
data: []
})
})
it('should render the no results text', async () => {

it('should render the no results text', () => {
const { getByTestId } = renderSearchDropBarDropdown(props)

await waitFor(async () => {
return waitFor(() => {
expect(getByTestId(NO_RESULTS_DATA_TEST_ID)).toBeInTheDocument()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('FavoritesCounter', () => {
})

describe('and the counter has no favorites', () => {
it('should have the non clickable class', async () => {
it('should have the non clickable class', () => {
const { getByTestId } = renderFavoritesCounter({
onCounterClick,
count: 0,
Expand All @@ -197,7 +197,7 @@ describe('FavoritesCounter', () => {
})

describe('and the counter has favorites', () => {
it('should not have the non clickable class', async () => {
it('should not have the non clickable class', () => {
const { getByTestId } = renderFavoritesCounter({
onCounterClick,
count: 1000,
Expand All @@ -218,7 +218,7 @@ describe('FavoritesCounter', () => {
})

describe('and the item picking or unpicking process is being loaded', () => {
it('should have the non clickable class', async () => {
it('should have the non clickable class', () => {
const { getByTestId } = renderFavoritesCounter({
onCounterClick,
count: 0,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Menu/DropdownMenu/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useState } from 'react'
import { MenuItem } from '../../Menu/MenuItem'
import { Props } from './DropdownMenu.types'

const DropdownMenu = <T extends unknown>(props: Props<T>) => {
const DropdownMenu = <T,>(props: Props<T>) => {
const { values, currentValue, onMenuItemClick } = props
const [isDropdownOpen, setIsDropdownOpen] = useState(currentValue && values.includes(currentValue))

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Menu/MenuItem/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classNames from 'classnames'
import { Props } from './MenuItem.types'
import './MenuItem.css'

const MenuItem = <T extends unknown>(props: Props<T>) => {
const MenuItem = <T,>(props: Props<T>) => {
const { className = '', value, currentValue, subtitle, image, nestedLevel, withCaret, onClick } = props

const handleOnClick = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export const BuyWithCryptoModal = (props: Props) => {
wallet
])

const handleCrossChainBuy = useCallback(async () => {
const handleCrossChainBuy = useCallback(() => {
if (route && crossChainProvider && crossChainProvider.isLibInitialized()) {
onBuyCrossChain(route)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ describe('when loading the component', () => {
})

describe('and the list fetching fails', () => {
beforeEach(async () => {
beforeEach(() => {
jest.spyOn(FavoritesAPI.prototype, 'getLists').mockRejectedValueOnce(new Error('An error'))
await act(async () => {
act(() => {
renderedModal = renderSaveToListModalModal({ metadata: { item } })
})
})
Expand All @@ -70,7 +70,7 @@ describe('when loading the component', () => {
describe('and the list fetching succeeds', () => {
let lists: ListOfLists[]

beforeEach(async () => {
beforeEach(() => {
lists = [
{
id: 'aListId',
Expand All @@ -94,7 +94,7 @@ describe('when loading the component', () => {
results: lists,
total: 2
})
await act(async () => {
act(() => {
renderedModal = renderSaveToListModalModal({ metadata: { item } })
})
})
Expand Down Expand Up @@ -127,13 +127,13 @@ describe('when loading the component', () => {
describe('when clicking on the create list button', () => {
let onCreateList: jest.Mock

beforeEach(async () => {
beforeEach(() => {
onCreateList = jest.fn()
jest.spyOn(FavoritesAPI.prototype, 'getLists').mockResolvedValueOnce({
results: [],
total: 0
})
await act(async () => {
act(() => {
renderedModal = renderSaveToListModalModal({ onCreateList })
})
})
Expand All @@ -149,7 +149,7 @@ describe('when clicking on the create list button', () => {

describe('when saving the picks', () => {
let lists: ListOfLists[]
beforeEach(async () => {
beforeEach(() => {
lists = [
{
id: 'aListId',
Expand All @@ -165,7 +165,7 @@ describe('when saving the picks', () => {
total: 1
})

await act(async () => {
act(() => {
renderedModal = renderSaveToListModalModal({ isSavingPicks: true })
})
})
Expand Down
Loading
Loading