Fix overriding default formatters in the user configuration #3042
+4
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My Report
My project have a .clang-format file in the home directory, opencode will ALWAYS run clang-format if that file exists. using custom configurations like disableing formatters is totally ignored, so i had to apply this fix to tell it not to ignore me.
Grok Explanation of the bug and the fix
The bug was that the formatters object was keyed by the export names from the Formatter module (e.g., 'clang'), but the configuration uses the name property of each formatter (e.g., "clang-format"). This mismatch meant that disabling a formatter in the config, like setting "clang-format": { "disabled": true }, wouldn't actually remove it because delete formatters["clang-format"] was trying to delete a key that didn't exist.
I fixed this by rebuilding the formatters object to use the name property as keys instead of the export names. Now the keys match what the config expects, so disabling formatters works correctly.