0

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.

Sam Estep
  • 12,974
  • 2
  • 37
  • 75

2 Answers2

1

If it's an option to switch the file-format, consider using config.json instead. Since JSON uses double-quotes by convention, there should be no conflict when making changes to your Atom configuration.

Atom is already in the transition to move away from CoffeeScript (and CSON) and you can use JavaScript/CoffeeScript and JSON/CSON interchangeably throughout the app.

idleberg
  • 12,634
  • 7
  • 43
  • 70
  • Thanks for letting me know about the transition! However, this doesn't answer my question. As I stated above, I am aware that I can use double quotes in my config file in order to align with Atom's styling to lessen the number of superficial changes it makes; using JSON instead of CSON simply forces me to take that option. It doesn't change the fact that Atom is making superficial changes to my config file, as evidenced by the fact that Atom still adds a `"editor": {},` line when I do something like adjusting the font size. – Sam Estep Mar 14 '17 at 15:42
  • 1
    I don't think there's a practical way of doing this. Atom uses `season` for parsing/stringifying CSON, not `cson`. There are no options that allow overriding its defaults. There might be a chance you create a package that watches `config.cson` for changes, then uses `cson` to parse and stringify its content and saves it. That should work if Atom doesn't interferes. – idleberg Mar 14 '17 at 15:58
  • By the way, I suggested the answer as a workaround, since JSON's conventions appear to be universally valid. Using JSON would make it easy to follow conventions, since you seem to care about this. – idleberg Mar 14 '17 at 16:16
  • OK, that makes sense, thanks; that's unfortunate that this isn't configurable, though. – Sam Estep Mar 14 '17 at 20:17
  • Actually, as it turns out, using `cson` instead of `season` wouldn't help, because both `cson` and `season` make use of the lower-level [`cson-parser`](https://github.com/groupon/cson-parser) library, which uses [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) [here](https://github.com/groupon/cson-parser/blob/v1.3.5/lib/stringify.js#L72) for object keys and [here](https://github.com/groupon/cson-parser/blob/v1.3.5/lib/stringify.js#L120) for other strings. – Sam Estep May 24 '17 at 23:38
  • I added a [brutal hack](https://github.com/Alhadis/Atom-PhoenixTheme/commit/67547e5cec2ef76e7d58c501d547d8d7bb19bd37) to my `init.js` file which forces Atom to use tabs when saving CSON files. You could try something similar which swaps quote-types in the stringified data. –  Oct 23 '17 at 23:06
0

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.

Sam Estep
  • 12,974
  • 2
  • 37
  • 75