-
Notifications
You must be signed in to change notification settings - Fork 146
[Feature] Add <SEPARATOR> special word #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v6
Are you sure you want to change the base?
Conversation
Hi @ayusharma, @byara |
This will need my additional changes (joutvhu/prettier-plugin-sort-imports#2) before merging, as adding tests revealed some critical issues. |
I changes the base branch to v6. Let's release it there. |
@byara I added tests |
Add tests for the separator special word
# Conflicts: # src/utils/get-sorted-nodes.ts
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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 insrc/constants.ts
- Extend
get-sorted-nodes-by-import-order.ts
to recognize<SEPARATOR>
and insert blank lines - Add/update test suites under
tests/Separator
andtests/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>', '^[./]'], |
There was a problem hiding this comment.
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/(.)$'.
importOrder: ['^@core/(.*)$', '^@server/(.*)', '^@ui/(.*)$', '<SEPARATOR>', '^[./]'], | |
importOrder: ['^@core/(.*)$', '^@server/(.*)$', '^@ui/(.*)$', '<SEPARATOR>', '^[./]'], |
Copilot uses AI. Check for mistakes.
@@ -52,7 +52,7 @@ import a from 'a';`; | |||
sourceType: 'module', | |||
plugins: getExperimentalParserPlugins([]), | |||
}; | |||
const ast = babelParser(code, parserOptions); | |||
const ast: any = babelParser(code, parserOptions); |
There was a problem hiding this comment.
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.
const ast: any = babelParser(code, parserOptions); | |
const ast: babelParser.ParseResult<File> = babelParser(code, parserOptions); |
Copilot uses AI. Check for mistakes.
Implement feature #268