eslint with xo in Emacs

Configure

For project specific js-mode settings, I used M-x add-dir-local-variable to create and build up .dir-locals.el like

((js-mode . ((flycheck-javascript-eslint-executable . "xo")
	     (flycheck-eslint-args . "--reporter=json")
	     (flymake-eslint-executable-args . "--reporter=json")
	     (flymake-eslint-executable-name . "xo")
	     (evil-indent-convert-tabs . t)
	     (indent-tabs-mode . t)
	     (tab-width . 2)
	     (editorconfig-mode . t))))

flymake settings are included, but flycheck is what ultimately worked.

Notes

I got here trying to hack on awesome-lint a bit. The repo is setup to use xo, ava, and editorconfig.

Lint with xo

xo wraps eslint with defaults such that .eslintrc.mjs or similar file isn't needed.

ALE (neo/vim) does the right thing out of the box for both linting and :ALEFix xo. And vim-test's :TestFile works for ava.

The closest I could get to ALE's out of the box support in emacs is to

  1. globally installing eslint and xo (npm -g --save-dev xo).1 and modifying flycheck eslint settings to use xo and --reporter=json.
  2. %!xo --fix --stdin (or M-! xo --fix $file C-x x g; or C-u M-| xo --fix --stdin on selection)
  3. toffee doesn't support javascript. M-! ../../node_modules/ava/entrypoints/cli.mjs $file doesn't work unless in project root. node_modules/ava/entrypoints/cli.mjs --watch works well for change tests but will rerun everything if source files change.

CLI

xo --reporter=unix testfile.js

or much faster but more ceremony

cat .eslint.mjs <<-HERE
module.exports = {
	root: true,
	extends: "eslint:recommended",
	parserOptions: { sourceType: 'module',  ecmaVersion: 2015 },
	rules: {indent: ["error", "tab"], },
};

HERE

eslint_d testfile.js

Aside: xo's default reporter is mangling my terminal (xterm) font. my kludge, fzf-font, helps reset (but font inc and dec wont work afterward).

EditorConfig

There's a emacs package for editorconfig. enabling it in .dir-locals with (editorconfig-mode . t).


1

could maybe write a mode hook that searches and sets $projectroot/.node_modules/


..