Skip to content

[Traits] Change TraitConfiguration struct to an enum #8355

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
bripeticca opened this issue Mar 11, 2025 · 0 comments · May be fixed by #8370
Open

[Traits] Change TraitConfiguration struct to an enum #8355

bripeticca opened this issue Mar 11, 2025 · 0 comments · May be fixed by #8370
Assignees

Comments

@bripeticca
Copy link
Contributor

Description

Currently, the TraitConfiguration struct describes a user-designated trait configuration wherein the user can decide which combination of traits are enabled/disabled for a given package. The way this struct is currently designed allows for an optional set of enabled traits, as well as a bool that describes the flag to enableAllTraits. Since there are distinct use cases depending on whether or not the enabled traits are nil, empty, or contains a list of traits, it makes more sense to treat this as an enum:

enum TraitConfiguration: Codable, Hashable { 
    case enableAllTraits // when the enableAllTraits flag is set, since this will simply enable everything
    case noConfiguration // when there isn't a configuration set, meaning that the default traits will be used
    case noTraits // when there is a configuration set and the set of enabled traits is empty, which overrides the default traits 
    case traits(Set<String>) // when there is a configuration set and there is a set of traits present
}

Expected behavior

This will make the checks done on TraitConfiguration to be more ergonomic, as there would be a defined set of cases that are explicitly named and would omit redundant checks.

Actual behavior

The current use of TraitConfiguration can be a bit painful - there are plenty of condition checks involving repeated terms (i.e. if let enabledTraits = traitConfiguration.enabledTraits, traitConfiguration.enableAllTraits == false { ... } and other variations of this) that can be condensed for ease of use.

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version && uname -a)

No response

@bripeticca bripeticca self-assigned this Mar 11, 2025
@bripeticca bripeticca changed the title Change TraitConfiguration struct to an enum [Traits] Change TraitConfiguration struct to an enum Mar 11, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant