Skip to content

Commit 37b750e

Browse files
authored
Merge pull request #2422 from oasisprotocol/mz/lintWarnings-3
Fix lint warnings around components
2 parents d2762a0 + 16e42fe commit 37b750e

44 files changed

Lines changed: 361 additions & 335 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changelog/2422.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix lint warnings around components

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const config = {
6262
'react/display-name': 'off', // TODO: Maybe enable
6363
'react/self-closing-comp': ['error', { component: true, html: true }],
6464

65-
'react-refresh/only-export-components': ['warn', { allowConstantExport: true /* vite */ }],
65+
'react-refresh/only-export-components': ['error', { allowConstantExport: true /* vite */ }],
6666

6767
'@typescript-eslint/no-empty-function': 'off', // Allow empty reducers for saga
6868
'@typescript-eslint/no-non-null-assertion': 'off',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"clean": "rm -rf build/ node_modules/.vite/",
1212
"start": "vite",
1313
"checkTs": "tsc --noEmit",
14-
"lint": "eslint --ext js,ts,tsx ./",
14+
"lint": "eslint --ext js,ts,tsx ./ --max-warnings 0",
1515
"lint:fix": "yarn run lint --fix",
1616
"lint-git": "node ./internals/scripts/gitlint.js",
1717
"lint-docs": "markdownlint --ignore '**/node_modules/**' '**/*.md'",

src/app/components/HighlightedText/HighlightedTrimmedText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC } from 'react'
22

33
import { HighlightedText, HighlightOptions } from './index'
4-
import { useHighlightPattern } from '../PatternHighlightingContext'
4+
import { useHighlightPattern } from '../PatternHighlightingContext/hooks'
55
import { trimAroundMatch } from './text-trimming'
66

77
type HighlightedTrimmedTextProps = {

src/app/components/HighlightedText/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22
import { findTextMatches, NormalizerOptions, PositiveMatchInfo } from './text-matching'
33
import { FC, ReactNode } from 'react'
4-
import { useHighlightPattern } from '../PatternHighlightingContext'
4+
import { useHighlightPattern } from '../PatternHighlightingContext/hooks'
55

66
export interface HighlightOptions {
77
/**
@@ -12,8 +12,6 @@ export interface HighlightOptions {
1212

1313
export type HighlightPattern = string[]
1414

15-
export const NoHighlights: HighlightPattern = []
16-
1715
interface HighlightedTextProps {
1816
/**
1917
* The text to display

src/app/components/HoverHighlightingContext/WithHoverHighlighting.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FC, ReactNode, useEffect } from 'react'
2-
import { useHoverHighlighting } from './index'
2+
import { useHoverHighlighting } from './hooks'
33
import { useScreenSize } from '../../hooks/useScreensize'
44
import { cn } from '@oasisprotocol/ui-library/src/lib/utils'
55

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createContext } from 'react'
2+
3+
export interface HoverHighlightingContextInfo {
4+
shouldHighlight: (address: string) => boolean
5+
selectAddress: (value: string) => void
6+
releaseAddress: (value: string) => void
7+
}
8+
9+
export const HoverHighlightingContext = createContext<HoverHighlightingContextInfo | null>(null)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useContext } from 'react'
2+
import { HoverHighlightingContext, HoverHighlightingContextInfo } from './context'
3+
4+
const noContext: HoverHighlightingContextInfo = {
5+
shouldHighlight: () => false,
6+
selectAddress: () => {},
7+
releaseAddress: () => {},
8+
}
9+
10+
export const useHoverHighlighting = () => {
11+
const context = useContext(HoverHighlightingContext)
12+
if (!context) {
13+
console.log('Warning: highlighting context is not provided!')
14+
return noContext
15+
}
16+
return context
17+
}
Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
import { createContext, FC, ReactNode, useContext, useState } from 'react'
1+
import { FC, ReactNode, useState } from 'react'
2+
import { HoverHighlightingContext } from './context'
23
import { getEvmBech32Address, isValidEthAddress } from '../../utils/helpers'
34

4-
interface HoverHighlightingContextInfo {
5-
shouldHighlight: (address: string) => boolean
6-
selectAddress: (value: string) => void
7-
releaseAddress: (value: string) => void
8-
}
9-
10-
const HoverHighlightingContext = createContext<HoverHighlightingContextInfo | null>(null)
11-
12-
const noContext: HoverHighlightingContextInfo = {
13-
shouldHighlight: () => false,
14-
selectAddress: () => {},
15-
releaseAddress: () => {},
16-
}
17-
185
/**
196
* Convert highlight address to a uniform format:
207
*/
@@ -43,12 +30,3 @@ export const HoverHighlightingContextProvider: FC<{ children: ReactNode }> = ({
4330
</HoverHighlightingContext.Provider>
4431
)
4532
}
46-
47-
export const useHoverHighlighting = () => {
48-
const context = useContext(HoverHighlightingContext)
49-
if (!context) {
50-
console.log('Warning: highlighting context is not provided!')
51-
return noContext
52-
}
53-
return context
54-
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createContext } from 'react'
2+
import { HighlightPattern } from '../HighlightedText'
3+
4+
export const PatternHighlightingContext = createContext<{
5+
readonly highlightPattern: HighlightPattern
6+
} | null>(null)

0 commit comments

Comments
 (0)