Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow js-mode for JavaScript layer? #4082

Closed
jupl opened this issue Dec 6, 2015 · 29 comments
Closed

Allow js-mode for JavaScript layer? #4082

jupl opened this issue Dec 6, 2015 · 29 comments
Labels
- Forum - JavaScript stale marked as a stale issue/pr (usually by a bot)

Comments

@jupl
Copy link
Contributor

jupl commented Dec 6, 2015

Lately I've been having some issue with js2-mode and I was wondering if there is any way to have an option to use js-mode instead of js2-mode for the JavaScript layer. I can switch to js-mode manually but it doesn't automatically set things up like Tern, Flycheck, Company, etc.

@stormpat
Copy link
Contributor

stormpat commented Dec 8, 2015

Whats the issues you encounter with js2-mode? AFAIK js-mode has not been maintained for the last 5 years, and is deprecated in favour for js3-mode, which is itself a fork of js2-mode.

@jupl
Copy link
Contributor Author

jupl commented Dec 8, 2015

The biggest problem is that js2 (and from what I hear js3 as well) is that it doesn't work well with new/experimental JS. I was working on some experimental code and js2-mode completely breaks in syntax highlighting (js2-mode errors appear and things stop working) until I remove the offending new features unlike js-mode, Atom, Sublime, Vim, etc. I opened an issue but because it's experimental code it's not something that will be fixed upstream. js-mode may be outdated, but it doesn't break the way js2-mode does. Also since you mention it there could be an option to select js-mode, js2-mode, or js3-mode.

@oppenlander
Copy link
Contributor

This is because js2-mode is parsing the code you write to provide the syntax highlighting (as well as other semantic features, like refactoring and folding).

👍 for having an option to switch, but this switching also needs to do things, like removing the "Refactoring" Major Mode bindings.
Also I do not think js3-mode is well supported. There's very little activity, and ES6+ support seems unlikely.

@stormpat
Copy link
Contributor

@jupl I work daily with JS, and have no issues with ES6 syntax highlighting/linting. Heres a screenshot from my emacs, it shows errors/warnings and more suggestions depending on the rules i use.

preview

preview

@jupl
Copy link
Contributor Author

jupl commented Dec 14, 2015

@stormpat ES6 is fine today now that it has been finalized. However, before then when I was messing around with proposed features I experienced quirks.

Here is a snippet of code that makes things fall apart when playing around with the function bind proposal that's available in Babel.

const y = {}
x::y()
function x() {}

@NervosaX
Copy link

Even react looks better in js-mode compared to js2-mode

js-mode
image

js2-mode
image

@oppenlander
Copy link
Contributor

@NervosaX You'll want to turn on js2-jsx-mode rather than js2-mode for proper JSX support.
Also js2-mode doesn't support the ES7 Object Rest/Spread operator, so even in js2-jsx-mode your snippet will not look right.

You might have better luck using web-mode/react-mode for better looking JSX editing.

@NervosaX
Copy link

@oppenlander Hey, thanks for the tips. Unfortunately without using js2-mode (or variant), I lose my eslint support. Kind of screwed over there. #3661 seems to go over all the issues with all the modes.

@oppenlander
Copy link
Contributor

@NervosaX You can also gain things like eslint back by toggling off warnings/errors in js2-mode with js2-mode-toggle-warnings-and-errors.
Your code after something like an Object Rest operator will be unstyled, but flycheck should still run.

@NervosaX
Copy link

Ah, that's way better with the warnings/errors off.

@ashnur
Copy link

ashnur commented Mar 27, 2016

For me neither of the js[23]?-modes are even close to something I would find pleasant. js-mode is abandoned, js2-mode has no support whatsoever afaik for standard.js and js3-mode is fully incompatible with spacemacs. For the past 4 months I couldn't configure how to make the indentation actually consistent. Spacemacs is just not for javascript at all, none of core people care about javascript to the slightest.

@StreakyCobra
Copy link
Contributor

@ashnur Most of Spacemacs functionalities are coming from upstream packages, and most of the work on layers is done by non-core contributors. If you find upstream packages that handle javascript well and you have a solution to integrate it, PRs are welcome :-)

@ashnur
Copy link

ashnur commented Mar 27, 2016

<rant>
There are 4 javascript "upstream packages" that I am aware of.

  • espresso-mode, abandoned, turned into js-mode
  • js-mode, abandoned, turned into js2-mode
  • js2-mode, current default, some very limited work on it, has no support for comma first, semicolon-less style ( standard.js ), the authors do not even considered these features to be configurable, or if they did, it's not documented, or if it is, I couldn't find the documentation
  • js3-mode, fork of js2-mode, has an almost working support for comma first style, it's inherently incompatible with spacemacs.

@StreakyCobra in this situation given your response I should either

  • fix or fork js2-mode (no chance)
  • fix spacemacs or js3-mode so they are not incompatible (probably not worth the effort)
  • write a new major mode for javascript (as if I knew where to start, i might even try it)
  • write a new editor from scratch
  • wait until neovim has some nicer interfaces or waste half a year configuring it (i don't really want to)
  • switch to an editor that somehow can support standard.js but can not support proper vim motions, for ex. Atom or Sublime Text 3

Right now I am using js2-mode, all errors disabled and indentation completely broken. I know, I should write this to them, but they obviously do not care at all, so I am not trying to complain, just describing the "best case scenario" I could manage to find. I can manually toggle the error reporting, and I am fairly sure there is a way to make it permanently configured, but this, as many other "obvious" things, I don't even know where to look for to find. I tried adding various settings in user-config but those are either ignored or overwritten, because they have no effect. (like disabling smartparens... not to mention, disabling it only for certain files, I am not even sure if it's possible)

I mean, it's still better than without any of these tools existing, and yeah it was worse before humans been able to control fire :D, but it still feels like a bottomless pit where I am stuck trying to climb out because got used to a number of things which are supported in a mutually exclusive way by half a dozen half-done, half-dead editors and plugins to these editors. Spacemacs is an exception in terms of how much care it's put into it, but that "care" completely ignored javascript and I get the feeling that although this ignorance comes from individual and rational decisions, it's still a result of conscious decisions.

I am fairly sure, although I have no proof for this, that the situation has risen because js-people find emacs hard, and no one who actually works on spacemacs also works in anything js related. So when spacemacs was put together, the most popular stuff (js2-mode) was just copy pasted into it.

In fact I am willing to bet that there isn't one single person on this planet who uses spacemacs for writing javascript with standard.js formatting style.
</rant>

@StreakyCobra
Copy link
Contributor

@ashnur I can understand your frustration about all this. The fact is that Spacemacs is an open-source project, we can not force people to work on features if they don't want to. Sadly it doesn't seem that a lot of people are interested in javascript and can contribute on this layer, so I don't have a solution for you right now.

You may try to open an issue (or PR) to start, animate and centralize a discussions about "how to improve javascript support in Spacemacs". People would be able to discuss what would be the best solution, share progression, find help for troubles, etc… I don't know if there will be people, but it's worth a try at least.

@stormpat
Copy link
Contributor

@ashnur I write a lot of javascript in my day job, and im always using spacemacs. Take a look at ESLint, i am using it as a linter, because its very easy to customize. Basically i just disable the original checker and add ESLint to flycheck instead. It works good enough for me, so maybe you too can get the desired functionality from it.

The js2-mode linter is a "ok" default, as it does not require any other tools. But i get your point, as i too was not pleased with the defaults.

@StreakyCobra I would want to argue that people are indeed using spacemacs for javascript, its kind of a must if you do any kind of webdev. But maybe most are satisfied with the defaults as javascript has many styles and personal tastes of look and feel. For people doing primarily webdev there are more popular editors like Atom, and Sublime, but hey we want emacs, right?

Finally, @ashnur you can customize your ESLint config or choose on of the many presets, airbnb being quite popular. Heres a blogpost on setting this up. (not spacemacs specific)

@StreakyCobra
Copy link
Contributor

@stormpat Ok, I don't do javascript, so I can not really know if Spacemacs is usable or not for this. But you're probably right saying people are doing some Javascript in Spacemacs. I'll let you discuss this further between javascripters ;-)

@ashnur
Copy link

ashnur commented Mar 28, 2016

@stormpat do you also happen to know a package that solves the indentation problem I have? Because that's the one which pushed me to comment here, and that's the one that you didn't answer.

I did make the mistake of thinking that standard.js is also comma first, because apart from this one rule (and some whitespace mismatch), it's the exact same style I use, so I was referring to it constantly. It isn't so I since configured eslint for something that's close to my style.

But I didn't refer to standard.js as "my problem is that i can't configure a linter package". I was using the name trying to explain that the auto indentation feature is incompatible with the style that the linter would be checking for. Simply put, I couldn't find the way how to make either js2-mode or js3-mode to indent my code the way I am used to. In the past several weeks it was so broken that I had to completely disable it, otherwise it was enforcing mixed indentation. That's quite bad I think.

@stormpat
Copy link
Contributor

Personally i dont use comma first style indents, and i can see your frustration with js2-mode not having support for it. To get support for comma first style, you could try web-mode, and if you do write react apps have a look at react-mode it bundles with web-mode.

@axyz
Copy link
Contributor

axyz commented Apr 20, 2016

you can have a look at react-layer code. Using web-mode, js2-minor and tern it works quite well and will respect your eslint style rules (never tried to configure eslint for comma first however).

A problem I'm facing right now is how to allow object spread (should be available as experimental feature on eslint, but no way to make it works on js2-mode or react-mode)

@dgutov
Copy link

dgutov commented Jul 13, 2016

js-mode has not been maintained for the last 5 years, and is deprecated in favour for js3-mode

js-mode, abandoned, turned into js2-mode

Where is all this coming from? js-mode is a part of Emacs, and as such is maintained with the rest of Emacs's development. It's not deprecated.

js3-mode, on the other hand, is very much unmaintained.

A problem I'm facing right now is how to allow object spread (should be available as experimental feature on eslint, but no way to make it works on js2-mode or react-mode)

Object spread works in js2-mode now.

@ashnur
Copy link

ashnur commented Jul 14, 2016

Where is all this coming from? js-mode is a part of Emacs, and as such is maintained with the rest of
Emacs's development. It's not deprecated.

I am sorry, I was wrong. It is actually worked on. Too bad this does not really show unless you go to the source because for me that mode was unusable for years now.

Object spread works in js2-mode now.

Great. One thing from hundreds works.
Does it have full ES2015 support, ASI support and does it allow indenting that is not ugly?

If I open my javascript code in it, would I have to wrestle with the editor to keep the formatting style consistent?

@dgutov
Copy link

dgutov commented Jul 14, 2016

Too bad this does not really show unless you go to the source because for me that mode was unusable for years now.

When did you last file a bug about that?

Does it have full ES2015 support

To my knowledge. File issues if it doesn't.

ASI support

That has been there for years.

does it allow indenting that is not ugly?

Absolutely. Not ugly to me, at least.

@ashnur
Copy link

ashnur commented Jul 14, 2016

@dgutov If it works for you be happy with it. Why come and argue with me though?

edit: No, really. Just because you use a style that is allowed and enabled by the available tools, doesn't mean it's "working" for everyone else too, as you can see others struggling with this problem too.
I don't file bugs because that would require knowledge that is beyond my reach at the moment.
ASI support is definitely not there for example, as the indentation always gets crazy and you can't line up stuff vertically only with considerable pain or leaving out auto-indenting, which is again, considerable pain.

@ashnur
Copy link

ashnur commented Sep 29, 2016

@dgutov
Copy link

dgutov commented Sep 29, 2016

@ashnur Indeed, the comma-first style isn't supported. But you can't really force someone to work on it by complaining.

Even if you could, this particular issue is a poor venue for it; the Emacs bug tracker is the standard place to do it, although there aren't many JS developers there. Maybe you could ask on Reddit, or the IRC channel. Either way probably calls for a tone change.

Asking questions like "does it allow indenting that is not ugly?" is vague and unhelpful.

ASI support is definitely not there for example, as the indentation always gets crazy

What does ASI have to do with indentation?

@ashnur
Copy link

ashnur commented Sep 29, 2016

@dgutov I agree with you. I also think that you should change your tone. Especially after you incorrectly and wrongfully insinuated that I am trying to force people to work on what I want. That comment is a huge strawman imho.

I also ask other people, this thread just became a collector of "why I dislike js2-mode". I don't want to change js2-mode though, because I believe that's not possible or at least not worthwhile. My only intent here and anywhere else I bring this up is to raise awareness that the situation is not as good as you and some others claim it to be.

ASI has and indentation are related because in my experience some auto-indent, formatting algorithms expect semicolons where they shouldn't really, or if they don't expect, but work differently if there are semicolons than if there aren't. I admit, that I might be wrong, and maybe this never happened. Doesn't change the big picture though, it doesn't really matter how many times you find some detail in what I said I wrote that is not correct, it changes nothing about the fact that js2-mode formatting is seriously lacking.

@dgutov
Copy link

dgutov commented Sep 29, 2016

My only intent here and anywhere else I bring this up is to raise awareness that the situation is not as good as you and some others claim it to be.

I don't believe I ever claimed comma-first indentation works in js2-mode.

@zyxue
Copy link

zyxue commented Oct 10, 2016

has the spread operation in incorporated into the react layer, please? e.g. ...this.state

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Forum - JavaScript stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

9 participants