I'll try to be as clear possible: Whenever a mod creates a config file, with categories and their respective keys and all that, if for some reason, the internal code of the mod changes the name of any category, or any key, Forge only appends those new values to the existing file, leaving the "old" categories untouched.
While this may be good to record all changes made to the config file, once there are many changes to the main code, many values are left behind, without use. This kind of changes may occur whenever there's major Mod Update or when someone rewrites a mod.
Would it be possible to let Forge clean all config files every time the game is started?
Maybe putting a marker on each requested category to afterwards just delete those who aren't marked would work?
Also, an option to enable/disable this feature would be useful if someone wants the old behavior.
Effectevly only the mod knows which configs are important and should handle/remove old configs themself.
That's true but, sometimes, modders forget this kind of concepts, specially new ones, and this feature would also reduce the garbage found in config files that have a lot of time since its creation...
Also, if a mod makes use of the Configuration class that Forge provides to create config files, each time a mod gathers info from its config file, it would necessarily make a call to a Forge method, so _in theory_ Forge has some control over the process, enough to tell if a Category/Key has been requested or not...
I'm not requesting a miracle neither, because if a mod doesn't use the Configuration class and/or has its own way of managing its own config, then only the mod will be able to tell wich info wasn't used at all..
Forge is not in the business of breaking working mods to work around poorly developed ones, full stop. If a mod decides to roll its own configuration because of developer preference or a bug/limitation in the forge implementation it would be very rude to just nuke their configuration.
Interestingly you basically are requesting a miracle - you're asking for forge to be able to determine from thin air whether an option in a config file is needed or not, so until a magic solution for that comes along...
The JVM is, as of Java 11, not able to interact with the octarine frequencies. The java.magic package is under review. This means that it cannot determine arbitrary values as seen by end users. This in turn makes it so that Forge cannot magically remove only "useless" configs.
Also, removing all files on startup would not only wipe all configs but is also resource intensive. Secondly, Forge has never had features that affect how it works that are toggleable. No one or everyone does it. Finally, the Forge team really don't like issues and pull requests that encourage or enable bad practices in modding or those that hurt existing well-made mods.
If a mod is poorly written, it is the author's and not Forge's problem. The actual solution to this issue would be for modders to properly implement and use the configuration system provided by Forge, and Forge isn't responsible for that. And since you mentioned "new" modders, how about getting resources for them so they can follow best practices better.
I came up with this idea after seeing my _config_ folder, and the bunch of unused config files after adding updates for some of the mods I use, and the many options that were left useless in those config files...So I thought that maybe this was a good idea, 'cause I had to manually clean all that "garbage" text, instead of deleting the entire directory and letting Forge regen the folder (Losing my settings in the process...)
Maybe not everyone thinks of this as a problem, soo...If I ever have time, maybe I'll try to figure out a way to achieve this, _maybe_. Until then, let's hope for java.magic to be approved...
This is impossible to implement without without having the potential to cause the exact issue you complain about ("Losing my settings in the process..."). I'd agree that it would be a useful feature, but sometimes in software development certain 'easy' tasks are much harder than it first seems.
It is up to mod authors to migrate their old configs to new versions.
There is no way for us to know if something is valid or not in arbitrary mod configs.
Most helpful comment
Effectevly only the mod knows which configs are important and should handle/remove old configs themself.