build: enable consistent type imports eslint rule (#7992)

* build: enable consistent type imports eslint rule

* change to warn

* fix the warning in example and excalidraw-app

* fix packages

* enable type annotations and throw error for the rule
This commit is contained in:
Aakansha Doshi 2024-05-08 14:21:50 +05:30 committed by GitHub
parent c1926f33bb
commit 1ed53b153c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
240 changed files with 635 additions and 611 deletions

View file

@ -1,6 +1,6 @@
import { AppState } from "../types";
import type { AppState } from "../types";
import { sceneCoordsToViewportCoords } from "../utils";
import { ElementsMap, NonDeletedExcalidrawElement } from "./types";
import type { ElementsMap, NonDeletedExcalidrawElement } from "./types";
import { getElementAbsoluteCoords } from ".";
import { useExcalidrawAppState } from "../components/App";

View file

@ -4,7 +4,7 @@ import * as GADirection from "../gadirections";
import * as GALine from "../galines";
import * as GATransform from "../gatransforms";
import {
import type {
ExcalidrawBindableElement,
ExcalidrawElement,
ExcalidrawRectangleElement,
@ -25,7 +25,7 @@ import {
} from "./types";
import { getElementAbsoluteCoords } from "./bounds";
import { AppClassProperties, AppState, Point } from "../types";
import type { AppClassProperties, AppState, Point } from "../types";
import { isPointOnShape } from "../../utils/collision";
import { getElementAtPosition } from "../scene";
import {
@ -36,7 +36,8 @@ import {
isLinearElement,
isTextElement,
} from "./typeChecks";
import { ElementUpdate, mutateElement } from "./mutateElement";
import type { ElementUpdate } from "./mutateElement";
import { mutateElement } from "./mutateElement";
import Scene from "../scene/Scene";
import { LinearElementEditor } from "./linearElementEditor";
import { arrayToMap, tupleToCoors } from "../utils";

View file

@ -1,7 +1,7 @@
import { ROUNDNESS } from "../constants";
import { arrayToMap } from "../utils";
import { getElementAbsoluteCoords, getElementBounds } from "./bounds";
import { ExcalidrawElement, ExcalidrawLinearElement } from "./types";
import type { ExcalidrawElement, ExcalidrawLinearElement } from "./types";
const _ce = ({
x,

View file

@ -1,4 +1,4 @@
import {
import type {
ExcalidrawElement,
ExcalidrawLinearElement,
Arrowhead,
@ -9,8 +9,8 @@ import {
} from "./types";
import { distance2d, rotate, rotatePoint } from "../math";
import rough from "roughjs/bin/rough";
import { Drawable, Op } from "roughjs/bin/core";
import { AppState, Point } from "../types";
import type { Drawable, Op } from "roughjs/bin/core";
import type { AppState, Point } from "../types";
import { generateRoughOptions } from "../scene/Shape";
import {
isArrowElement,
@ -22,7 +22,7 @@ import {
import { rescalePoints } from "../points";
import { getBoundTextElement, getContainerElement } from "./textElement";
import { LinearElementEditor } from "./linearElementEditor";
import { Mutable } from "../utility-types";
import type { Mutable } from "../utility-types";
import { ShapeCache } from "../scene/ShapeCache";
import { arrayToMap } from "../utils";

View file

@ -1,18 +1,15 @@
import { isPathALoop, isPointWithinBounds } from "../math";
import {
import type {
ElementsMap,
ExcalidrawElement,
ExcalidrawRectangleElement,
} from "./types";
import { getElementBounds } from "./bounds";
import { FrameNameBounds } from "../types";
import {
Polygon,
GeometricShape,
getPolygonShape,
} from "../../utils/geometry/shape";
import type { FrameNameBounds } from "../types";
import type { Polygon, GeometricShape } from "../../utils/geometry/shape";
import { getPolygonShape } from "../../utils/geometry/shape";
import { isPointInShape, isPointOnShape } from "../../utils/collision";
import { isTransparent } from "../utils";
import {

View file

@ -1,4 +1,4 @@
import { ExcalidrawTextContainer } from "./types";
import type { ExcalidrawTextContainer } from "./types";
export const originalContainerCache: {
[id: ExcalidrawTextContainer["id"]]:

View file

@ -1,12 +1,13 @@
import { updateBoundElements } from "./binding";
import { Bounds, getCommonBounds } from "./bounds";
import type { Bounds } from "./bounds";
import { getCommonBounds } from "./bounds";
import { mutateElement } from "./mutateElement";
import { getPerfectElementSize } from "./sizeHelpers";
import { NonDeletedExcalidrawElement } from "./types";
import { AppState, PointerDownState } from "../types";
import type { NonDeletedExcalidrawElement } from "./types";
import type { AppState, PointerDownState } from "../types";
import { getBoundTextElement } from "./textElement";
import { getGridPoint } from "../math";
import Scene from "../scene/Scene";
import type Scene from "../scene/Scene";
import { isArrowElement, isFrameLikeElement } from "./typeChecks";
export const dragSelectedElements = (

View file

@ -1,18 +1,18 @@
import { register } from "../actions/register";
import { FONT_FAMILY, VERTICAL_ALIGN } from "../constants";
import { ExcalidrawProps } from "../types";
import type { ExcalidrawProps } from "../types";
import { getFontString, updateActiveTool } from "../utils";
import { setCursorForShape } from "../cursor";
import { newTextElement } from "./newElement";
import { wrapText } from "./textElement";
import { isIframeElement } from "./typeChecks";
import {
import type {
ExcalidrawElement,
ExcalidrawIframeLikeElement,
IframeData,
} from "./types";
import { sanitizeHTMLAttribute } from "../data/url";
import { MarkRequired } from "../utility-types";
import type { MarkRequired } from "../utility-types";
import { StoreAction } from "../store";
type IframeDataWithSandbox = MarkRequired<IframeData, "sandbox">;

View file

@ -3,9 +3,9 @@
// -----------------------------------------------------------------------------
import { MIME_TYPES, SVG_NS } from "../constants";
import { AppClassProperties, DataURL, BinaryFiles } from "../types";
import type { AppClassProperties, DataURL, BinaryFiles } from "../types";
import { isInitializedImageElement } from "./typeChecks";
import {
import type {
ExcalidrawElement,
FileId,
InitializedExcalidrawImageElement,

View file

@ -1,4 +1,4 @@
import {
import type {
ExcalidrawElement,
NonDeletedExcalidrawElement,
NonDeleted,

View file

@ -1,4 +1,4 @@
import {
import type {
NonDeleted,
ExcalidrawLinearElement,
ExcalidrawElement,
@ -22,13 +22,13 @@ import {
arePointsEqual,
} from "../math";
import { getElementAbsoluteCoords, getLockedLinearCursorAlignSize } from ".";
import type { Bounds } from "./bounds";
import {
Bounds,
getCurvePathOps,
getElementPointsCoords,
getMinMaxXYFromCurvePathOps,
} from "./bounds";
import {
import type {
Point,
AppState,
PointerCoords,
@ -47,9 +47,9 @@ import { isBindingElement } from "./typeChecks";
import { KEYS, shouldRotateWithDiscreteAngle } from "../keys";
import { getBoundTextElement, handleBindTextResize } from "./textElement";
import { DRAGGING_THRESHOLD } from "../constants";
import { Mutable } from "../utility-types";
import type { Mutable } from "../utility-types";
import { ShapeCache } from "../scene/ShapeCache";
import { Store } from "../store";
import type { Store } from "../store";
const editorMidPointsCache: {
version: number | null;

View file

@ -1,10 +1,10 @@
import { ExcalidrawElement } from "./types";
import type { ExcalidrawElement } from "./types";
import Scene from "../scene/Scene";
import { getSizeFromPoints } from "../points";
import { randomInteger } from "../random";
import { Point } from "../types";
import type { Point } from "../types";
import { getUpdatedTimestamp } from "../utils";
import { Mutable } from "../utility-types";
import type { Mutable } from "../utility-types";
import { ShapeCache } from "../scene/ShapeCache";
export type ElementUpdate<TElement extends ExcalidrawElement> = Omit<

View file

@ -3,7 +3,7 @@ import { mutateElement } from "./mutateElement";
import { API } from "../tests/helpers/api";
import { FONT_FAMILY, ROUNDNESS } from "../constants";
import { isPrimitive } from "../utils";
import { ExcalidrawLinearElement } from "./types";
import type { ExcalidrawLinearElement } from "./types";
const assertCloneObjects = (source: any, clone: any) => {
for (const key in clone) {

View file

@ -1,4 +1,4 @@
import {
import type {
ExcalidrawElement,
ExcalidrawImageElement,
ExcalidrawTextElement,
@ -27,7 +27,7 @@ import {
import { randomInteger, randomId } from "../random";
import { bumpVersion, newElementWith } from "./mutateElement";
import { getNewGroupIdsForDuplication } from "../groups";
import { AppState } from "../types";
import type { AppState } from "../types";
import { getElementAbsoluteCoords } from ".";
import { adjustXYWithRotation } from "../math";
import { getResizedElementAbsoluteCoords } from "./bounds";
@ -46,7 +46,7 @@ import {
DEFAULT_VERTICAL_ALIGN,
VERTICAL_ALIGN,
} from "../constants";
import { MarkOptional, Merge, Mutable } from "../utility-types";
import type { MarkOptional, Merge, Mutable } from "../utility-types";
export type ElementConstructorOpts = MarkOptional<
Omit<ExcalidrawGenericElement, "id" | "type" | "isDeleted" | "updated">,

View file

@ -2,7 +2,7 @@ import { MIN_FONT_SIZE, SHIFT_LOCKING_ANGLE } from "../constants";
import { rescalePoints } from "../points";
import { rotate, centerPoint, rotatePoint } from "../math";
import {
import type {
ExcalidrawLinearElement,
ExcalidrawTextElement,
NonDeletedExcalidrawElement,
@ -31,11 +31,11 @@ import {
import { mutateElement } from "./mutateElement";
import { getFontString } from "../utils";
import { updateBoundElements } from "./binding";
import {
import type {
MaybeTransformHandleType,
TransformHandleDirection,
} from "./transformHandles";
import { Point, PointerDownState } from "../types";
import type { Point, PointerDownState } from "../types";
import Scene from "../scene/Scene";
import {
getApproxMinLineWidth,

View file

@ -1,28 +1,31 @@
import {
import type {
ExcalidrawElement,
PointerType,
NonDeletedExcalidrawElement,
ElementsMap,
} from "./types";
import {
getTransformHandlesFromCoords,
getTransformHandles,
import type {
TransformHandleType,
TransformHandle,
MaybeTransformHandleType,
} from "./transformHandles";
import {
getTransformHandlesFromCoords,
getTransformHandles,
getOmitSidesForDevice,
canResizeFromSides,
} from "./transformHandles";
import { AppState, Device, Zoom } from "../types";
import { Bounds, getElementAbsoluteCoords } from "./bounds";
import type { AppState, Device, Zoom } from "../types";
import type { Bounds } from "./bounds";
import { getElementAbsoluteCoords } from "./bounds";
import { SIDE_RESIZING_THRESHOLD } from "../constants";
import {
angleToDegrees,
pointOnLine,
pointRotate,
} from "../../utils/geometry/geometry";
import { Line, Point } from "../../utils/geometry/shape";
import type { Line, Point } from "../../utils/geometry/shape";
import { isLinearElement } from "./typeChecks";
const isInsideTransformHandle = (

View file

@ -1,6 +1,6 @@
import { NonDeletedExcalidrawElement } from "./types";
import type { NonDeletedExcalidrawElement } from "./types";
import { getSelectedElements } from "../scene";
import { UIAppState } from "../types";
import type { UIAppState } from "../types";
export const showSelectedShapeActions = (
appState: UIAppState,

View file

@ -1,8 +1,8 @@
import { ElementsMap, ExcalidrawElement } from "./types";
import type { ElementsMap, ExcalidrawElement } from "./types";
import { mutateElement } from "./mutateElement";
import { isFreeDrawElement, isLinearElement } from "./typeChecks";
import { SHIFT_LOCKING_ANGLE } from "../constants";
import { AppState, Zoom } from "../types";
import type { AppState, Zoom } from "../types";
import { getElementBounds } from "./bounds";
import { viewportCoordsToSceneCoords } from "../utils";

View file

@ -1,7 +1,7 @@
import { API } from "../tests/helpers/api";
import { mutateElement } from "./mutateElement";
import { normalizeElementOrder } from "./sortElements";
import { ExcalidrawElement } from "./types";
import type { ExcalidrawElement } from "./types";
const assertOrder = (
elements: readonly ExcalidrawElement[],

View file

@ -1,5 +1,5 @@
import { arrayToMapWithIndex } from "../utils";
import { ExcalidrawElement } from "./types";
import type { ExcalidrawElement } from "./types";
const normalizeGroupElementOrder = (elements: readonly ExcalidrawElement[]) => {
const origElements: ExcalidrawElement[] = elements.slice();

View file

@ -11,7 +11,7 @@ import {
getDefaultLineHeight,
parseTokens,
} from "./textElement";
import { ExcalidrawTextElementWithContainer, FontString } from "./types";
import type { ExcalidrawTextElementWithContainer, FontString } from "./types";
describe("Test wrapText", () => {
const font = "20px Cascadia, width: Segoe UI Emoji" as FontString;

View file

@ -1,5 +1,5 @@
import { getFontString, arrayToMap, isTestEnv, normalizeEOL } from "../utils";
import {
import type {
ElementsMap,
ExcalidrawElement,
ExcalidrawElementType,
@ -21,16 +21,16 @@ import {
TEXT_ALIGN,
VERTICAL_ALIGN,
} from "../constants";
import { MaybeTransformHandleType } from "./transformHandles";
import type { MaybeTransformHandleType } from "./transformHandles";
import { isTextElement } from ".";
import { isBoundToContainer, isArrowElement } from "./typeChecks";
import { LinearElementEditor } from "./linearElementEditor";
import { AppState } from "../types";
import type { AppState } from "../types";
import {
resetOriginalContainerCache,
updateOriginalContainerCache,
} from "./containerCache";
import { ExtractSetType, MakeBrand } from "../utility-types";
import type { ExtractSetType, MakeBrand } from "../utility-types";
export const normalizeText = (text: string) => {
return (

View file

@ -11,7 +11,7 @@ import {
import { queryByText } from "@testing-library/react";
import { FONT_FAMILY, TEXT_ALIGN, VERTICAL_ALIGN } from "../constants";
import {
import type {
ExcalidrawTextElement,
ExcalidrawTextElementWithContainer,
} from "./types";

View file

@ -12,13 +12,13 @@ import {
isTextElement,
} from "./typeChecks";
import { CLASSES } from "../constants";
import {
import type {
ExcalidrawElement,
ExcalidrawLinearElement,
ExcalidrawTextElementWithContainer,
ExcalidrawTextElement,
} from "./types";
import { AppState } from "../types";
import type { AppState } from "../types";
import { bumpVersion, mutateElement } from "./mutateElement";
import {
getBoundTextElementId,
@ -39,7 +39,7 @@ import {
actionIncreaseFontSize,
} from "../actions/actionProperties";
import { actionZoomIn, actionZoomOut } from "../actions/actionCanvas";
import App from "../components/App";
import type App from "../components/App";
import { LinearElementEditor } from "./linearElementEditor";
import { parseClipboard } from "../clipboard";
import {

View file

@ -1,13 +1,14 @@
import {
import type {
ElementsMap,
ExcalidrawElement,
NonDeletedExcalidrawElement,
PointerType,
} from "./types";
import { Bounds, getElementAbsoluteCoords } from "./bounds";
import type { Bounds } from "./bounds";
import { getElementAbsoluteCoords } from "./bounds";
import { rotate } from "../math";
import { Device, InteractiveCanvasAppState, Zoom } from "../types";
import type { Device, InteractiveCanvasAppState, Zoom } from "../types";
import { isTextElement } from ".";
import { isFrameLikeElement, isLinearElement } from "./typeChecks";
import {

View file

@ -1,8 +1,8 @@
import { ROUNDNESS } from "../constants";
import { ElementOrToolType } from "../types";
import { MarkNonNullable } from "../utility-types";
import type { ElementOrToolType } from "../types";
import type { MarkNonNullable } from "../utility-types";
import { assertNever } from "../utils";
import {
import type {
ExcalidrawElement,
ExcalidrawTextElement,
ExcalidrawEmbeddableElement,

View file

@ -1,13 +1,13 @@
import { Point } from "../types";
import {
import type { Point } from "../types";
import type {
FONT_FAMILY,
ROUNDNESS,
TEXT_ALIGN,
THEME,
VERTICAL_ALIGN,
} from "../constants";
import { MakeBrand, MarkNonNullable, ValueOf } from "../utility-types";
import { MagicCacheData } from "../data/magic";
import type { MakeBrand, MarkNonNullable, ValueOf } from "../utility-types";
import type { MagicCacheData } from "../data/magic";
export type ChartType = "bar" | "line";
export type FillStyle = "hachure" | "cross-hatch" | "solid" | "zigzag";