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

Wrong json-mode formatter chosen when specified in dir-locals file #328

Closed
daut opened this issue Oct 30, 2024 · 5 comments
Closed

Wrong json-mode formatter chosen when specified in dir-locals file #328

daut opened this issue Oct 30, 2024 · 5 comments

Comments

@daut
Copy link

daut commented Oct 30, 2024

I'm trying to specify different formatters for three different modes in .dir-locals.el file. Here's how the file looks like.

((js-mode . ((apheleia-formatter . eslint)))
 (json-mode . ((apheleia-formatter . prettier-json)))
 (web-mode . ((apheleia-formatter . eslint))))

js and web mode files are correctly using eslint formatter, but json-mode incorrectly uses eslint as well. When I delete the first line from the above dir-locals file json-mode correctly has prettier-json set in the apheleia-formatter variable.

I'm suspecting this is caused by the fact that javascript-mode is json-mode's parent, but don't have an idea how to fix it. Are there any ways around this?

@raxod502
Copy link
Member

raxod502 commented Feb 7, 2025

Hm. When I create that .dir-locals.el file and open a JSON file in the same directory, the value of the variable apheleia-formatter in that buffer is prettier-json.

What version of Emacs is this? I am testing with 28.1.

@daut
Copy link
Author

daut commented Feb 11, 2025

I'm on 29.1.

GNU Emacs 29.1 (build 1, aarch64-apple-darwin23.1.0, NS appkit-2487.20 Version 14.1.1 (Build 23B81)) of 2023-11-19

@raxod502
Copy link
Member

Okay, I can reproduce this - make docker VERSION=29 CMD="make fmt-emacs" and then create the described files.

@raxod502
Copy link
Member

Oh, okay.

The problem is in Emacs 29 there is a builtin json-mode, but it's not called json-mode, it's called js-json-mode.

Change your .dir-locals.el as:

((js-json-mode . ((apheleia-formatter . eslint)))
 (json-mode . ((apheleia-formatter . prettier-json)))
 (web-mode . ((apheleia-formatter . eslint))))

(or include entries for both mode names if you want to cover both versions).

Meanwhile in Emacs 28 my json-mode is provided by an external package and is really called json-mode.

@daut
Copy link
Author

daut commented Feb 12, 2025

OK, thanks!

I was actually using json-mode too for .json files. Switching to js-json-mode does solve the issue.

@daut daut closed this as completed Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants