Remove configuration option from package


#1

I don’t see a way to remove a config option in your package once it’s been used. I had an option in a package that I’ve now removed and the option still appears in the user’s settings view. I’m sure it’s still displaying there because even though it’s no longer in my package config it’s still in the user’s config file.

I’ve tried using the unset method or setting the value to null but I can’t seem to actually remove the option entirely.

Any advice?


#2

Have you tried to manually remove the related config object from the config.cson file?


#3

Yes I have tried that and surprisingly it’s still in my package settings file. Also, even if this did work it wouldn’t solve the issue of removing the option from a user who has the package installed.


#4

Could you please tell me what package is that?

It is my understanding that the object in the configuration file is recreated if any value in the package configuration differs from the default. This is not the case, right?


#5

This issue has come up in several packages and the one I’m working on right now isn’t published yet. What you’re describing would be great but that doesn’t seem to be the case.


#6

I just used atom.config.unset to remove a find-and-replace.foo setting I manually added to my config.cson. If unset isn’t working for you, please share the steps to reproduce the problem.

In any case, here’s the brute force method to resolve the problem:

Let’s say that you have two configuration options, one old and one new called some-package.old and some-package.new respectively. If your config.cson looks like this:

"*":
  "some-package":
    old: 5

And you want to get rid of some-package.old, you can use atom.config.get('some-package') to get the entire object of settings for your package. In this case, it would be { old: 5 }. Then you can delete the old property and use atom.config.set('some-package', settingsObject) to store the updated configuration. The code would look like this:

let settings = atom.config.get('some-package')
delete(settings.old)
atom.config.set('some-package', settings)

#7

Ah yes you are correct. I think the main issue that had me confused is that I often have a production version of a package running on one open editor with another editor in dev mode to see the changes of the same package while developing. Since the live package still has the option in the config it was showing up in the atom.config.get('some-package') call.

The unset and the brute force options both work. Is the expected development workflow that whenever you remove a config option you should add an atom.config.unset call inside the package activation command? I noticed some bloat in my own config file while investigating this for packages that I don’t have installed anymore.

Any best practices? Thanks again.


#8

My personal preference is to “upgrade” old configuration settings to new ones if you’re changing the meaning of things. So yes, in activation check for old settings and convert them to new ones.


#9

Gotcha - thanks again and happy new year!