Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json/prettier reformatting SyntaxError in orgmode BEGIN_SRC block #11343

Closed
tko opened this issue Sep 19, 2018 · 7 comments
Closed

json/prettier reformatting SyntaxError in orgmode BEGIN_SRC block #11343

tko opened this issue Sep 19, 2018 · 7 comments
Labels
- Bug tracker - Fixed in develop stale marked as a stale issue/pr (usually by a bot)

Comments

@tko
Copy link
Contributor

tko commented Sep 19, 2018

Description :octocat:

json/prettier reformatting doesn't work in orgmode BEGIN_SRC block, instead prettier complains about "SyntaxError"

The same content when edited in a .json file reformats without problem.

Reproduction guide 🪲

  • Start Emacs
  • Create test.org file containing
    #+BEGIN_SRC json
    {"type":
     1}
    #+END_SRC
    
  • Move within the BEGIN_SRC block and press , ' (org-edit-special)
  • Press , = to reformat the JSON in the buffer

Observed behaviour: 👀 💔

prettier errors:
[error] stdin: SyntaxError: Unexpected token, expected ";" (1:8)
[error] > 1 | {"type":
[error]     |        ^
[error]   2 |  1}
[error]   3 | 

Expected behaviour: ❤️ 😄
The buffer content is pretty-printed, something like

#+BEGIN_SRC json
{
  "type: 1
}
#+END_SRC

System Info 💻

  • OS: darwin
  • Emacs: 26.1
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. 9865e77)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(helm emacs-lisp neotree
      (javascript :variables javascript-fmt-tool 'prettier)
      (json :variables json-fmt-tool 'prettier))
  • System configuration features: NOTIFY ACL LIBXML2 ZLIB TOOLKIT_SCROLL_BARS THREADS
@Miciah
Copy link
Contributor

Miciah commented Sep 19, 2018

In your example BEGIN_SRC blocks, the example json is missing a double-quote: "type: should be "type":. However, from prettier's error message, it looks like you actually tested with "type":. So just to be clear, are you getting the reported error message with "type":?

@tko
Copy link
Contributor Author

tko commented Sep 19, 2018

I'm testing with valid json, so with "type": .. not sure what happened there.

@tko
Copy link
Contributor Author

tko commented Sep 20, 2018

I'm seeing the same error if just I pipe json through prettier. Apparently for json you need prettier --parser=json. There's prettier-js-args variable that can pass arguments to prettier, I guess that should be prefilled for json.

tko added a commit to tko/spacemacs that referenced this issue Sep 23, 2018
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: syl20bnr#11343
@tko
Copy link
Contributor Author

tko commented Sep 23, 2018

I guess similar hooks need to be set for all other modes (for which prettier is added) as well as prettier needs to be told what the real format is when used in orgmode. Related: prettier/prettier-emacs#38

tko added a commit to tko/spacemacs that referenced this issue Nov 4, 2018
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: syl20bnr#11343
d12frosted pushed a commit that referenced this issue Nov 7, 2018
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
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 28, 2020
@Miciah
Copy link
Contributor

Miciah commented Feb 28, 2020

Looks like #11364 fixed this issue on the develop branch.

@duianto
Copy link
Collaborator

duianto commented Mar 7, 2020

Thank you for posting an update.

@duianto duianto closed this as completed Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Bug tracker - Fixed in develop stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

4 participants