Giter VIP home page Giter VIP logo

Comments (15)

jbr avatar jbr commented on May 16, 2024 4

@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.

rcoedo avatar rcoedo commented on May 16, 2024 3

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.

soywod avatar soywod commented on May 16, 2024 3

@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.

wpcarro avatar wpcarro commented on May 16, 2024 1

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.

nickmccurdy avatar nickmccurdy commented on May 16, 2024 1

IMO this is solved by add-node-modules-path and isn't necessary to fix in this package.

from prettier-emacs.

mattdeboard avatar mattdeboard commented on May 16, 2024

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.

mattdeboard avatar mattdeboard commented on May 16, 2024

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.

joefiorini avatar joefiorini commented on May 16, 2024

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.

mattdeboard avatar mattdeboard commented on May 16, 2024

@joefiorini Can you explain more about how you used --stdin-filepath to make this plugin respect your .prettierrc?

from prettier-emacs.

mattdeboard avatar mattdeboard commented on May 16, 2024

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.

mattdeboard avatar mattdeboard commented on May 16, 2024

@jbr Might work for you as well.

from prettier-emacs.

giodamelio avatar giodamelio commented on May 16, 2024

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.

jbr avatar jbr commented on May 16, 2024

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.

nickmccurdy avatar nickmccurdy commented on May 16, 2024

That's odd, I have changed my prettier config in package.json and prettier-js-mode picks it up automatically.

from prettier-emacs.

jbr avatar jbr commented on May 16, 2024

I think #10 actually fixed this. Closing the issue. Thanks, all.

from prettier-emacs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.