Skip to content

feat: Import sort order skip files#360

Merged
vladislavarsenev merged 12 commits into
trivago:v6from
RyderKishan:main
Oct 24, 2025
Merged

feat: Import sort order skip files#360
vladislavarsenev merged 12 commits into
trivago:v6from
RyderKishan:main

Conversation

@RyderKishan
Copy link
Copy Markdown
Contributor

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

@RyderKishan RyderKishan marked this pull request as ready for review May 15, 2025 10:42
@RyderKishan
Copy link
Copy Markdown
Contributor Author

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

@byara byara requested review from Copilot and vladislavarsenev July 9, 2025 12:00
@byara byara changed the base branch from main to v6 July 9, 2025 12:00
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 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
Copy Markdown
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.

Comment thread src/index.ts Outdated
Comment thread types/index.d.ts
Comment thread src/index.ts Outdated
Comment thread tsconfig.json Outdated
@RyderKishan
Copy link
Copy Markdown
Contributor Author

@vladislavarsenev The comments are addressed. Please validate

@vladislavarsenev vladislavarsenev self-assigned this Oct 20, 2025
@vladislavarsenev
Copy link
Copy Markdown
Collaborator

Hey again! Sorry for long delay. Could you please resolve merge conflicts? I'll be able to merge it.

@vladislavarsenev vladislavarsenev mentioned this pull request Oct 24, 2025
@vladislavarsenev vladislavarsenev merged commit cc7c7eb into trivago:v6 Oct 24, 2025
3 checks passed
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.

4 participants