Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/renovate-475bdf8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@scaleway/eslint-config-react': patch
---

Updated dependency `@typescript-eslint/eslint-plugin` to `6.4.0`.
Updated dependency `@typescript-eslint/parser` to `6.4.0`.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
},
"extends": ["@scaleway/react/typescript"],
"rules": {
"no-console": "off"
"no-console": "off",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-floating-promises": "warn"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
import {
afterEach,
beforeEach,
describe,
expect,
it,
jest,
} from '@jest/globals'
import fs from 'node:fs/promises'
import { simpleGit } from 'simple-git'
import { run } from '..'
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"license": "MIT",
"dependencies": {
"@emotion/eslint-plugin": "11.11.0",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@typescript-eslint/eslint-plugin": "6.4.0",
"@typescript-eslint/parser": "6.4.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-prettier": "9.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-config-react/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/no-floating-promises': 'error',
// https://github.com/typescript-eslint/typescript-eslint/issues/4619
'@typescript-eslint/no-misused-promises': [
'error',
Expand All @@ -38,10 +39,12 @@ module.exports = {
},
},
],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/no-redundant-type-constituents': 'warn',
// We favor object defaults instead of default props in TS
// https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/default_props/#you-may-not-need-defaultprops
// https://twitter.com/dan_abramov/status/1133878326358171650
Expand Down
9 changes: 8 additions & 1 deletion packages/outdated-browser/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { afterEach, beforeAll, describe, expect, jest, test } from '@jest/globals'
import {
afterEach,
beforeAll,
describe,
expect,
jest,
test,
} from '@jest/globals'

/**
* @jest-environment jsdom
Expand Down
25 changes: 18 additions & 7 deletions packages/use-dataloader/src/__tests__/dataloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ describe('Dataloader class', () => {
notifyChanges,
})
expect(method).toBeCalledTimes(0)
instance.load().catch(undefined)
instance.load().catch(undefined)
await instance.load()

// simulate multiple call in //
await Promise.all([
instance.load().catch(undefined),
instance.load().catch(undefined),
instance.load(),
])

expect(method).toBeCalledTimes(1)
instance.clearData()
})
Expand All @@ -71,7 +76,9 @@ describe('Dataloader class', () => {
})
expect(instance.getData()).toBe(undefined)
expect(notify).toBeCalledTimes(0)
instance.load().catch(undefined)

instance.load().catch(() => null)

expect(method).toBeCalledTimes(1)
instance.cancel()
expect(notify).toBeCalledTimes(0)
Expand Down Expand Up @@ -145,7 +152,9 @@ describe('Dataloader class', () => {
method,
notifyChanges,
})

instance.load().catch(undefined)

instance.cancel()
await waitForExpect(() => expect(instance.status).toBe(StatusEnum.IDLE))
expect(notifyChanges).toBeCalledTimes(1)
Expand Down Expand Up @@ -181,9 +190,11 @@ describe('Dataloader class', () => {
notifyChanges,
}),
)
instances.forEach(instance => {
instance.load().catch(undefined)
})

for await (const instance of instances) {
await instance.load().catch(() => null)
}

await waitForExpect(() => expect(method).toBeCalledTimes(5))
})
})
14 changes: 9 additions & 5 deletions packages/use-dataloader/src/useDataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export const useDataLoader = <ResultType = unknown, ErrorType = Error>(

useEffect(() => {
if (needLoad) {
request.load().then(onSuccessRef.current).catch(onErrorRef.current)
const defaultOnSuccessOrError = () => {}
const onSuccessLoad = onSuccessRef.current ?? defaultOnSuccessOrError
const onFailedLoad = onErrorRef.current ?? defaultOnSuccessOrError
request.load().then(onSuccessLoad).catch(onFailedLoad)
}
optimisticIsLoadingRef.current = false
}, [needLoad, request])
Expand All @@ -130,10 +133,11 @@ export const useDataLoader = <ResultType = unknown, ErrorType = Error>(
needPollingRef.current &&
!request.isCalled)
) {
request
.load(true)
.then(onSuccessRef.current)
.catch(onErrorRef.current)
const defaultOnSuccessOrError = () => {}
const onSuccessLoad = onSuccessRef.current ?? defaultOnSuccessOrError
const onFailedLoad = onErrorRef.current ?? defaultOnSuccessOrError

request.load(true).then(onSuccessLoad).catch(onFailedLoad)
}
}, pollingInterval)
}
Expand Down
9 changes: 8 additions & 1 deletion packages/use-gtm/src/__tests__/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
import {
afterEach,
beforeEach,
describe,
expect,
it,
jest,
} from '@jest/globals'
import { fireEvent, renderHook } from '@testing-library/react'
import mockdate from 'mockdate'
import type { ReactNode } from 'react'
Expand Down
9 changes: 8 additions & 1 deletion packages/use-i18n/src/__tests__/usei18n.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
import {
afterEach,
beforeEach,
describe,
expect,
it,
jest,
} from '@jest/globals'
import { act, renderHook, waitFor } from '@testing-library/react'
import mockdate from 'mockdate'
import type { ReactNode } from 'react'
Expand Down
2 changes: 1 addition & 1 deletion packages/use-media/src/useMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const createUseMedia =
effect(() => {
let mounted = true
const mediaQueryList: MediaQueryList =
typeof window === 'undefined' ||
typeof window !== 'undefined' &&
typeof window.matchMedia === 'undefined'
? mockMediaQueryList
: window.matchMedia(query)
Expand Down
11 changes: 6 additions & 5 deletions packages/use-storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ declare global {
}
}

const canUseDOM = !!(
const canUseDOM =
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.localStorage !== 'undefined' &&
typeof window.sessionStorage !== 'undefined'
)
!!(
typeof window.document !== 'undefined' &&
typeof window.localStorage !== 'undefined' &&
typeof window.sessionStorage !== 'undefined'
)

const subscribeStorage = (callback: () => void) => {
if (canUseDOM) {
Expand Down
Loading