Converting ~/.atom/init.coffee to init.js?

Hi!

I prefer to use js instead of CoffeeScript and I saw in documentation that it’s possible. My intuition was to simply rename the file and write javascript code. But, after the relaunch, Atom shows error notification:

Failed to load /Users/viktor/.atom/init.coffee

reserved word ‘function’

I searched .atom folder for init.coffee, but with no luck. Where can I change this so it starts working?

Thank you!

Odd, renaming it is how you would do it.

What happens if you remove the file completely? Or rename the .atom folder so Atom makes a new one, and change it in there?

Ooooooh!
I didn’t know if that’s the way to go about it so I gave up when it wasn’t working. Now I investigated further and found out what was the cause for this issue. I use a CLI tool called mackup that keeps my dotfiles in sync on multiple machines. It does this by moving dotfiles to Dropbox folder and creates symlinks for them in Dropbox. mackup made a symlink of init.coffee, but when I loaded the ~/.atom dir in Atom, it showed the files like files (it didn’t show any signs of files being symlinks). I then used Atom to rename the file from init.coffee to init.js. This only renamed the symlink. The original file is still /smth/smth/Dropbox/.atom/init.coffee and Atom treats it as such.

Not sure if this should be treated as Atom’s bug or not…

2 Likes

More explanation (I don’t know how to edit posts here :smile:):
mackup tool: https://github.com/lra/mackup

> ls -l ~/.atom
lrwxr-xr-x    1 viktor  staff    46B Mar 19 23:00 init.js -> /Users/viktor/Dropbox/Mackup/.atom/init.coffee

It’s not an unintended behavior of Atom, really. It might be valuable for the tree-view package to check for symbolic links and mark them somehow, but that would likely be considered a feature expansion by the developers and prioritized as such.

1 Like

Let me reply a little more directly to the issue: CoffeeScript is not a subset of JS, nor is it a superset. The intersection is non-zero, but it’s still very little. So this doesn’t really surprise me, to be honest.

If you have a small init.coffee, you can probably just rewrite it in JS with very little effort. If it’s larger and more involved, you could probably run Decaffeinate on it and be done with it with few if any extra edits.

CoffeeScript is not a subset of JS, nor is it a superset

The landing page says it compiles to JS, which means it’s definitely a subset of JS.

But the issue here was just if it’s possible to use an init.js file, not if the same contents can be used.

Compiles to JS ≠ subset of JS. It might mostly represent a subset of JS semantically (and it represents a nearly complete semantic subset), but it certainly isn’t a syntactic subset, and the syntactic aspect is what I’m referring to. That’s why simply changing the extension wasn’t sufficient.

@vfonic explained quite accurately why changing the extension didn’t work in this circumstance, and based on his posts, I imagine he’s quite familiar with the difference between CS and JS.