This setup adheres to JavaScript Standard Style; unfortunately due to conflict between standard
's ruleset and Chai assertions, we have to acheive this by using eslint
directly + the Standard rules. Since we can't use standard
directly, we also throw in Prettier for code formatting. Specifically, we use prettier-standard to keep all of the pieces working together nicely. What's that mean for you? Well, here's the scoop on setting up a few editors for linting/formatting fun.
If you're using Vim, you should be using ALE. It's a fantastic asynchronous linting engine (which is what ALE stands for). After installing, ALE's linting setup doesn't need any tweaking, but you'll need to explicitly specify a fixer for Javascript:
" In ~/.vim/ftplugin/javascript.vim, or somewhere similar.
" Fix files with prettier, and then ESLint.
let b:ale_fixers = ['prettier_standard']
" Equivalent to the above.
let b:ale_fixers = {'javascript': ['prettier_standard']}
Additionally, you may want to specify some additional global config in your .vimrc
(if you have not done so already):
" Runs the fixer upon save; otherwise :ALEFix will need to be run manually
let g:ale_fix_on_save = 1
" Opens a list of the formatting/linting errors upon save
let g:ale_open_list = 'on_save'
" Switches the list of errors from a loclist to the quickfix list
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
Spacemacs needs the following configuration layers enabled in your ~/.spacemacs
file:
dotspacemacs-configuration-layers
'(
...
(javascript :variables node-add-modules-path t)
syntax-checking
...
)
Additionally you'll need to disable js2-mode
's built-in syntax checking by setting the following in the defun dotspacemacs/user-config ()
section:
(defun dotspacemacs/user-config ()
...
(setq-default
...
js2-mode-show-parse-errors nil
js2-mode-show-strict-warnings nil
...
)
...
)
Note that this only enables linting; code formatting with Prettier isn't covered. That's not to say it can't be done, just that we haven't figured out how to do it yet. Consquently you'll still need to duck out to the command line and run npm run-script format
or yarn format
to tidy up your code.
Coming soon.
- Install the
prettier-atom
package (including, if necessary, thelinter
dependency) - In
prettier-atom
's settings, enable the following:- ESLint Integration
- Format Files on Save
- Install the
linter-eslint
package - In
linter-eslint
's settings, enable the following:- Ignore fixable rules while typing
- Restart Atom and install any necessary dependencies