Skip to content

Commit

Permalink
chore: enforce types imports (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yovach authored Oct 11, 2023
1 parent c38b52e commit 1c15986
Show file tree
Hide file tree
Showing 22 changed files with 283 additions and 113 deletions.
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "import"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
Expand All @@ -14,7 +14,9 @@
],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/consistent-type-imports": ["error", { "fixStyle": "separate-type-imports" }],
"import/consistent-type-specifier-style": ["error", "prefer-top-level"]
},
"env": {
"browser": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/next-app/app/[locale]/client/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode } from 'react';
import type { ReactNode } from 'react';
import { Provider } from '../provider';

export default function Layout({ params: { locale }, children }: { params: { locale: string }; children: ReactNode }) {
Expand Down
2 changes: 1 addition & 1 deletion examples/next-app/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement } from 'react';
import type { ReactElement } from 'react';
import './globals.css';
import { Switch } from './switch';
import Link from 'next/link';
Expand Down
2 changes: 1 addition & 1 deletion examples/next-app/app/[locale]/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { ReactNode } from 'react';
import type { ReactNode } from 'react';
import { I18nProviderClient } from '../../locales/client';

type ProviderProps = {
Expand Down
2 changes: 1 addition & 1 deletion examples/next-app/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createI18nMiddleware } from 'next-international/middleware';
import { NextRequest } from 'next/server';
import type { NextRequest } from 'next/server';

const I18nMiddleware = createI18nMiddleware({
locales: ['en', 'fr'],
Expand Down
2 changes: 1 addition & 1 deletion examples/next-pages/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AppProps } from 'next/app';
import type { AppProps } from 'next/app';
import { I18nProvider } from '../locales';
import en from '../locales/en';

Expand Down
2 changes: 1 addition & 1 deletion examples/next-pages/pages/ssr-ssg.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetServerSideProps } from 'next';
import type { GetServerSideProps } from 'next';
import { getLocaleProps, useChangeLocale, useCurrentLocale, useI18n, useScopedI18n } from '../locales';

export const getServerSideProps: GetServerSideProps = getLocaleProps();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@vitest/coverage-v8": "^0.32.2",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "5.0.0-canary-7118f5dd7-20230705",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Context, ReactNode, Suspense, use, useMemo } from 'react';
import type { BaseLocale, ImportedLocales } from 'international-types';

import type { LocaleContext } from '../../types';
import type { Context, ReactNode } from 'react';
import React, { Suspense, use, useMemo } from 'react';
import { flattenLocale } from '../../common/flatten-locale';
import type { LocaleContext } from '../../types';

type I18nProviderProps = Omit<I18nProviderWrapperProps, 'fallback'>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { notFound, useParams } from 'next/navigation';
import { useMemo } from 'react';
import { DEFAULT_SEGMENT_NAME } from '../../common/constants';
import { I18nClientConfig } from '../../types';
import type { I18nClientConfig } from '../../types';
import { error } from '../../helpers/log';

export function createUseCurrentLocale<LocalesKeys>(locales: LocalesKeys[], config: I18nClientConfig) {
Expand Down
3 changes: 2 additions & 1 deletion packages/next-international/src/app/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';

import { LOCALE_COOKIE, LOCALE_HEADER } from '../../common/constants';
import type { I18nMiddlewareConfig } from '../../types';
Expand Down
4 changes: 2 additions & 2 deletions packages/next-international/src/app/server/create-get-i18n.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { BaseLocale, ImportedLocales } from 'international-types';
import { createT } from '../../common/create-t';
import { I18nServerConfig, LocaleContext } from '../../types';
import { getLocaleCache } from './get-locale-cache';
import { flattenLocale } from '../../common/flatten-locale';
import type { I18nServerConfig, LocaleContext } from '../../types';
import { getLocaleCache } from './get-locale-cache';

export function createGetI18n<Locales extends ImportedLocales, Locale extends BaseLocale>(
locales: Locales,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BaseLocale, ImportedLocales, Scopes } from 'international-types';
import { createT } from '../../common/create-t';
import { I18nServerConfig, LocaleContext } from '../../types';
import type { I18nServerConfig, LocaleContext } from '../../types';
import { getLocaleCache } from './get-locale-cache';
import { flattenLocale } from '../../common/flatten-locale';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ImportedLocales } from 'international-types';
import { I18nServerConfig } from '../../types';
import type { I18nServerConfig } from '../../types';
import { DEFAULT_SEGMENT_NAME } from '../../common/constants';

export function createGetStaticParams<Locales extends ImportedLocales>(locales: Locales, config: I18nServerConfig) {
Expand Down
4 changes: 2 additions & 2 deletions packages/next-international/src/app/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'server-only';

import type { ExplicitLocales, FlattenLocale, GetLocaleType, ImportedLocales } from 'international-types';
import type { I18nServerConfig } from '../../types';
import { createGetCurrentLocale } from './create-get-current-locale';
import { createGetI18n } from './create-get-i18n';
import { createGetScopedI18n } from './create-get-scoped-i18n';
import { createGetCurrentLocale } from './create-get-current-locale';
import { createGetStaticParams } from './create-get-static-params';
import { I18nServerConfig } from '../../types';

export { setStaticParamsLocale } from './get-locale-cache';

Expand Down
5 changes: 3 additions & 2 deletions packages/next-international/src/common/create-t.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isValidElement, cloneElement, ReactNode } from 'react';
import type {
BaseLocale,
CreateParams,
Expand All @@ -8,7 +7,9 @@ import type {
ScopedValue,
Scopes,
} from 'international-types';
import type { ReactParamsObject, LocaleContext, LocaleMap } from '../types';
import type { ReactNode } from 'react';
import { cloneElement, isValidElement } from 'react';
import type { LocaleContext, LocaleMap, ReactParamsObject } from '../types';

export function createT<Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined>(
context: LocaleContext<Locale>,
Expand Down
3 changes: 2 additions & 1 deletion packages/next-international/src/common/create-use-i18n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useContext, Context } from 'react';
import type { Context } from 'react';
import { useContext } from 'react';
import type { BaseLocale } from 'international-types';
import type { LocaleContext } from '../types';
import { createT } from './create-t';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useContext, Context } from 'react';
import type { Context } from 'react';
import { useContext } from 'react';
import type { BaseLocale, Scopes } from 'international-types';
import type { LocaleContext } from '../types';
import { createT } from '../common/create-t';
Expand Down
2 changes: 1 addition & 1 deletion packages/next-international/src/common/flatten-locale.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseLocale } from 'international-types';
import type { BaseLocale } from 'international-types';

export const flattenLocale = <Locale extends BaseLocale>(locale: Record<string, unknown>, prefix = ''): Locale =>
Object.entries(locale).reduce(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { Context, ReactElement, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import type { LocaleContext } from '../types';
import type { BaseLocale, ImportedLocales } from 'international-types';
import { useRouter } from 'next/router';
import { error, warn } from '../helpers/log';
import type { Context, ReactElement, ReactNode } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { flattenLocale } from '../common/flatten-locale';
import { error, warn } from '../helpers/log';
import type { LocaleContext } from '../types';

type I18nProviderProps<Locale extends BaseLocale> = {
locale: Locale;
Expand Down
2 changes: 1 addition & 1 deletion packages/next-international/src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext } from 'react';
import { ImportedLocales, ExplicitLocales, GetLocaleType, FlattenLocale } from 'international-types';
import type { ImportedLocales, ExplicitLocales, GetLocaleType, FlattenLocale } from 'international-types';
import type { LocaleContext } from '../types';
import { createDefineLocale } from '../common/create-define-locale';
import { createGetLocaleProps } from './create-get-locale-props';
Expand Down
Loading

0 comments on commit 1c15986

Please sign in to comment.