Skip to content

feat: Sort JSON keys in configuration file for better version control support (closes #816) #819

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

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

dotWee
Copy link
Contributor

@dotWee dotWee commented Oct 5, 2024

Summary

This PR improves the consistency of the configuration file (linearmouse.json) by ensuring that the JSON keys are always written in a sorted, predictable order.

Previously, the keys were written in a random or non-deterministic order, which caused unnecessary changes in version control systems (like Git) when no actual settings were modified. This behaviour could result in cluttered diffs and make it harder to track changes effectively.

Changes

  • Updated the dump method in Configuration.swift to use .sortedKeys as an option in JSONEncoder.outputFormatting.

Benefits

  • JSON keys are now consistently sorted alphabetically.
  • This improves the readability and management of the linearmouse.json file.
  • It reduces noise in Git diffs, making it easier to track real changes to the configuration.

Testing

The change has been tested to ensure that:

  • The configuration file is saved with sorted keys.
  • The app continues to load and save settings correctly without any issues.

Thanks for considering this contribution! I believe this will enhance the developer experience for users managing their configuration files in version control systems.

… management (closes linearmouse#816)

Added `.sortedKeys` option to `JSONEncoder` in the `dump` function to ensure that the keys in the configuration file (`linearmouse.json`) are written in a consistent, alphabetically sorted order.

This change improves readability and ensures that the JSON key order remains stable, which is especially helpful when using version control systems like Git, as it reduces unnecessary diffs caused by random key ordering.
@lujjjh lujjjh merged commit 7c214b5 into linearmouse:main Oct 6, 2024
1 check failed
@lujjjh lujjjh added the enhancement New feature or request label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants