Skip to content

Commit

Permalink
fix: Linting rules one (no-empty, no-yield, no-case-declarations and …
Browse files Browse the repository at this point in the history
…no-unused-vars) (#2181)

* fix: No empty rule

* fix: No yield rule

* fix: Fix no case declarations rule

* fix: No unused vars & correct linting script in CI
  • Loading branch information
LautaroPetaccio authored Mar 12, 2024
1 parent 2cce14f commit ff19a8b
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Install
run: npm install --legacy-peer-deps
- name: Lint
run: npm run lint
run: npm run check:code
4 changes: 0 additions & 4 deletions webapp/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = {
'@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/
'@typescript-eslint/no-unused-vars': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unused-vars
'@typescript-eslint/no-unnecessary-type-assertion': 'error', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unnecessary-type-assertion
'@typescript-eslint/explicit-module-boundary-types': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/explicit-module-boundary-types
'@typescript-eslint/restrict-template-expressions': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/restrict-template-expressions
Expand All @@ -26,7 +25,6 @@ module.exports = {
'@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
'no-case-declarations': 'off', // TODO: migrate code progressively to remove this line. https://eslint.org/docs/rules/no-case-declarations
'@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/
Expand All @@ -37,9 +35,7 @@ module.exports = {
'@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
'require-yield': 'off', // TODO: migrate code progressively to remove this line. https://eslint.org/docs/rules/require-yield
'import/order': 'off', // TODO: migrate code progressively to remove this line.
'no-empty': 'off', // TODO: migrate code progressively to remove this line. https://eslint.org/docs/rules/no-empty
'@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
1 change: 0 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"build": "tsc && node --max_old_space_size=8192 ./node_modules/vite/bin/vite.js build",
"test": "jest",
"test:coverage": "npm run test -- --coverage",
"lint": "eslint -c .eslintrc.cjs --ext .ts src",
"check:code": "eslint -c .eslintrc.cjs src",
"fix:code": "npm run check:code -- --fix",
"pre-commit:fix:code": "eslint -c .eslintrc.cjs --fix",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export const BuyWithCryptoModal = (props: Props) => {
<span className={styles.warning}>
{t('buy_with_crypto_modal.insufficient_funds', {
token: insufficientToken?.symbol || 'MANA',
card: (text: string) => onBuyWithCard ? <span>{text}</span> : undefined
card: (text: string) => (onBuyWithCard ? <span>{text}</span> : undefined)
})}
</span>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useLocation } from 'react-router-dom'
import classNames from 'classnames'
import { Button, Close, Container, Field, Icon, Loader, Popup, useTabletAndBelowMediaQuery } from 'decentraland-ui'
import { isErrorWithMessage } from 'decentraland-dapps/dist/lib'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { config } from '../../../config'
import infoIcon from '../../../images/infoIcon.png'
Expand Down Expand Up @@ -51,7 +52,9 @@ const ClaimNamePage = (props: Props) => {
try {
const bannedNames = await lists.fetchBannedNames()
setBannedNames(bannedNames)
} catch (error) {}
} catch (error) {
console.error('Error fetching banned names', isErrorWithMessage(error) ? error.message : 'Unknown error')
}
})()
}, [])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ const AssetCell = ({ asset, link: linkProp }: Props) => {
let subtitle: string | undefined

switch (asset.category) {
case NFTCategory.ESTATE:
case NFTCategory.ESTATE: {
subtitle = t('global.parcel_count', {
count: asset.data.estate!.parcels.length
})
break
case NFTCategory.PARCEL:
}
case NFTCategory.PARCEL: {
const { x, y } = asset.data.parcel!
subtitle = `${x},${y}`
break
}
}

const link = linkProp
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/RankingsTable/RankingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const RankingsTable = (props: Props) => {
const getTableHeader = () => {
switch (currentEntity) {
case RankingEntities.EMOTES:
case RankingEntities.WEARABLES:
case RankingEntities.WEARABLES: {
const label = currentEntity === RankingEntities.EMOTES ? 'emotes' : 'wearables'
return (
<Table.Header>
Expand Down Expand Up @@ -179,6 +179,7 @@ const RankingsTable = (props: Props) => {
</Table.Row>
</Table.Header>
)
}
case RankingEntities.CREATORS:
return (
<Table.Header>
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/lib/timer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('when the timer is running', () => {
describe("and the timer hasn't finished", () => {
it('should return isRunning as true', async () => {
const { result } = renderHook(() => useTimer(1200))
const [_, startTimer] = result.current
const [, startTimer] = result.current

act(() => {
startTimer()
Expand All @@ -38,7 +38,7 @@ describe('when the timer is running', () => {
it('should return isRunning as false', async () => {
runTimerAutomaticallyOnce()
const { result } = renderHook(() => useTimer(1200))
const [_, startTimer] = result.current
const [, startTimer] = result.current

act(() => {
startTimer()
Expand All @@ -53,7 +53,7 @@ describe('when the timer is running', () => {
describe('and the timer is re-started', () => {
it('should re-start the timeout procedure', () => {
const { result } = renderHook(() => useTimer(1200))
const [_, startTimer] = result.current
const [, startTimer] = result.current

act(() => {
startTimer()
Expand Down
9 changes: 6 additions & 3 deletions webapp/src/modules/analytics/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,29 @@ type AnalyticsReducerAction =

export function analyticsReducer(state = INITIAL_STATE, action: AnalyticsReducerAction): AnalyticsState {
switch (action.type) {
case FETCH_ANALYTICS_VOLUME_DATA_REQUEST:
case FETCH_ANALYTICS_VOLUME_DATA_REQUEST: {
return {
...state,
loading: loadingReducer(state.loading, action)
}
case FETCH_ANALYTICS_VOLUME_DATA_SUCCESS:
}
case FETCH_ANALYTICS_VOLUME_DATA_SUCCESS: {
const { analyticsVolumeData } = action.payload
return {
...state,
loading: loadingReducer(state.loading, action),
error: null,
volumeData: analyticsVolumeData
}
case FETCH_ANALYTICS_VOLUME_DATA_FAILURE:
}
case FETCH_ANALYTICS_VOLUME_DATA_FAILURE: {
const { error } = action.payload
return {
...state,
loading: loadingReducer(state.loading, action),
error
}
}
case FETCH_RANKINGS_REQUEST: {
return {
...state,
Expand Down
15 changes: 8 additions & 7 deletions webapp/src/modules/collection/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ type CollectionReducerAction =
export function collectionReducer(state = INITIAL_STATE, action: CollectionReducerAction): CollectionState {
switch (action.type) {
case FETCH_COLLECTIONS_REQUEST:
case FETCH_SINGLE_COLLECTION_REQUEST:
case FETCH_SINGLE_COLLECTION_REQUEST: {
return {
...state,
loading: loadingReducer(state.loading, action)
}

case FETCH_COLLECTIONS_SUCCESS:
}
case FETCH_COLLECTIONS_SUCCESS: {
const { collections, count } = action.payload

return {
Expand All @@ -62,8 +62,8 @@ export function collectionReducer(state = INITIAL_STATE, action: CollectionReduc
),
count
}

case FETCH_SINGLE_COLLECTION_SUCCESS:
}
case FETCH_SINGLE_COLLECTION_SUCCESS: {
const { collection } = action.payload

return {
Expand All @@ -72,16 +72,17 @@ export function collectionReducer(state = INITIAL_STATE, action: CollectionReduc
error: null,
data: { ...state.data, [collection.urn]: collection }
}

}
case FETCH_COLLECTIONS_FAILURE:
case FETCH_SINGLE_COLLECTION_FAILURE:
case FETCH_SINGLE_COLLECTION_FAILURE: {
const { error } = action.payload

return {
...state,
loading: loadingReducer(state.loading, action),
error
}
}
default:
return state
}
Expand Down
9 changes: 6 additions & 3 deletions webapp/src/modules/event/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ type EventReducerAction = FetchEventRequestAction | FetchEventSuccessAction | Fe

export function eventReducer(state = INITIAL_STATE, action: EventReducerAction): EventState {
switch (action.type) {
case FETCH_EVENT_REQUEST:
case FETCH_EVENT_REQUEST: {
return {
...state,
loading: loadingReducer(state.loading, action)
}
case FETCH_EVENT_SUCCESS:
}
case FETCH_EVENT_SUCCESS: {
const { eventTag, contracts } = action.payload
return {
...state,
Expand All @@ -40,13 +41,15 @@ export function eventReducer(state = INITIAL_STATE, action: EventReducerAction):
[eventTag]: contracts
}
}
case FETCH_EVENT_FAILURE:
}
case FETCH_EVENT_FAILURE: {
const { error } = action.payload
return {
...state,
loading: loadingReducer(state.loading, action),
error
}
}
default:
return state
}
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/modules/favorites/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function favoritesReducer(state = INITIAL_STATE, action: FavoritesReducer
}
}

case FETCH_ITEMS_SUCCESS:
case FETCH_ITEMS_SUCCESS: {
const { items } = action.payload

return {
Expand All @@ -158,7 +158,7 @@ export function favoritesReducer(state = INITIAL_STATE, action: FavoritesReducer
},
loading: loadingReducer(state.loading, action)
}

}
case FETCH_FAVORITED_ITEMS_SUCCESS: {
const { items, createdAt } = action.payload

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/modules/identity/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ function* handleConnectWalletSuccess(action: ConnectWalletSuccessAction) {

function* handleDisconnect(_action: DisconnectWalletAction) {
if (auxAddress) {
localStorageClearIdentity(auxAddress)
yield localStorageClearIdentity(auxAddress)
}
}
4 changes: 2 additions & 2 deletions webapp/src/modules/nft/hooks.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ describe('when the nft is not an estate', () => {

it('should return contractFingerprint as undefined', () => {
const { result } = renderHook(() => useFingerprint(nft))
const [_contract, _isLoading, contractFingerprint] = result.current
const [, , contractFingerprint] = result.current
expect(contractFingerprint).toBe(undefined)
})

it('should return loading as false', () => {
const { result } = renderHook(() => useFingerprint(nft))
const [_contract, isLoading] = result.current
const [, isLoading] = result.current
expect(isLoading).toBe(false)
})
})
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/modules/routing/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export function* fetchAssetsFromRoute(options: BrowseOptions) {
})
)
break
default:
default: {
const isWearableHead = section === Sections[VendorName.DECENTRALAND].WEARABLES_HEAD
const isWearableAccessory = section === Sections[VendorName.DECENTRALAND].WEARABLES_ACCESSORIES

Expand Down Expand Up @@ -313,6 +313,7 @@ export function* fetchAssetsFromRoute(options: BrowseOptions) {
})
)
}
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions webapp/src/modules/sale/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ type SaleReducerAction = FetchSalesRequestAction | FetchSalesSuccessAction | Fet

export function saleReducer(state = INITIAL_STATE, action: SaleReducerAction): SaleState {
switch (action.type) {
case FETCH_SALES_REQUEST:
case FETCH_SALES_REQUEST: {
return {
...state,
loading: loadingReducer(state.loading, action)
}
case FETCH_SALES_SUCCESS:
}
case FETCH_SALES_SUCCESS: {
const { sales, count } = action.payload
return {
...state,
Expand All @@ -47,13 +48,15 @@ export function saleReducer(state = INITIAL_STATE, action: SaleReducerAction): S
),
count
}
case FETCH_SALES_FAILURE:
}
case FETCH_SALES_FAILURE: {
const { error } = action.payload
return {
...state,
loading: loadingReducer(state.loading, action),
error
}
}
default:
return state
}
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/modules/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ export function storeReducer(state = INITIAL_STATE, action: StoreReducerAction):
error
}
}
case UPDATE_LOCAL_STORE:
case UPDATE_LOCAL_STORE: {
const { store } = action.payload
return {
...state,
localStore: store
}
}
case REVERT_LOCAL_STORE: {
const { address } = action.payload
const previous = state.data[address]
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/modules/ui/browse/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ export function browseReducer(state: BrowseUIState = INITIAL_STATE, action: UIRe
}
}

case BULK_PICK_SUCCESS:
case BULK_PICK_SUCCESS: {
const { ownerRemovedFromCurrentList } = action.payload

return {
...state,
count: state.count !== undefined && ownerRemovedFromCurrentList ? --state.count : state.count
}

}
case BROWSE: {
const { view } = action.payload.options
return {
Expand Down Expand Up @@ -168,7 +168,7 @@ export function browseReducer(state: BrowseUIState = INITIAL_STATE, action: UIRe
itemIds: isLoadingMoreResults(state, action.payload.options.page) ? state.itemIds : []
}

case FETCH_FAVORITED_ITEMS_SUCCESS:
case FETCH_FAVORITED_ITEMS_SUCCESS: {
const {
timestamp,
options: { page },
Expand All @@ -189,7 +189,7 @@ export function browseReducer(state: BrowseUIState = INITIAL_STATE, action: UIRe
page: forceLoadMore ? state.page : page,
count: total
}

}
case FETCH_ITEMS_SUCCESS: {
const {
timestamp,
Expand Down
Loading

0 comments on commit ff19a8b

Please sign in to comment.