Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Import sort order skip files #360

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

Open
RyderKishan wants to merge 12 commits into trivago:v6
base: v6
Choose a base branch
Loading
from RyderKishan:main
Open

Conversation

Copy link

@RyderKishan RyderKishan commented May 15, 2025

Feature: Skip Import Sorting for Specified Files

Problem

In large codebases with hundreds of thousands of files, manually adding // sort-imports-ignore comments to each file that should be excluded from import sorting becomes impractical and maintenance-heavy. This is particularly problematic for:

  • Generated files that shouldn't be modified
  • Test files with specific import ordering requirements
  • Legacy code that should maintain its current import structure
  • Specific directories that should be excluded from import sorting

Solution

This PR introduces a new configuration option importOrderSkipFiles that 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

{
 "importOrderSkipFiles": [
 "generated/**", // Skip all files in generated directory
 "*.test.{ts,tsx}", // Skip all test files
 "legacy/*.js", // Skip specific directory
 "specific-file.ts" // Skip specific file
 ]
}

Features

  • 🎯 Pattern-based file matching using minimatch
  • 📁 Supports both directory and file patterns
  • 🔄 Works with relative and absolute paths
  • ⚡ Efficient pattern matching for large codebases
  • 🧪 Comprehensive test coverage

Implementation Details

  • Added minimatch dependency for robust glob pattern matching
  • Implemented shouldSkipFile utility with thorough test coverage
  • Integrated skip functionality in the main preprocessor
  • Added TypeScript types for the new configuration option

Testing

The implementation includes comprehensive tests covering:

  • Empty skip patterns
  • Various glob pattern scenarios
  • Directory-specific patterns
  • Filename-only patterns
  • Special character handling
  • Mixed path separator support
  • Exact filename matches

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

  • Add support for negative patterns (e.g., !generated/important.ts)
  • Consider adding directory-specific import ordering rules
  • Add documentation for common skip patterns and use cases

umanghome reacted with thumbs up emoji
@RyderKishan RyderKishan marked this pull request as ready for review May 15, 2025 10:42
Copy link
Author

@ayusharma @byara Can i get a review on this?

@byara byara changed the base branch from main to v6 July 9, 2025 12:00
Copy link

@Copilot 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 support for skipping import sorting based on user-defined glob patterns, improving maintainability for generated, test, and legacy files.

  • Introduces importOrderSkipFiles configuration for file glob patterns
  • Implements shouldSkipFile utility with corresponding tests
  • Integrates skip logic in the main preprocessor
  • Adds new option definition in src/index.ts and installs minimatch

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 that shouldSkipFile correctly normalizes backslashes to forward slashes before matching.
}); 

Copy link
Collaborator

@vladislavarsenev vladislavarsenev left a comment

Choose a reason for hiding this comment

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

It's really useful . Thank you for your effort! I've left a few minor comments.

Copy link
Author

@vladislavarsenev The comments are addressed. Please validate

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

Reviewers

@vladislavarsenev vladislavarsenev vladislavarsenev left review comments

Copilot code review Copilot Copilot left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /