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

Search for configuration in config directories (dotfiles, etc) #749

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

WuerfelDev
Copy link

Searches for configuration files (swift-format/config.json) in the config directories (~/Library/Application Support, $XDG_CONFIG_HOME, .config).
That enables a "global" (userwide) configuration that is stored eg in the dotfiles.

The configuration file is only used when no other configuration file was found

Searches for:
- ~/Library/Application Support/swift-format/config.json
- $XDG_CONFIG_HOME/swift-format/config.json
- ~/.config/swift-format/config.json
@WuerfelDev WuerfelDev changed the title Configuration files in config directories (dotfiles, etc) Search for configuration in config directories (dotfiles, etc) Jun 5, 2024
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @calebhearth. I think adding an ability to have a global .swift-format configuration without putting .swift-format in / will be useful.

A couple comments regarding the search locations:

@calebhearth
Copy link

@WuerfelDev opened the PR, but I second the thanks!

@ahoppen
Copy link
Member

ahoppen commented Oct 30, 2024

Oh, whoops, sorry. @WuerfelDev thank you for opening the PR 🙏🏽

@WuerfelDev
Copy link
Author

WuerfelDev commented Oct 31, 2024

I will make the changes within the next week. However I am unable to test on windows

Thanks for the SourceKit link, I'll get some "inspiration" from there

@ahoppen
Copy link
Member

ahoppen commented Oct 31, 2024

I will make the changes within the next week. However I am unable to test on windows

That’s fine. Just try and do the best you can think of, leaving FIXMEs for things that you know need covering and I can do the rest.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

A couple more comments. Also, could you format your changes using swift-format? Otherwise CI will fail with that issue.

Sources/swift-format/Frontend/Frontend.swift Outdated Show resolved Hide resolved
Sources/swift-format/Frontend/Frontend.swift Outdated Show resolved Hide resolved
Sources/swift-format/Frontend/Frontend.swift Show resolved Hide resolved
Merge remote-tracking branch 'upstream/main' into global-config-files
@WuerfelDev
Copy link
Author

@ahoppen Thank you so much for guiding me through this feature implementation, being new to swift I've learned a bunch of things along the way
I hope everything is fine now, else lmk if more changes are required

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thanks. Looking through it again, I just found one more small nitpick, otherwise looking great.

@@ -268,6 +270,64 @@ class Frontend {
}
}

// Load global configuration file
// First URLs are created, then they are queried. First match is loaded
var configLocations: [URL?] = []
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I only now noticed: Do we ever add nil to this array? I don’t think so and we wouldn’t need to do case var location? in the loop below if we don’t allow optionals in here.

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.

3 participants