Skip to content

import/order false positives for TypeScript module declarations #2217

@remcohaszing

Description

@remcohaszing

The import/order rule gives false positives for imports inside TypeScript module declarations.

Practical example:

declare module 'monaco-editor/esm/vs/base/common/cancellation' {
  export enum CancellationToken {
    None,
  }
}

declare module 'monaco-editor/esm/vs/editor/contrib/documentSymbols/documentSymbols' {
  import { ITextModel, languages } from 'monaco-editor';
  import { CancellationToken } from 'monaco-editor/esm/vs/base/common/cancellation';

  export function getDocumentSymbols(
    model: ITextModel,
    flat: boolean,
    token: CancellationToken,
  ): Promise<languages.DocumentSymbol[]>;
}

declare module 'monaco-editor/esm/vs/editor/editor.worker' {
  import { worker } from 'monaco-editor/esm/vs/editor/editor.api';

  export function initialize(
    fn: (ctx: worker.IWorkerContext, createData: unknown) => unknown,
  ): void;
}

This is happening, because import/order collects all import statements and assumes they are in the program body.

I would expect the import/order rule to be applied to each body separately. Currently these are the Program body and the TSModuleBlock body, but who knows what the future holds.

Alternatively the rule could be applied to imports which are direct children Program body only.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions