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

enhance: upgrade ts lint config #1169

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 10 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"impliedStrict": true,
"experimentalObjectRestSpread": true
},
"allowImportExportEverywhere": true
"allowImportExportEverywhere": true,
"project": ["**/tsconfig.json", "tsconfig.test.json"]
},
"plugins": ["@typescript-eslint", "react-hooks"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint",
Expand All @@ -32,16 +32,17 @@
"jest": true
},
"rules": {
"func-names": ["error", "as-needed"],
"no-shadow": "error",
"prefer-const": 0,
"func-names": [2, "as-needed"],
"no-shadow": 2,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/ban-ts-ignore": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-explicit-any": 0,
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
"@typescript-eslint/explicit-module-boundary-types": 0,
"react-hooks/rules-of-hooks": 2,
"react-hooks/exhaustive-deps": 1
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"@types/jest": "25.2.3",
"@types/node": "11.12.0",
"@types/react": "16.9.11",
"@typescript-eslint/eslint-plugin": "2.5.0",
"@typescript-eslint/parser": "2.5.0",
"@typescript-eslint/eslint-plugin": "4.24.0",
"@typescript-eslint/parser": "4.24.0",
"bunchee": "1.5.4",
"concurrently": "6.0.0",
"eslint": "6.6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function useStateWithDeps<Data, Error, S = State<Data, Error>>(
MutableRefObject<Record<StateKeys, boolean>>,
(payload: S) => void
] {
const rerender = useState<object>({})[1]
const rerender = useState<Record<string, unknown>>({})[1]
const stateRef = useRef(state)

// If a state property (data, error or isValidating) is accessed by the render
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ export type SWRInfiniteResponseInterface<Data = any, Error = any> = SWRResponse<
> & {
size: number
setSize: (
size: number | ((size: number) => number)
size: number | ((_size: number) => number)
) => Promise<Data[] | undefined>
}
export interface SWRInfiniteResponse<Data = any, Error = any>
extends SWRResponse<Data[], Error> {
size: number
setSize: (
size: number | ((size: number) => number)
size: number | ((_size: number) => number)
) => Promise<Data[] | undefined>
}

Expand Down
2 changes: 1 addition & 1 deletion src/use-swr-infinite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function useSWRInfinite<Data = any, Error = any>(
// get the serialized key of the first page
let firstPageKey: string | null = null
try {
;[firstPageKey] = serialize(getKey ? getKey(0, null) : null)
firstPageKey = serialize(getKey ? getKey(0, null) : null)[0]
} catch (err) {
// not ready
}
Expand Down
2 changes: 1 addition & 1 deletion src/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function useSWR<Data = any, Error = any>(
const { retryCount = 0, dedupe = false } = revalidateOpts

let loading = true
let shouldDeduping = !isUndefined(CONCURRENT_PROMISES[key]) && dedupe
const shouldDeduping = !isUndefined(CONCURRENT_PROMISES[key]) && dedupe

// start fetching
try {
Expand Down
6 changes: 3 additions & 3 deletions test/use-swr-infinite.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('useSWRInfinite', () => {

it('should support mutate and initialSize', async () => {
// mock api
let pageData = ['apple', 'banana', 'pineapple']
const pageData = ['apple', 'banana', 'pineapple']

function Page() {
const { data, mutate: boundMutate } = useSWRInfinite<string, string>(
Expand Down Expand Up @@ -399,7 +399,7 @@ describe('useSWRInfinite', () => {
await screen.findByText('data:page 0, page 1,')

// check all `setSize`s are referential equal.
for (let setSize of setters) {
for (const setSize of setters) {
expect(setSize).toEqual(setters[0])
}
})
Expand Down Expand Up @@ -450,7 +450,7 @@ describe('useSWRInfinite', () => {
'/api?page=1': ['page-1-1', 'page-1-2'],
'/api?page=2': ['page-2-1', 'page-2-2']
}
let requests = []
const requests = []

function Page() {
const { data, size, setSize } = useSWRInfinite<string[], string>(
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-local-mutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ describe('useSWR - local mutation', () => {
await act(() => sleep(50))

// check all `setSize`s are referential equal.
for (let ref of refs) {
for (const ref of refs) {
expect(ref).toEqual(refs[0])
}
})
Expand Down
24 changes: 4 additions & 20 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"jsx": "react",
"lib": ["esnext", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./dist",
"types": ["node", "jest"],
"target": "es5",
"typeRoots": ["./types", "./node_modules/@types"]
"rootDir": ".",
"strict": false
},
"include": ["src/**/*", "./jest-setup.ts"],
"watchOptions": {
"watchFile": "useFsEvents",
"watchDirectory": "useFsEvents",
"fallbackPolling": "dynamicPriority"
}
"include": ["test/**/*", "./jest-setup.ts"]
}
Loading