Skip to content
Draft
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
31 changes: 0 additions & 31 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion __tests__/fpjs-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vi.mock('@fingerprint/agent', { spy: true })
const mockStart = vi.mocked(agent.start)

describe('FingerprintProvider', () => {
it('should configure an instance of the Fp Agent', async () => {
it('should configure an instance of the Fp Agent', () => {
const loadOptions = getDefaultLoadOptions()
const wrapper = createWrapper({
cache: {
Expand Down
7 changes: 5 additions & 2 deletions __tests__/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ export const getDefaultLoadOptions = () => ({

export const createWrapper =
(providerProps: Partial<FingerprintProviderOptions> = {}) =>
({ children }: PropsWithChildren<{}>) => (
({ children }: PropsWithChildren<object>) => (
<FingerprintProvider {...getDefaultLoadOptions()} {...providerProps}>
{children}
</FingerprintProvider>
)

export const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
export const wait = (ms: number) =>
new Promise<void>((resolve) => {
setTimeout(resolve, ms)
})

export const actWait = async (ms: number) => {
await act(async () => {
Expand Down
25 changes: 20 additions & 5 deletions __tests__/use-visitor-data.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('useVisitorData', () => {
mockStart.mockReturnValue(mockAgent)
})

it('should provide the Fp context', async () => {
it('should provide the Fp context', () => {
const wrapper = createWrapper()
const {
result: { current },
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('useVisitorData', () => {
)
})

it("shouldn't call getData on mount if 'immediate' option is set to false", async () => {
it("shouldn't call getData on mount if 'immediate' option is set to false", () => {
mockGet.mockImplementation(() => mockGetResult)

const wrapper = createWrapper()
Expand Down Expand Up @@ -141,7 +141,13 @@ describe('useVisitorData', () => {

return (
<>
<button onClick={() => setTag((prev) => prev + 1)}>Change options</button>
<button
onClick={() => {
setTag((prev) => prev + 1)
}}
>
Change options
</button>
<pre>{JSON.stringify(data)}</pre>
</>
)
Expand All @@ -158,7 +164,8 @@ describe('useVisitorData', () => {
await actWait(1000)

act(() => {
userEvent.click(container.querySelector('button')!)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
void userEvent.click(container.querySelector('button')!)
})

await actWait(1000)
Expand Down Expand Up @@ -278,7 +285,13 @@ describe('useVisitorData', () => {
getDataValues.push(getData)
return (
<>
<button onClick={() => setCount((count) => count + 1)}>Increment count</button>
<button
onClick={() => {
setCount((count) => count + 1)
}}
>
Increment count
</button>
<pre>{JSON.stringify(data)}</pre>
</>
)
Expand All @@ -293,6 +306,7 @@ describe('useVisitorData', () => {
)

await act(async () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await userEvent.click(container.querySelector('button')!)
})

Expand All @@ -303,6 +317,7 @@ describe('useVisitorData', () => {
// in between renders if this click were in the previous act block.
// This ensures that the case is covered where the options
// object does not semantically change.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await userEvent.click(container.querySelector('button')!)
})

Expand Down
4 changes: 2 additions & 2 deletions __tests__/with-environment.preact.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe('WithEnvironment', () => {
})
it('should detect env as "preact"', async () => {
const { WithEnvironment } = await import('../src/components/with-environment')
const PrintEnv = (props: any) => h('div', null, props?.env?.name)
const PrintEnv = (props: { env?: { name: string } }) => h('div', null, props.env?.name)

// @ts-ignore
// @ts-expect-error -- preact's render signature does not match React's @testing-library/react types
const { container } = preactRender(h(WithEnvironment, null, h(PrintEnv, null)))

expect(container.innerHTML).toContain('preact')
Expand Down
5 changes: 3 additions & 2 deletions __tests__/with-environment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { describe, it, expect, vi } from 'vitest'

describe('WithEnvironment', () => {
it('enhances provided element with `env` prop', () => {
const Mock = vi.fn(() => <div>foo</div>) as FunctionComponent
const Mock: FunctionComponent = vi.fn(() => <div>foo</div>)

render(
<WithEnvironment>
Expand Down Expand Up @@ -56,7 +56,8 @@ describe('WithEnvironment', () => {
)

act(() => {
userEvent.click(container.querySelector('#test')!)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
void userEvent.click(container.querySelector('#test')!)
})

await actWait(250)
Expand Down
60 changes: 60 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { includeIgnoreFile } from 'eslint/config'
import path from 'path'
import { fileURLToPath } from 'url'
import cfg from '@fingerprintjs/eslint-config-dx-team/type-checked'
import tseslint from 'typescript-eslint'
import nextConfig from 'eslint-config-next/core-web-vitals'

const __dirname = fileURLToPath(new URL('.', import.meta.url))

const config = [
includeIgnoreFile(path.resolve(__dirname, '.gitignore')),
{ ignores: ['examples/'] },
...cfg,
...nextConfig,
// eslint-config-next overrides the parser to @babel/eslint-parser for all files, then
// restores @typescript-eslint/parser only for .ts/.tsx. Re-apply it here for .js files
// so that the ESLint v10-compatible scope manager is used everywhere.
{
files: ['**/*.{js,mjs,cjs,jsx}'],
languageOptions: { parser: tseslint.parser },
},
// Point the type-aware rules at a lint-only tsconfig that covers the tests and
// root config files, not just `src` (the build tsconfig). Must come after
// nextConfig so its parser swap doesn't strip the typed parser off .tsx files.
{
files: ['**/*.{ts,tsx,mts,cts}'],
languageOptions: {
parserOptions: {
project: './tsconfig.eslint.json',
tsconfigRootDir: __dirname,
},
},
},
// Pure-JS config/scripts can't join a TS program; disable the type-aware rules there.
{
files: ['**/*.{js,mjs,cjs,jsx}'],
...tseslint.configs.disableTypeChecked,
},
// vitest matchers like `expect.any()` return `any`, so asserting on mock call
// args trips no-unsafe-assignment. Relax it for tests only.
{
files: ['__tests__/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
},
},
{
settings: {
react: { version: '18.2' },
},
rules: {
'react/display-name': 'off',
'react/self-closing-comp': ['error', { component: true, html: true }],
'react/react-in-jsx-scope': 'off',
'@next/next/no-html-link-for-pages': 'off',
},
},
]

export default config
20 changes: 0 additions & 20 deletions examples/preact/.eslintrc.js

This file was deleted.

29 changes: 29 additions & 0 deletions examples/preact/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import tseslint from 'typescript-eslint'
import { fileURLToPath } from 'url'

const __dirname = fileURLToPath(new URL('.', import.meta.url))

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

const config = [
{ ignores: ['build/'] },
...compat.extends('preact'),
...tseslint.configs.recommended,
{
rules: {
semi: ['error', 'never'],
'linebreak-style': ['error', 'unix'],
'prefer-const': 'error',
'@typescript-eslint/no-unused-vars': ['error'],
curly: [2, 'all'],
},
},
]

export default config
6 changes: 3 additions & 3 deletions examples/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
"build": "preact build --no-sw",
"serve": "sirv build --port 8080 --cors --single",
"dev": "preact watch --no-sw",
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'"
"lint": "eslint --max-warnings 0"
},
"dependencies": {
"@fingerprint/react": "workspace:*",
"preact": "10.19.6",
"preact-render-to-string": "^6.4.0"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "*",
"@typescript-eslint/parser": "*",
"eslint": "*",
"eslint-config-preact": "*",
"typescript": "*"
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"typescript-eslint": "^8.60.0",
"dotenv": "^16.4.5",
"preact-cli": "^3.5.1",
"sirv-cli": "^2.0.2"
Expand Down
1 change: 0 additions & 1 deletion examples/preact/preact.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import dotenv from 'dotenv'

dotenv.config()

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default (config, env, helpers) => {
const { plugin } = helpers.getPluginsByName(config, 'DefinePlugin')[0]
plugin.definitions['process.env.PREACT_APP_FPJS_PUBLIC_API_KEY'] = JSON.stringify(
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"prepare": "husky install",
"watch": "vite build --watch",
"build": "vite build",
"lint": "eslint --ext .js,.ts,.tsx --ignore-path .gitignore --max-warnings 0 .",
"start:spa": "pnpm start --prefix=examples/spa",
"lint": "eslint --max-warnings 0",
"lint:fix": "pnpm lint --fix",
"test": "vitest",
"test:coverage": "vitest run --coverage",
Expand Down Expand Up @@ -70,7 +71,7 @@
"@commitlint/cli": "^19.2.0",
"@fingerprintjs/changesets-changelog-format": "^0.2.0",
"@fingerprintjs/commit-lint-dx-team": "^0.0.2",
"@fingerprintjs/eslint-config-dx-team": "^0.1.0",
"@fingerprintjs/eslint-config-dx-team": "^3.0.0",
"@fingerprintjs/prettier-config-dx-team": "^0.2.0",
"@fingerprintjs/tsconfig-dx-team": "^0.0.2",
"@testing-library/preact": "^3.2.4",
Expand All @@ -80,12 +81,13 @@
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@vitest/coverage-istanbul": "^4.0.18",
"eslint": "8.57.0",
"eslint-config-next": "14.1.3",
"eslint": "^10.4.1",
"eslint-config-next": "^16.2.0",
"@eslint/eslintrc": "^3.0.0",
"typescript-eslint": "^8.60.0",
"eslint-config-preact": "^1.3.0",
"eslint-plugin-prettier": "^5.5.5",
"eslint-plugin-react": "7.34.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react": "^7.37.0",
"eslint-plugin-react-hooks": "^7.0.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"preact": "^10.19.6",
Expand Down
Loading
Loading