Two import declarations read the same module

tx0/ts:duplicate-import-sourcerecommendedwarningstyle

What it finds

Two import declarations that read the same module split what the file uses from it over two places, and invite adding a third. One declaration lists it all.

A declaration is reported when an earlier one in the file imports from the same module string and the two could be merged: both import values or both only types with import type, and neither is a namespace import, which other names cannot join. Imports for side effects only, without names, and those inside declare module are left alone.

From the rule's source, duplicate_import_source.rs.

Example from the rule's tests
import { readFile } from "fs";import { writeFile } from "fs";tx0 reports: fs is already imported aboveimport type { Stats } from "fs";import * as path from "path";import { join } from "path";import "./polyfills";import "./polyfills";export const used = [readFile, writeFile, path, join] as unknown as Stats;
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:duplicate-import-source" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:duplicate-import-source] reason="..."

tx0 explain tx0/ts:duplicate-import-source shows the same in the terminal. Found a false positive? Report it.