Skip to content

Commit

Permalink
json: tell prettier content is to be parsed as json
Browse files Browse the repository at this point in the history
In json-mode tell prettier the content is always to be parsed as json.
Fixes formatting in orgmode `#+BEGIN_SRC json` blocks as prettier
otherwise expects content as javascript.

Fixes: #11343
  • Loading branch information
tko committed Sep 23, 2018
1 parent ca8aa4e commit 28ad9b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions layers/+lang/json/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
;;
;;; License: GPLv3

(defun spacemacs/json-setup-prettier ()
"Tell prettier the content is to be parsed as JSON regardless of any file
extensions."
(when (eq json-fmt-tool 'prettier)
(setq-local prettier-js-args '("--parser=json"))))

(defun spacemacs/json-navigator-dwim (arg &optional start end)
"Display the JSON hierarchy of the whole buffer or the active region.
If ARG is a universal prefix argument then display the hierarchy after point."
Expand Down
3 changes: 3 additions & 0 deletions layers/+lang/json/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
(use-package json-mode
:defer t))

(defun json/post-init-json-mode ()
(add-hook 'json-mode-hook #'spacemacs/json-setup-prettier))

(defun json/init-json-navigator ()
(use-package json-navigator
:defer t
Expand Down

0 comments on commit 28ad9b1

Please sign in to comment.