Skip to content
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

Add wildcard pattern support for —exclude option #300

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rakuyoMo
Copy link

@rakuyoMo rakuyoMo commented Mar 13, 2025

Summary

Enhances the path exclusion functionality to support wildcard patterns:

  • Add support for * (match any number of characters) and ? (match single character)
  • Implement special path formats:
    • /pattern: Only match at root level
    • pattern/: Match directories and their contents
  • Improve performance by using efficient pattern matching

This change allows for more flexible and precise control over which paths
should be excluded during processing, without requiring third-party dependencies.

Reasoning

Currently, only fixed folders are supported, and wildcards are not supported. This is not easy to use in some scenarios. For example, Tuist will put the automatically generated files into the Derived folder. These folders may be scattered in multiple subfolders of the same project, such as the following:

.
├── App
│   ├── Derived
│   │   ├── InfoPlists
│   │   └── Sources
│   ├── App.xcodeproj
│   ├── Project.swift
│   ├── Resources
│   │   └── Assets.xcassets
│   ├── Sources
│   └── Tests
├── Components
│   ├── Settings
│   │   ├── Settings.xcodeproj
│   │   ├── Derived
│   │   ├── Project.swift
│   │   ├── Sources
│   │   └── Tests
│   └── InternalTools
│       ├── Derived
│       ├── Project.swift
│       ├── Resources
│       ├── Sources
│       ├── InternalTools.xcodeproj
│       └── Tests
├── App.xcworkspace
├── Package.resolved
├── Package.swift
├── Tuist
│   ├── ProjectDescriptionHelpers
│   └── ResourceSynthesizers
├── Tuist.swift
└── Workspace.swift

After adding the wildcard function, you can use --exclude "Derived/" to exclude all Derived directories. When adding new submodules in the future, there is no need to modify the format configuration.

Break

This change affects existing functionality. For the original README:

$ swift package format --exclude Tests

Now matches all paths containing a file or directory component named "Test", e.g.

  • Tests (a single Tests file or directory)
  • path/to/Tests (a file or directory named Tests at any level)
  • src/Tests/file.swift (a path containing a Tests directory)

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.

1 participant