Created
November 19, 2017 09:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gets rid of extraneous warnings from js2-mode when using chai test library, e.g.
triggers
Code has no side effect
warning.This is just a workaround: such messages will be removed for the whole file.