Comments (15)
@mattdeboard this type of solution assumes that there's only one project, which means that switching between repos requires editing prettier settings between each save
from prettier-emacs.
Excuse me for the delay on this. I believe you can achieve this using a tool like this one. It allows emacs to add to path the bin folder in node_modules
. With this I think Emacs will use your node_modules/.bin/prettier and it will read your local configuration
https://github.com/codesuki/add-node-modules-path
from prettier-emacs.
@jbr this didn't fix the issue for me (with TypeScript / TSX). To make it work with tide, I had to install add-node-modules-path (thanks @rcoedo), remove before-save
:
(use-package tide
:ensure t
:after (typescript-mode company flycheck)
:hook ((typescript-mode . tide-setup)
(typescript-mode . tide-hl-identifier-mode)))
; (before-save . tide-format-before-save)))
and add:
(add-hook 'before-save-hook 'prettier-js-mode)
(eval-after-load
'typescript-mode
'(add-hook 'typescript-mode-hook #'add-node-modules-path))
from prettier-emacs.
I tried using vim-prettier and it seems to be reading my .prettierrc
, which is fantastic. I expected similar behavior in Emacs. Perhaps there is some configuration in vim-prettier that needs to be ported to the prettier-emacs?
from prettier-emacs.
IMO this is solved by add-node-modules-path
and isn't necessary to fix in this package.
from prettier-emacs.
I like this idea. The mode should be driven by the config file. Even when I add "--config" "/abs/path/to/.prettierrc"
to prettier-js-args
, it still doesn't work out.
from prettier-emacs.
Actually it looks like prettier
itself does not have any protection in place for my personal issue.
For example, I added "requirePragma": true
to my .prettierrc
.
When I run prettier -l "src/**/*.js"
I get nothing. But when I just do prettier "src/**/*.js"
it lists out all the changes it would make. Even if I do prettier "src/**/*.js" --require-pragma
it still lists out everything.
So this seems like a problem with prettier, not necessarily with prettier-emacs
.
from prettier-emacs.
UPDATE: Never mind, apparently I was still on an older version of prettier and didn't realize it. Thanks to the --stdin-filepath
this does work for the use case below.
I am sad that this doesn't work. We have a big team and I want to make sure everyone is using the same settings. I have a config file with singleQuote: true
, but when I run prettier in emacs (even with --config /abs/path/to/.prettierrc
it still formats with double quotes. I don't understand why it wouldn't work if we directly specify the config file path. Is there something in prettier stopping it from applying when you use --stdin
?
from prettier-emacs.
@joefiorini Can you explain more about how you used --stdin-filepath
to make this plugin respect your .prettierrc
?
from prettier-emacs.
Aha, wait, here we go.
Before, I was doing this:
(setq prettier-js-command (concat HOME "path/to/project/node_modules/.bin/prettier"))
(setq prettier-js-args
`("--config " ,(concat HOME "path/to/project/.prettierrc")
"--write"))
I changed it to this and it works:
(setq prettier-js-command (concat HOME "path/to/project/node_modules/.bin/prettier"))
(setq prettier-js-args
`(,(concat "--config " (concat HOME "path/to/project/.prettierrc"))
"--write"))
from prettier-emacs.
@jbr Might work for you as well.
from prettier-emacs.
Ya, it would be great if could check if prettier is installed in the current project and use it, otherwise use the globally installed prettier if it exists.
from prettier-emacs.
I think there are a few different related issues. I'm not having trouble finding the binary, but have project-specific prettier settings in my package.json, as is supported by the prettier cli tool. This bug also applies to projects that use prettierrc. Prettier traverses up from the file in question until it finds a project configuration file and applies those settings. prettier-emacs moves files to a temp directory, so those project-specific configuration files are not found. It is possible to specify the settings in prettier-emacs customize-group (through args), but if you're working on multiple projects with different settings, prettier emacs will not adapt, but prettier on the cli will.
tldr: there is a distinct issue has nothing to do with the binary path, but has to do with the fact that the file to be prettier-ed is moved out of the project directory
from prettier-emacs.
That's odd, I have changed my prettier
config in package.json
and prettier-js-mode
picks it up automatically.
from prettier-emacs.
I think #10 actually fixed this. Closing the issue. Thanks, all.
from prettier-emacs.
Related Issues (20)
- "No such file or directory" "prettier" Error HOT 1
- Using eslint_d to do the same as this package
- [question] "prettier-js is an available obsolete package."
- Disable formatting on save HOT 3
- prettier empties file HOT 1
- Could not apply prettier HOT 1
- diff error on OpenBSD
- prettier-js-mode reformats file even when file is in .prettierignore HOT 3
- "prettier errors: env: node: No such file or directory" HOT 6
- Highlighting "flickering" while applying formatting HOT 2
- Searching for program: No such file or directory, prettier HOT 2
- [warn] Ignored unknown option --stdin HOT 1
- Convenient way to disable per file HOT 1
- No files matching the pattern were found: "false". HOT 2
- Cannot find prettier anywhere HOT 2
- Prettier not formatting typescript file HOT 1
- do not respect .prettierignore
- Not working with prettier 3.0.1 HOT 2
- Handle cloned buffers and give error message when not visiting a file
- prettier-js cleanse the code HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettier-emacs.