Skip to content

[Feature] Add <SEPARATOR> special word#296

Closed
joutvhu wants to merge 7 commits into
trivago:v6from
joutvhu:develop
Closed

[Feature] Add <SEPARATOR> special word#296
joutvhu wants to merge 7 commits into
trivago:v6from
joutvhu:develop

Conversation

@joutvhu
Copy link
Copy Markdown

@joutvhu joutvhu commented Jun 1, 2024

Implement feature #268

@joutvhu
Copy link
Copy Markdown
Author

joutvhu commented Jun 1, 2024

Hi @ayusharma, @byara
Please help to review

@forivall
Copy link
Copy Markdown

forivall commented Dec 6, 2024

This will need my additional changes (joutvhu/prettier-plugin-sort-imports#2) before merging, as adding tests revealed some critical issues.

@byara byara changed the base branch from main to v5.2.0 December 8, 2024 14:58
@byara byara changed the base branch from v5.2.0 to main December 8, 2024 15:01
@byara
Copy link
Copy Markdown
Collaborator

byara commented Dec 8, 2024

Hey @joutvhu can we please update this PR with some tests mentioned by @forivall?

@byara byara changed the base branch from main to v6 December 9, 2024 10:49
@byara
Copy link
Copy Markdown
Collaborator

byara commented Dec 9, 2024

I changes the base branch to v6. Let's release it there.

@joutvhu
Copy link
Copy Markdown
Author

joutvhu commented Dec 9, 2024

@byara I added tests

joutvhu and others added 3 commits December 10, 2024 00:42
Add tests for the separator special word
# Conflicts:
#	src/utils/get-sorted-nodes.ts
Copy link
Copy Markdown

@forivall forivall Dec 12, 2024

Choose a reason for hiding this comment

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

this doesnt have any comments? I already included similar tests in ImportsManualSeparated, so i think these Separator tests can be removed or merged into that folder.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @joutvhu can you please address this comment?
There might be some other tests within a copy of this PR from here, it would be nice to add those too.

Copy link
Copy Markdown
Collaborator

@byara byara left a comment

Choose a reason for hiding this comment

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

Thank you for the PR 👏 really appreciate the effort you have put into this!
I left a comment, could you please take a look?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @joutvhu can you please address this comment?
There might be some other tests within a copy of this PR from here, it would be nice to add those too.

@byara byara requested review from Copilot and vladislavarsenev July 9, 2025 12:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a <SEPARATOR> placeholder to the import-sorting plugin, allowing users to manually inject blank lines between import groups.

  • Introduce a new SEPARATOR_SPECIAL_WORD constant and expose it in src/constants.ts
  • Extend get-sorted-nodes-by-import-order.ts to recognize <SEPARATOR> and insert blank lines
  • Add/update test suites under tests/Separator and tests/ImportsManualSeparated to cover manual separators

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/constants.ts Exported SEPARATOR_SPECIAL_WORD
src/utils/get-sorted-nodes-by-import-order.ts Handle SEPARATOR_SPECIAL_WORD in the import-sorting logic
src/utils/tests/get-code-from-ast.spec.ts Added : any annotation for the AST variable
tests/Separator/ppsi.spec.js New spec invoking <SEPARATOR> in importOrder
tests/Separator/* Various input files and snapshots updated for separator behavior
tests/ImportsManualSeparated/ppsi.spec.js Manual-separated tests updated to include <SEPARATOR>
tests/ImportsManualSeparated/* Additional manual separation scenarios and snapshots

@@ -0,0 +1,5 @@
run_spec(__dirname, ["typescript"], {
importOrder: ['^@core/(.*)$', '^@server/(.*)', '^@ui/(.*)$', '<SEPARATOR>', '^[./]'],
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

The regex '^@server/(.)' is missing the trailing '$' to match the end of the string. For consistency with the other patterns, it should be '^@server/(.)$'.

Suggested change
importOrder: ['^@core/(.*)$', '^@server/(.*)', '^@ui/(.*)$', '<SEPARATOR>', '^[./]'],
importOrder: ['^@core/(.*)$', '^@server/(.*)$', '^@ui/(.*)$', '<SEPARATOR>', '^[./]'],

Copilot uses AI. Check for mistakes.
plugins: getExperimentalParserPlugins([]),
};
const ast = babelParser(code, parserOptions);
const ast: any = babelParser(code, parserOptions);
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

[nitpick] Using any for the AST reduces type safety. Consider importing and using Babel's AST types (e.g., babelParser.ParseResult<File>) to improve maintainability.

Suggested change
const ast: any = babelParser(code, parserOptions);
const ast: babelParser.ParseResult<File> = babelParser(code, parserOptions);

Copilot uses AI. Check for mistakes.
@forivall
Copy link
Copy Markdown

forivall commented Sep 8, 2025

This pr is now obsolete with #339 merged now, so i think this can be safely closed.

@byara byara closed this Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants