Skip to content

feat: add support for import tags#252

Merged
fardad-dev merged 9 commits intofardad-dev:masterfrom
Didericis:master
Oct 29, 2025
Merged

feat: add support for import tags#252
fardad-dev merged 9 commits intofardad-dev:masterfrom
Didericis:master

Conversation

@Didericis
Copy link
Copy Markdown
Contributor

Implemented the feature requested here

Features

  • Merges all import tags which share the same source (within the same comment block)
  • Normalizes quotes and whitespace for sources and type aliases
  • Splits any imports for more than one type so each type is its own line
  • Orders imports alphabetically (with respect to aliases if given, or type if not)
  • Sorts imports before all other tags by default
  • Handles default imports (uses default name in last encountered import tag)

Example

Before

/**
 * @typedef {Object} Foo
 * @import {A} from 'a'
 * @import BM, { B as B1,
 * B2   , B4 } from 'b'
 * @import BMain, {B3  } from 'b'
 */
/**
 * @import BDefault, {       B5 } from   'b'
 * @import C    from    'c'
 */

After

/**
 * @import {A} from "a"
 * @import BMain, {
 *   B as B1,
 *   B2,
 *   B3,
 *   B4
 * } from "b"
 * @typedef {Object} Foo
 */
/**
 * @import BDefault, {B5} from "b"
 * @import C from "c"
 */

Limitations

  • Does not consolidate imports across comment blocks

@Didericis Didericis marked this pull request as draft October 15, 2025 19:35
@Didericis
Copy link
Copy Markdown
Contributor Author

Realized I should also add the following:

  1. Ability to sort import tags by source
  2. Option to toggle this feature on/off
  3. Option for line splitting
  4. Option for whitespace settings

Comment thread tests/typeScript.test.ts Outdated
*/
testFunction(){

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this spaces need to be changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just an auto formatting thing from my editor. Tests are passing with the change, so figured it was ok to keep

Copy link
Copy Markdown
Contributor Author

@Didericis Didericis Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added them back just in case there was any deliberate whitespace cleaning being tested 👍

@fardad-dev
Copy link
Copy Markdown
Owner

LGTM

@Didericis Didericis marked this pull request as ready for review October 15, 2025 22:04
@Didericis Didericis requested a review from fardad-dev October 18, 2025 17:47
@fardad-dev fardad-dev merged commit ab5c488 into fardad-dev:master Oct 29, 2025
6 checks passed
@fardad-dev
Copy link
Copy Markdown
Owner

Release v1.5.0

Thank you

Comment thread src/parser.ts
: `{${typeString}}`;
importClauses.push(namedImportClause);
}
spec.description = `${importClauses.join(", ")} from "${src}"`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed with this release I’ve lost my single quoted import paths and I think this could be the source. Does the prettier singleQuote option need to be checked here and the quotes modified accordingly?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reporting this.
Yes it is related to this pr
I think we should use prettier to format import, it can handle all other configs like space, import sort and others.

Copy link
Copy Markdown
Contributor Author

@Didericis Didericis Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hosseinmd If you want to fix lmk, otherwise I'll plan to refactor to use prettier some time tonight when I'm free

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants