Search code examples
configatom-editordouble-quotessingle-quotescson

How can I prevent Atom from making superficial changes to config.cson?


From what I can tell from the CSON README and other CSON usages I've found on the Internet, it's conventional to use single rather than double quotes for string literals. Because of this (and because I agree with the rationale I've generally seen behind this convention), I am using it for my Atom config files, such as keymap.cson:

'body':
  'ctrl-tab': 'pane:show-next-item'
  'ctrl-tab ^ctrl': 'unset!'
  'ctrl-shift-tab': 'pane:show-previous-item'
  'ctrl-shift-tab ^ctrl': 'unset!'

So far, this has worked fine for me. However, I am running into a problem when I try to use the same convention for my config.cson file as well. For instance, I am trying to have its contents set to the following:

'*':
  core:
    disabledPackages: [
      'exception-reporting'
    ]
    restorePreviousWindowsOnStart: false
    telemetryConsent: 'no'
  welcome:
    showOnStartup: false
  whitespace:
    ignoreWhitespaceOnCurrentLine: false

But if I open Atom and hit Ctrl+= Ctrl+- (to play with the font size) or do some other similar change and then restore Atom back to its previous state, Atom changes my config.cson file to look like this:

"*":
  core:
    disabledPackages: [
      "exception-reporting"
    ]
    restorePreviousWindowsOnStart: false
    telemetryConsent: "no"
  editor: {}
  welcome:
    showOnStartup: false
  whitespace:
    ignoreWhitespaceOnCurrentLine: false

As you can see, it changed all the single quotes to double quotes and added an unnecessary editor section.

Is there a way to prevent Atom from making these sorts of superficial changes to my config.cson file? The reason this matters to me is that I am keeping my Atom config files in version control, so in order to prevent very noisy diffs, I would need to either disable this behavior or use inconsistent or suboptimal styling for my quotes, and I would find the former option much more preferable if it is possible.


Solution

  • As of v2.0.0, the cson-parser library uses the conventional default for quote type when stringifying CSON, so you can write a simple shell script using that library and run it on config.cson before committing to Git. It would also be relatively simple to remove things like the empty editor section in such a script before calling stringify.

    You could potentially write this into an Atom package, as @idleberg mentioned in a comment, but I haven't tried that myself.

    If season upgrades its cson-parser dependency to v2.0.0, that would solve the quote type problem, but the empty editor section would still need to be removed by something else.