Skip to content

Commit 7d89d54

Browse files
authored
chore: Strict type imports with ESLint (#1524)
1 parent f44ae15 commit 7d89d54

Some content is hidden

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

57 files changed

+187
-151
lines changed

packages/next-intl/eslint.config.mjs

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export default (await getPresets('typescript', 'react', 'vitest')).concat({
2121
}
2222
]
2323
}
24-
]
24+
],
25+
26+
// Strict type imports to avoid side effects
27+
'@typescript-eslint/consistent-type-imports': 'error',
28+
'@typescript-eslint/consistent-type-exports': 'error',
29+
'@typescript-eslint/no-import-type-side-effects': 'error',
30+
'import/no-duplicates': ['error', {'prefer-inline': true}]
2531
}
2632
});

packages/next-intl/src/middleware/getAlternateLinksHeaderValue.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {NextRequest} from 'next/server.js';
44
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
55
import {receiveRoutingConfig} from '../routing/config.tsx';
6-
import {Pathnames} from '../routing.tsx';
6+
import type {Pathnames} from '../routing.tsx';
77
import getAlternateLinksHeaderValue from './getAlternateLinksHeaderValue.tsx';
88

99
describe.each([{basePath: undefined}, {basePath: '/base'}])(

packages/next-intl/src/middleware/getAlternateLinksHeaderValue.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {NextRequest} from 'next/server.js';
2-
import {ResolvedRoutingConfig} from '../routing/config.tsx';
3-
import {
1+
import type {NextRequest} from 'next/server.js';
2+
import type {ResolvedRoutingConfig} from '../routing/config.tsx';
3+
import type {
44
DomainsConfig,
55
LocalePrefixMode,
66
Locales,

packages/next-intl/src/middleware/middleware.test.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
import {RequestCookies} from 'next/dist/compiled/@edge-runtime/cookies';
44
import {NextRequest, NextResponse} from 'next/server.js';
55
import {pathToRegexp} from 'path-to-regexp';
6-
import {Mock, afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
6+
import {
7+
type Mock,
8+
afterEach,
9+
beforeEach,
10+
describe,
11+
expect,
12+
it,
13+
vi
14+
} from 'vitest';
715
import createMiddleware from '../middleware.tsx';
8-
import {Pathnames, defineRouting} from '../routing.tsx';
16+
import {type Pathnames, defineRouting} from '../routing.tsx';
917

1018
const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';
1119

packages/next-intl/src/middleware/middleware.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {NextRequest, NextResponse} from 'next/server.js';
2-
import {RoutingConfig, receiveRoutingConfig} from '../routing/config.tsx';
3-
import {
1+
import {type NextRequest, NextResponse} from 'next/server.js';
2+
import {type RoutingConfig, receiveRoutingConfig} from '../routing/config.tsx';
3+
import type {
44
DomainsConfig,
55
LocalePrefixMode,
66
Locales,

packages/next-intl/src/middleware/resolveLocale.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {match} from '@formatjs/intl-localematcher';
22
import Negotiator from 'negotiator';
3-
import {RequestCookies} from 'next/dist/server/web/spec-extension/cookies.js';
3+
import type {RequestCookies} from 'next/dist/server/web/spec-extension/cookies.js';
44
import type {Locale} from 'use-intl';
5-
import {ResolvedRoutingConfig} from '../routing/config.tsx';
6-
import {
5+
import type {ResolvedRoutingConfig} from '../routing/config.tsx';
6+
import type {
77
DomainConfig,
88
DomainsConfig,
99
LocalePrefixMode,

packages/next-intl/src/middleware/syncCookie.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {NextRequest, NextResponse} from 'next/server.js';
1+
import type {NextRequest, NextResponse} from 'next/server.js';
22
import type {Locale} from 'use-intl';
3-
import {
3+
import type {
44
InitializedLocaleCookieConfig,
55
ResolvedRoutingConfig
66
} from '../routing/config.tsx';
7-
import {
7+
import type {
88
DomainConfig,
99
DomainsConfig,
1010
LocalePrefixMode,

packages/next-intl/src/middleware/utils.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {Locale} from 'use-intl';
2-
import {
2+
import type {
33
DomainConfig,
44
DomainsConfig,
55
LocalePrefixConfigVerbose,

packages/next-intl/src/navigation/createNavigation.test.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import {
55
redirect as nextRedirect
66
} from 'next/navigation.js';
77
import {renderToString} from 'react-dom/server';
8-
import {Locale, useLocale} from 'use-intl';
8+
import {type Locale, useLocale} from 'use-intl';
99
import {beforeEach, describe, expect, it, vi} from 'vitest';
10-
import {DomainsConfig, Pathnames, defineRouting} from '../routing.tsx';
10+
import {
11+
type DomainsConfig,
12+
type Pathnames,
13+
defineRouting
14+
} from '../routing.tsx';
1115
import createNavigationClient from './react-client/createNavigation.tsx';
1216
import createNavigationServer from './react-server/createNavigation.tsx';
1317
import getServerLocale from './react-server/getServerLocale.tsx';

packages/next-intl/src/navigation/react-client/createNavigation.test.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import {
33
usePathname as useNextPathname,
44
useRouter as useNextRouter
55
} from 'next/navigation.js';
6-
import type {Locale} from 'use-intl';
7-
import {useLocale} from 'use-intl';
6+
import {type Locale, useLocale} from 'use-intl';
87
import {beforeEach, describe, expect, it, vi} from 'vitest';
9-
import {DomainsConfig, Pathnames} from '../../routing.tsx';
8+
import type {DomainsConfig, Pathnames} from '../../routing.tsx';
109
import createNavigation from './createNavigation.tsx';
1110

1211
vi.mock('next/navigation.js');

packages/next-intl/src/navigation/react-client/createNavigation.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import {
44
} from 'next/navigation.js';
55
import {useMemo} from 'react';
66
import {type Locale, useLocale} from 'use-intl';
7-
import {
7+
import type {
88
RoutingConfigLocalizedNavigation,
99
RoutingConfigSharedNavigation
1010
} from '../../routing/config.tsx';
11-
import {
11+
import type {
1212
DomainsConfig,
1313
LocalePrefixMode,
1414
Locales,

packages/next-intl/src/navigation/react-client/useBasePathname.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {usePathname as useNextPathname} from 'next/navigation.js';
22
import {useMemo} from 'react';
33
import {useLocale} from 'use-intl';
4-
import {
4+
import type {
55
LocalePrefixConfigVerbose,
66
LocalePrefixMode,
77
Locales

packages/next-intl/src/navigation/react-server/createNavigation.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {
1+
import type {
22
RoutingConfigLocalizedNavigation,
33
RoutingConfigSharedNavigation
44
} from '../../routing/config.tsx';
5-
import {
5+
import type {
66
DomainsConfig,
77
LocalePrefixMode,
88
Locales,

packages/next-intl/src/navigation/shared/BaseLink.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use client';
22

3-
import NextLink, {LinkProps} from 'next/link.js';
3+
import NextLink, {type LinkProps} from 'next/link.js';
44
import {usePathname} from 'next/navigation.js';
55
import {
6-
ComponentProps,
7-
MouseEvent,
8-
Ref,
6+
type ComponentProps,
7+
type MouseEvent,
8+
type Ref,
99
forwardRef,
1010
useEffect,
1111
useState
1212
} from 'react';
1313
import {type Locale, useLocale} from 'use-intl';
14-
import {InitializedLocaleCookieConfig} from '../../routing/config.tsx';
14+
import type {InitializedLocaleCookieConfig} from '../../routing/config.tsx';
1515
import syncLocaleCookie from './syncLocaleCookie.tsx';
1616

1717
type NextLinkProps = Omit<ComponentProps<'a'>, keyof LinkProps> &

packages/next-intl/src/navigation/shared/createSharedNavigationFns.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ import {
22
permanentRedirect as nextPermanentRedirect,
33
redirect as nextRedirect
44
} from 'next/navigation.js';
5-
import {ComponentProps, forwardRef} from 'react';
5+
import {type ComponentProps, forwardRef} from 'react';
66
import type {Locale} from 'use-intl';
77
import {
8-
RoutingConfigLocalizedNavigation,
9-
RoutingConfigSharedNavigation,
8+
type RoutingConfigLocalizedNavigation,
9+
type RoutingConfigSharedNavigation,
1010
receiveRoutingConfig
1111
} from '../../routing/config.tsx';
12-
import {
12+
import type {
1313
DomainConfig,
1414
DomainsConfig,
1515
LocalePrefixMode,
1616
Locales,
1717
Pathnames
1818
} from '../../routing/types.tsx';
19-
import {ParametersExceptFirst, Prettify} from '../../shared/types.tsx';
19+
import type {ParametersExceptFirst, Prettify} from '../../shared/types.tsx';
2020
import use from '../../shared/use.tsx';
2121
import {isLocalizableHref} from '../../shared/utils.tsx';
2222
import BaseLink from './BaseLink.tsx';
2323
import {
24-
HrefOrHrefWithParams,
25-
HrefOrUrlObjectWithParams,
26-
QueryParams,
24+
type HrefOrHrefWithParams,
25+
type HrefOrUrlObjectWithParams,
26+
type QueryParams,
2727
applyPathnamePrefix,
2828
compileLocalizedPathname,
2929
normalizeNameOrNameWithParams,

packages/next-intl/src/navigation/shared/syncLocaleCookie.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {Locale} from 'use-intl';
2-
import {InitializedLocaleCookieConfig} from '../../routing/config.tsx';
2+
import type {InitializedLocaleCookieConfig} from '../../routing/config.tsx';
33
import {getBasePath} from './utils.tsx';
44

55
/**

packages/next-intl/src/navigation/shared/utils.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type {ParsedUrlQueryInput} from 'node:querystring';
22
import type {UrlObject} from 'url';
33
import type {Locale} from 'use-intl';
4-
import {ResolvedRoutingConfig} from '../../routing/config.tsx';
5-
import {
4+
import type {ResolvedRoutingConfig} from '../../routing/config.tsx';
5+
import type {
66
DomainsConfig,
77
LocalePrefixMode,
88
Locales,
@@ -16,7 +16,7 @@ import {
1616
normalizeTrailingSlash,
1717
prefixPathname
1818
} from '../../shared/utils.tsx';
19-
import StrictParams from './StrictParams.tsx';
19+
import type StrictParams from './StrictParams.tsx';
2020

2121
type SearchParamValue = ParsedUrlQueryInput[keyof ParsedUrlQueryInput];
2222

packages/next-intl/src/plugin/getNextConfig.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import {NextConfig} from 'next';
4-
import {PluginConfig} from './types.tsx';
3+
import type {NextConfig} from 'next';
4+
import type {PluginConfig} from './types.tsx';
55
import {throwError} from './utils.tsx';
66

77
function withExtensions(localPath: string) {

packages/next-intl/src/react-server/NextIntlClientProviderServer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ComponentProps} from 'react';
1+
import type {ComponentProps} from 'react';
22
import getConfigNow from '../server/react-server/getConfigNow.tsx';
33
import getFormats from '../server/react-server/getFormats.tsx';
44
import {getLocale, getTimeZone} from '../server.react-server.tsx';

packages/next-intl/src/react-server/testUtils.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import {ReactNode, Suspense} from 'react';
2-
import {ReactDOMServerReadableStream} from 'react-dom/server';
1+
import {type ReactNode, Suspense} from 'react';
2+
import type {ReactDOMServerReadableStream} from 'react-dom/server';
33
// @ts-expect-error -- Not available in types
44
import {renderToReadableStream as _renderToReadableStream} from 'react-dom/server.browser';
55

6+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
67
const renderToReadableStream: typeof import('react-dom/server').renderToReadableStream =
78
_renderToReadableStream;
89

packages/next-intl/src/routing/config.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {NextResponse} from 'next/server.js';
2-
import {
2+
import type {
33
DomainsConfig,
44
LocalePrefix,
55
LocalePrefixConfigVerbose,

packages/next-intl/src/routing/defineRouting.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import {RoutingConfig} from './config.tsx';
2-
import {DomainsConfig, LocalePrefixMode, Locales, Pathnames} from './types.tsx';
1+
import type {RoutingConfig} from './config.tsx';
2+
import type {
3+
DomainsConfig,
4+
LocalePrefixMode,
5+
Locales,
6+
Pathnames
7+
} from './types.tsx';
38

49
export default function defineRouting<
510
const AppLocales extends Locales,

packages/next-intl/src/routing/types.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
import {describe, it} from 'vitest';
3-
import {DomainConfig, LocalePrefix} from './types.tsx';
3+
import type {DomainConfig, LocalePrefix} from './types.tsx';
44

55
describe('LocalePrefix', () => {
66
it('does not require a type param for simple values', () => {

packages/next-intl/src/server/react-server/RequestLocale.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {headers} from 'next/headers.js';
22
import {cache} from 'react';
3-
import {Locale} from 'use-intl';
3+
import type {Locale} from 'use-intl';
44
import {HEADER_LOCALE_NAME} from '../../shared/constants.tsx';
55
import {getCachedRequestLocale} from './RequestLocaleCache.tsx';
66

packages/next-intl/src/server/react-server/getConfig.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {cache} from 'react';
22
import {
3-
IntlConfig,
3+
type IntlConfig,
44
type Locale,
55
_createCache,
66
_createIntlFormatters,
77
initializeConfig
88
} from 'use-intl/core';
99
import {getRequestLocale} from './RequestLocale.tsx';
1010
import createRequestConfig from './createRequestConfig.tsx';
11-
import {GetRequestConfigParams} from './getRequestConfig.tsx';
11+
import type {GetRequestConfigParams} from './getRequestConfig.tsx';
1212

1313
// This is automatically inherited by `NextIntlClientProvider` if
1414
// the component is rendered from a Server Component

packages/next-intl/src/server/react-server/getFormatter.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {cache} from 'react';
2-
import {type Locale, createFormatter} from 'use-intl/core';
2+
import type {Locale, createFormatter} from 'use-intl/core';
33
import getConfig from './getConfig.tsx';
44
import getServerFormatter from './getServerFormatter.tsx';
55

packages/next-intl/src/server/react-server/getLocale.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {cache} from 'react';
2-
import {Locale} from 'use-intl';
2+
import type {Locale} from 'use-intl';
33
import getConfig from './getConfig.tsx';
44

55
async function getLocaleCachedImpl(): Promise<Locale> {

packages/next-intl/src/server/react-server/getServerTranslator.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {cache} from 'react';
22
import {
3-
Messages,
4-
NamespaceKeys,
5-
NestedKeyOf,
3+
type Messages,
4+
type NamespaceKeys,
5+
type NestedKeyOf,
66
createTranslator
77
} from 'use-intl/core';
88

packages/next-intl/src/server/react-server/getTranslations.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {cache} from 'react';
2-
import {
2+
import type {
33
Locale,
44
Messages,
55
NamespaceKeys,

packages/next-intl/src/shared/NextIntlClientProvider.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

3-
import {ComponentProps} from 'react';
4-
import {type Locale} from 'use-intl';
3+
import type {ComponentProps} from 'react';
4+
import type {Locale} from 'use-intl';
55
import {IntlProvider} from 'use-intl/react';
66

77
type Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {

packages/next-intl/src/shared/utils.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {LinkProps} from 'next/link.js';
2-
import {
1+
import type {LinkProps} from 'next/link.js';
2+
import type {
33
LocalePrefixConfigVerbose,
44
LocalePrefixMode,
55
Locales

packages/use-intl/eslint.config.mjs

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export default (await getPresets('typescript', 'react', 'vitest')).concat({
66
'react-compiler': reactCompilerPlugin
77
},
88
rules: {
9-
'react-compiler/react-compiler': 'error'
9+
'react-compiler/react-compiler': 'error',
10+
11+
// Strict type imports to avoid side effects
12+
'@typescript-eslint/consistent-type-imports': 'error',
13+
'@typescript-eslint/consistent-type-exports': 'error',
14+
'@typescript-eslint/no-import-type-side-effects': 'error',
15+
'import/no-duplicates': ['error', {'prefer-inline': true}]
1016
}
1117
});

0 commit comments

Comments
 (0)