Skip to content

Instantly share code, notes, and snippets.

@RockyRoad29
Created November 19, 2017 09:49
Show Gist options
  • Save RockyRoad29/598ef01cae013042e21a1ae99e6f6267 to your computer and use it in GitHub Desktop.
Save RockyRoad29/598ef01cae013042e21a1ae99e6f6267 to your computer and use it in GitHub Desktop.
Emacs js2-mode hook - Avoid "Code has no side effect" warnings in tests using chaijs
;; Get rid of extraneous warnings from js2-mode when using chai test library, e.g.
;; expect(o.loaded).to.be.false;
;; triggers "Code has no side effect"
;;
;; This is just a workaround: such messages will be removed for the whole file.
(defun rr-js2-tests-filter-warnings ()
(setq js2-parsed-warnings
(let (rslt)
(dolist (e js2-parsed-warnings (reverse rslt))
(when (not (string= (caar e) "msg.no.side.effects"))
(setq rslt (cons (caar e) rslt))
))
))
)
(add-hook 'js2-mode-hook
(lambda ()
(when (or
(string-match-p "/tests?/.*\\.js$" (buffer-file-name))
(string-match-p "\\.spec\\.js$" (buffer-file-name))
))
(add-hook 'js2-post-parse-callbacks 'rr-js2-tests-filter-warnings)
)
)
@finalclass
Copy link

Very nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment