SZJX
Default Javascript Linter (e.g. ESLint) Configuration/Standard?
When programming Javascript files with Emacs/Vim etc. a linter like ESLint is likely enabled. In my case it seems that the default airbnb style configuration is not very compatible with default Javascript files generated by Phoenix. For example, airbnb standard insists on using singlequotes for strings while Phoenix generates double-quoted ones. Also it insists on appending semicolons which are by default not there. This results in the linter showing a lot of errors in a JS file.
I would like to know, is there any kind of standard followed by Phoenix when generating its Javascript files, or is there any convention/consensus in the community? Ideally I would be able to set the default options of ESLint to report much fewer errors.
Or is it the case that this really varies a lot from person to person and since the Javascript files generated by default are relatively few, the user should just modify the default files to their own taste and follow their own standard when writing new JS files?
Most Liked
sotojuan
Sure, but the standard linter lints against the gotchas of no semis. But yes, without it you’ll be in danger!
sotojuan
Agreed. I actually find Phoenix’ default JavaScript strange and ugly lol. I get it that they tried to make it look like Elixir, but it’s a different language.
Most people use single quotes in JavaScript, so most pre-configured linters will prefer them. I also use Standard for all my JavaScript stuff. I recommend that Phoenix at least generate JavaScript that conforms to most people’s uses (Airbnb or Standard).
peerreynders
[quote=“SZJX, post:1, topic:1745”]the user should just modify the default files to their own taste and follow their own standard when writing new JS files?
[/quote]
This would be my assumption - (unless there is re-generated JS in Phoenix which I haven’t come across yet). Obviously the Phoenix project has made some of it’s own choices (for whatever reason) but that shouldn’t override your needs (i.e. your custom eslint configuration).
So I’d basically “clean up” the initial JS assets placed by mix in web/static/js to conform with my chosen standard and move forward from there.
Probably a lost cause given how divisive just the semicolon issue is (e.g. hence the existence of semistandard).
Last Post!
peerreynders
If anybody is looking for a more challenging ESlint standard: eslint-config-cleanjs
Highlights:
- no
thisand no classes- no
nullandundefined(implying that all functions mustreturn)- no mutation of any kind
- no variable reassignment
- no statements, only expressions (including no
if)- no CommonJS or AMD, only ES6 modules
![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









