feat: Import sort order skip files#360
Merged
Merged
Conversation
Contributor
Author
|
@ayusharma @byara Can i get a review on this? |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for skipping import sorting based on user-defined glob patterns, improving maintainability for generated, test, and legacy files.
- Introduces
importOrderSkipFilesconfiguration for file glob patterns - Implements
shouldSkipFileutility with corresponding tests - Integrates skip logic in the main preprocessor
- Adds new option definition in
src/index.tsand installsminimatch
Reviewed Changes
Copilot reviewed 5 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/should-skip-file.ts | New utility to determine if a file matches any skip patterns |
| src/utils/tests/should-skip-file.spec.ts | Comprehensive tests for the skip-file utility |
| src/preprocessors/preprocessor.ts | Early return in preprocessor when a file should be skipped |
| src/index.ts | Defines importOrderSkipFiles option in plugin configuration |
| package.json | Adds minimatch dependency and its types |
Comments suppressed due to low confidence (2)
src/index.ts:19
- The default value for importOrderSkipFiles should be an empty array of strings (e.g.,
default: []) instead of an array with an object wrapper. This ensures the option is initialized correctly as a string array.
default: [{ value: [] }],
src/utils/tests/should-skip-file.spec.ts:61
- Consider adding a test case that uses Windows-style path separators (e.g.,
\\on Windows) to verify thatshouldSkipFilecorrectly normalizes backslashes to forward slashes before matching.
});
Collaborator
vladislavarsenev
left a comment
There was a problem hiding this comment.
It's really useful . Thank you for your effort! I've left a few minor comments.
Contributor
Author
|
@vladislavarsenev The comments are addressed. Please validate |
Collaborator
|
Hey again! Sorry for long delay. Could you please resolve merge conflicts? I'll be able to merge it. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature: Skip Import Sorting for Specified Files
Problem
In large codebases with hundreds of thousands of files, manually adding
// sort-imports-ignorecomments to each file that should be excluded from import sorting becomes impractical and maintenance-heavy. This is particularly problematic for:Solution
This PR introduces a new configuration option
importOrderSkipFilesthat allows users to specify glob patterns for files that should be excluded from import sorting. This provides a more scalable and maintainable way to manage import sorting exclusions.New Configuration Option
Features
Implementation Details
minimatchdependency for robust glob pattern matchingshouldSkipFileutility with thorough test coverageTesting
The implementation includes comprehensive tests covering:
Usage Example
{ "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], "importOrderSkipFiles": [ "generated/**/*.ts", "**/*.test.{ts,tsx}", "legacy/**" ] }Breaking Changes
None. This is a purely additive feature that maintains backward compatibility.
Future Considerations
!generated/important.ts)