Skip to content

Commit

Permalink
Add lint rule for inner { type } imports and fix all
Browse files Browse the repository at this point in the history
  • Loading branch information
OEvgeny committed Jan 19, 2024
1 parent 54774db commit 830ceee
Show file tree
Hide file tree
Showing 132 changed files with 251 additions and 217 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ overrides:

no-empty-function: off
'@typescript-eslint/no-empty-function': error

'@typescript-eslint/consistent-type-imports':
- error
- fixStyle: inline-type-imports

# TODO #4003: We will rework on these rules
'@typescript-eslint/ban-ts-comment': off
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/defaultStyleOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint no-magic-numbers: "off" */
import StyleOptions from './StyleOptions';
import type StyleOptions from './StyleOptions';

function fontFamily(fonts) {
return fonts.map(font => `'${font}'`).join(', ');
Expand Down
28 changes: 15 additions & 13 deletions packages/api/src/hooks/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,37 @@ import {
import { default as WebChatAPIContext } from './internal/WebChatAPIContext';
import ActivityAcknowledgementComposer from '../providers/ActivityAcknowledgement/ActivityAcknowledgementComposer';
import ActivityKeyerComposer from '../providers/ActivityKeyer/ActivityKeyerComposer';
import ActivityMiddleware from '../types/ActivityMiddleware';
import type ActivityMiddleware from '../types/ActivityMiddleware';
import ActivitySendStatusComposer from '../providers/ActivitySendStatus/ActivitySendStatusComposer';
import ActivitySendStatusTelemetryComposer from '../providers/ActivitySendStatusTelemetry/ActivitySendStatusTelemetryComposer';
import AttachmentForScreenReaderMiddleware from '../types/AttachmentForScreenReaderMiddleware';
import AttachmentMiddleware from '../types/AttachmentMiddleware';
import AvatarMiddleware from '../types/AvatarMiddleware';
import CardActionMiddleware from '../types/CardActionMiddleware';
import type AttachmentForScreenReaderMiddleware from '../types/AttachmentForScreenReaderMiddleware';
import type AttachmentMiddleware from '../types/AttachmentMiddleware';
import type AvatarMiddleware from '../types/AvatarMiddleware';
import type CardActionMiddleware from '../types/CardActionMiddleware';
import createCustomEvent from '../utils/createCustomEvent';
import createDefaultCardActionMiddleware from './middleware/createDefaultCardActionMiddleware';
import createDefaultGroupActivitiesMiddleware from './middleware/createDefaultGroupActivitiesMiddleware';
import defaultSelectVoice from './internal/defaultSelectVoice';
import ErrorBoundary from './utils/ErrorBoundary';
import getAllLocalizedStrings from '../localization/getAllLocalizedStrings';
import GroupActivitiesMiddleware from '../types/GroupActivitiesMiddleware';
import type GroupActivitiesMiddleware from '../types/GroupActivitiesMiddleware';
import isObject from '../utils/isObject';
import LocalizedStrings from '../types/LocalizedStrings';
import type LocalizedStrings from '../types/LocalizedStrings';
import mapMap from '../utils/mapMap';
import normalizeLanguage from '../utils/normalizeLanguage';
import normalizeStyleOptions from '../normalizeStyleOptions';
import observableToPromise from './utils/observableToPromise';
import patchStyleOptionsFromDeprecatedProps from '../patchStyleOptionsFromDeprecatedProps';
import PonyfillComposer from '../providers/Ponyfill/PonyfillComposer';
import PrecompiledGlobalizeType from '../types/PrecompiledGlobalize';
import ScrollToEndButtonMiddleware, { ScrollToEndButtonComponentFactory } from '../types/ScrollToEndButtonMiddleware';
import StyleOptions from '../StyleOptions';
import TelemetryMeasurementEvent, { TelemetryExceptionMeasurementEvent } from '../types/TelemetryMeasurementEvent';
import ToastMiddleware from '../types/ToastMiddleware';
import type PrecompiledGlobalizeType from '../types/PrecompiledGlobalize';
import { type ScrollToEndButtonComponentFactory } from '../types/ScrollToEndButtonMiddleware';
import type ScrollToEndButtonMiddleware from '../types/ScrollToEndButtonMiddleware';
import type StyleOptions from '../StyleOptions';
import { type TelemetryExceptionMeasurementEvent } from '../types/TelemetryMeasurementEvent';
import type TelemetryMeasurementEvent from '../types/TelemetryMeasurementEvent';
import type ToastMiddleware from '../types/ToastMiddleware';
import Tracker from './internal/Tracker';
import TypingIndicatorMiddleware from '../types/TypingIndicatorMiddleware';
import type TypingIndicatorMiddleware from '../types/TypingIndicatorMiddleware';
import useMarkAllAsAcknowledged from './useMarkAllAsAcknowledged';
import usePonyfill from '../hooks/usePonyfill';
import WebChatReduxContext, { useDispatch } from './internal/WebChatReduxContext';
Expand Down
26 changes: 13 additions & 13 deletions packages/api/src/hooks/internal/WebChatAPIContext.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { createContext } from 'react';

import { AttachmentForScreenReaderComponentFactory } from '../../types/AttachmentForScreenReaderMiddleware';
import { AvatarComponentFactory } from '../../types/AvatarMiddleware';
import { GroupActivities } from '../../types/GroupActivitiesMiddleware';
import { LegacyActivityRenderer } from '../../types/ActivityMiddleware';
import { PerformCardAction } from '../../types/CardActionMiddleware';
import { RenderActivityStatus } from '../../types/ActivityStatusMiddleware';
import { RenderAttachment } from '../../types/AttachmentMiddleware';
import { RenderToast } from '../../types/ToastMiddleware';
import { ScrollToEndButtonComponentFactory } from '../../types/ScrollToEndButtonMiddleware';
import { StrictStyleOptions } from '../../StyleOptions';
import LocalizedStrings from '../../types/LocalizedStrings';
import PrecompiledGlobalize from '../../types/PrecompiledGlobalize';
import TelemetryMeasurementEvent from '../../types/TelemetryMeasurementEvent';
import { type AttachmentForScreenReaderComponentFactory } from '../../types/AttachmentForScreenReaderMiddleware';
import { type AvatarComponentFactory } from '../../types/AvatarMiddleware';
import { type GroupActivities } from '../../types/GroupActivitiesMiddleware';
import { type LegacyActivityRenderer } from '../../types/ActivityMiddleware';
import { type PerformCardAction } from '../../types/CardActionMiddleware';
import { type RenderActivityStatus } from '../../types/ActivityStatusMiddleware';
import { type RenderAttachment } from '../../types/AttachmentMiddleware';
import { type RenderToast } from '../../types/ToastMiddleware';
import { type ScrollToEndButtonComponentFactory } from '../../types/ScrollToEndButtonMiddleware';
import { type StrictStyleOptions } from '../../StyleOptions';
import type LocalizedStrings from '../../types/LocalizedStrings';
import type PrecompiledGlobalize from '../../types/PrecompiledGlobalize';
import type TelemetryMeasurementEvent from '../../types/TelemetryMeasurementEvent';

import { type DirectLineJSBotConnection, type Observable, type WebChatActivity } from 'botframework-webchat-core';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isValidElement, useMemo } from 'react';

import { ActivityComponentFactory } from '../../types/ActivityMiddleware';
import { RenderAttachment } from '../../types/AttachmentMiddleware';
import { type ActivityComponentFactory } from '../../types/ActivityMiddleware';
import { type RenderAttachment } from '../../types/AttachmentMiddleware';
import useRenderAttachment from '../useRenderAttachment';
import useWebChatAPIContext from './useWebChatAPIContext';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/internal/useValueRef.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RefObject, useMemo, useRef } from 'react';
import { type RefObject, useMemo, useRef } from 'react';

export default function useValueRef<T>(value: T): RefObject<T> {
const ref = useRef<T>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sendMessage, sendMessageBack, sendPostBack } from 'botframework-webchat-core';

import CardActionMiddleware from '../../types/CardActionMiddleware';
import type CardActionMiddleware from '../../types/CardActionMiddleware';

export default function createDefaultCardActionMiddleware(): CardActionMiddleware {
return ({ dispatch }) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SENDING, SENT } from '../../types/internal/SendStatus';
import GroupActivitiesMiddleware from '../../types/GroupActivitiesMiddleware';
import type GroupActivitiesMiddleware from '../../types/GroupActivitiesMiddleware';

import { type GlobalScopePonyfill, type WebChatActivity } from 'botframework-webchat-core';
import { type SendStatus } from '../../types/internal/SendStatus';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useActiveTyping.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react';

import { useSelector } from './internal/WebChatReduxContext';
import Typing from '../types/Typing';
import type Typing from '../types/Typing';
import useForceRender from './internal/useForceRender';
import usePonyfill from './usePonyfill';
import useStyleOptions from './useStyleOptions';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useCreateActivityRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActivityComponentFactory } from '../types/ActivityMiddleware';
import { type ActivityComponentFactory } from '../types/ActivityMiddleware';
import useCreateActivityRendererInternal from './internal/useCreateActivityRendererInternal';

// The newer useCreateActivityRenderer() hook does not support override renderAttachment().
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScrollToEndButtonComponentFactory } from '../types/ScrollToEndButtonMiddleware';
import { type ScrollToEndButtonComponentFactory } from '../types/ScrollToEndButtonMiddleware';
import useWebChatAPIContext from './internal/useWebChatAPIContext';

export default function useCreateScrollToEndButtonRenderer(): ScrollToEndButtonComponentFactory {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useDebouncedNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRef } from 'react';
import updateIn from 'simple-update-in';

import findMin from '../utils/findMin';
import Notification from '../types/Notification';
import type Notification from '../types/Notification';
import useForceRender from './internal/useForceRender';
import useNotifications from './useNotifications';
import usePonyfill from './usePonyfill';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSelector } from './internal/WebChatReduxContext';
import Notification from '../types/Notification';
import type Notification from '../types/Notification';

export default function useNotifications(): [Notification[]] {
return [useSelector(({ notifications }) => notifications)];
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/usePerformCardAction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PerformCardAction } from '../types/CardActionMiddleware';
import { type PerformCardAction } from '../types/CardActionMiddleware';
import useWebChatAPIContext from './internal/useWebChatAPIContext';

export default function usePerformCardAction(): PerformCardAction {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/usePostActivity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Observable from 'core-js/features/observable';
import type Observable from 'core-js/features/observable';
import { type WebChatActivity } from 'botframework-webchat-core';

import useWebChatAPIContext from './internal/useWebChatAPIContext';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useRenderToast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RenderToast } from '../types/ToastMiddleware';
import { type RenderToast } from '../types/ToastMiddleware';
import useWebChatAPIContext from './internal/useWebChatAPIContext';

export default function useRenderToast(): RenderToast {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useRenderTypingIndicator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RenderTypingIndicator } from '../types/TypingIndicatorMiddleware';
import { type RenderTypingIndicator } from '../types/TypingIndicatorMiddleware';
import useWebChatAPIContext from './internal/useWebChatAPIContext';

export default function useRenderTypingIndicator(): RenderTypingIndicator {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useSetNotification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Notification from '../types/Notification';
import type Notification from '../types/Notification';
import useWebChatAPIContext from './internal/useWebChatAPIContext';

export default function useSetNotification(): (notification: Notification) => void {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useStyleOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StrictStyleOptions } from '../StyleOptions';
import { type StrictStyleOptions } from '../StyleOptions';
import useWebChatAPIContext from './internal/useWebChatAPIContext';

export default function useStyleOptions(): [StrictStyleOptions] {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/utils/observableToPromise.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Observable from 'core-js/features/observable';
import type Observable from 'core-js/features/observable';

import { type GlobalScopePonyfill } from 'botframework-webchat-core';

Expand Down
38 changes: 23 additions & 15 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import { localize } from './localization/Localize';
import * as hooks from './hooks';
import ActivityMiddleware, { ActivityComponentFactory } from './types/ActivityMiddleware';
import AttachmentForScreenReaderMiddleware, {
AttachmentForScreenReaderComponentFactory
} from './types/AttachmentForScreenReaderMiddleware';
import AttachmentMiddleware, { RenderAttachment } from './types/AttachmentMiddleware';
import AvatarMiddleware, { AvatarComponentFactory } from './types/AvatarMiddleware';
import CardActionMiddleware, { PerformCardAction } from './types/CardActionMiddleware';
import Composer, { ComposerProps } from './hooks/Composer';
import { type ActivityComponentFactory } from './types/ActivityMiddleware';
import type ActivityMiddleware from './types/ActivityMiddleware';
import { type AttachmentForScreenReaderComponentFactory } from './types/AttachmentForScreenReaderMiddleware';
import type AttachmentForScreenReaderMiddleware from './types/AttachmentForScreenReaderMiddleware';
import { type RenderAttachment } from './types/AttachmentMiddleware';
import type AttachmentMiddleware from './types/AttachmentMiddleware';
import { type AvatarComponentFactory } from './types/AvatarMiddleware';
import type AvatarMiddleware from './types/AvatarMiddleware';
import { type PerformCardAction } from './types/CardActionMiddleware';
import type CardActionMiddleware from './types/CardActionMiddleware';
import Composer, { type ComposerProps } from './hooks/Composer';
import concatMiddleware from './hooks/middleware/concatMiddleware';
import defaultStyleOptions from './defaultStyleOptions';
import GroupActivitiesMiddleware, { GroupActivities } from './types/GroupActivitiesMiddleware';
import { type GroupActivities } from './types/GroupActivitiesMiddleware';
import type GroupActivitiesMiddleware from './types/GroupActivitiesMiddleware';
import normalizeStyleOptions from './normalizeStyleOptions';
import ScrollToEndButtonMiddleware, { ScrollToEndButtonComponentFactory } from './types/ScrollToEndButtonMiddleware';
import StyleOptions, { StrictStyleOptions } from './StyleOptions';
import ToastMiddleware, { RenderToast } from './types/ToastMiddleware';
import TypingIndicatorMiddleware, { RenderTypingIndicator } from './types/TypingIndicatorMiddleware';
import WebSpeechPonyfill from './types/WebSpeechPonyfill';
import WebSpeechPonyfillFactory from './types/WebSpeechPonyfillFactory';
import { type ScrollToEndButtonComponentFactory } from './types/ScrollToEndButtonMiddleware';
import type ScrollToEndButtonMiddleware from './types/ScrollToEndButtonMiddleware';
import { type StrictStyleOptions } from './StyleOptions';
import type StyleOptions from './StyleOptions';
import { type RenderToast } from './types/ToastMiddleware';
import type ToastMiddleware from './types/ToastMiddleware';
import { type RenderTypingIndicator } from './types/TypingIndicatorMiddleware';
import type TypingIndicatorMiddleware from './types/TypingIndicatorMiddleware';
import type WebSpeechPonyfill from './types/WebSpeechPonyfill';
import type WebSpeechPonyfillFactory from './types/WebSpeechPonyfillFactory';

import { type ActivityStatusMiddleware, type RenderActivityStatus } from './types/ActivityStatusMiddleware';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/localization/getAllLocalizedStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import zhHK from './zh-HK.json';
import zhTW from './zh-TW.json';

import bundledOverrides from './overrides.json';
import LocalizedStrings from '../types/LocalizedStrings';
import type LocalizedStrings from '../types/LocalizedStrings';
import mergeLocalizedStrings from './mergeLocalizedStrings';

let localizedStrings;
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/localization/mergeLocalizedStrings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isForbiddenPropertyName } from 'botframework-webchat-core';

import LocalizedStrings from '../types/LocalizedStrings';
import type LocalizedStrings from '../types/LocalizedStrings';

type LocalizedStringsMap = { [language: string]: LocalizedStrings };

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/normalizeStyleOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { warnOnce } from 'botframework-webchat-core';

import defaultStyleOptions from './defaultStyleOptions';
import StyleOptions, { StrictStyleOptions } from './StyleOptions';
import { type StrictStyleOptions } from './StyleOptions';
import type StyleOptions from './StyleOptions';

const hideScrollToEndButtonDeprecation = warnOnce(
'"styleOptions.hideScrollToEndButton" has been deprecated. To hide scroll to end button, set "scrollToEndBehavior" to false. This deprecation migration will be removed on or after 2023-06-02.'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useMemo, useState, type PropsWithChildren, type ReactNode } from 'react';

import ActivityAcknowledgementContext, { ActivityAcknowledgementContextType } from './private/Context';
import ActivityAcknowledgementContext, { type ActivityAcknowledgementContextType } from './private/Context';
import findLastIndex from '../../utils/findLastIndex';
import useActivities from '../../hooks/useActivities';
import useActivityKeys from '../ActivityKeyer/useActivityKeys';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { type DirectLineAttachment, type WebChatActivity } from 'botframework-we

// TODO: We should consider using a prop for "attachmentMiddleware" to render for screen reader, instead of having another middleware.

import ComponentMiddleware, { ComponentFactory } from './ComponentMiddleware';
import { type ComponentFactory } from './ComponentMiddleware';
import type ComponentMiddleware from './ComponentMiddleware';

type AttachmentForScreenReaderComponentFactoryOptions = [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/types/AvatarMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type WebChatActivity } from 'botframework-webchat-core';

import { StrictStyleOptions } from '../StyleOptions';
import { type StrictStyleOptions } from '../StyleOptions';
import type ComponentMiddleware from './ComponentMiddleware';
import { type ComponentFactory } from './ComponentMiddleware';

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/types/CardActionMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type DirectLineCardAction } from 'botframework-webchat-core';

import FunctionMiddleware from './FunctionMiddleware';
import type FunctionMiddleware from './FunctionMiddleware';

type PerformCardAction = (cardAction: DirectLineCardAction, event?: { target: EventTarget }) => void;

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/types/ComponentMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode } from 'react';
import { type ReactNode } from 'react';

type OnScreenReactNode = Exclude<ReactNode, boolean | null | undefined>;

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/types/GroupActivitiesMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type WebChatActivity } from 'botframework-webchat-core';

import FunctionMiddleware, { CallFunction } from './FunctionMiddleware';
import { type CallFunction } from './FunctionMiddleware';
import type FunctionMiddleware from './FunctionMiddleware';

type GroupActivities = CallFunction<
[{ activities: WebChatActivity[] }],
Expand Down
5 changes: 3 additions & 2 deletions packages/api/src/types/ScrollToEndButtonMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StrictStyleOptions } from '../StyleOptions';
import ComponentMiddleware, { ComponentFactory } from './ComponentMiddleware';
import { type StrictStyleOptions } from '../StyleOptions';
import { type ComponentFactory } from './ComponentMiddleware';
import type ComponentMiddleware from './ComponentMiddleware';

/**
* @type {object}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/types/ToastMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode } from 'react';
import { type ReactNode } from 'react';

import Notification from './Notification';
import type Notification from './Notification';

type ToastProps = {
notification: Notification;
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/types/TypingIndicatorMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode } from 'react';
import { type ReactNode } from 'react';

import Typing from './Typing';
import type Typing from './Typing';

type TypingIndicatorProps = {
activeTyping: { [id: string]: Typing };
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/types/WebSpeechPonyfillFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WebSpeechPonyfill from './WebSpeechPonyfill';
import type WebSpeechPonyfill from './WebSpeechPonyfill';

type WebSpeechPonyfillFactory = ({ referenceGrammarID }: { referenceGrammarID?: string }) => WebSpeechPonyfill;

Expand Down
Loading

0 comments on commit 830ceee

Please sign in to comment.