MunifTanjim / prettier.nvim

Prettier plugin for Neovim's built-in LSP client.
MIT License
289 stars 9 forks source link

prettier disabled: configured in package.json #15

Closed yosiat closed 2 years ago

yosiat commented 2 years ago

Hi,

I am trying to use this plugin together with null-ls and looks it can't work in my projects setup, since I configure prettier (with shared config) in package.json like:

   "prettier": "shared-config-pkg"

Prettier is not being active source (checked with NullLsInfo) because of this line - https://github.com/MunifTanjim/prettier.nvim/blob/main/lua/prettier/utils.lua#L17

Is there any option to get configuration option working with current existing code? or a PR is needed?

Update: Managed to get prettier working with null-ls formatting support.

MunifTanjim commented 2 years ago

Can you switch to a prettier config file instead of using package.json? You'll just need to create .prettierrc.js with the content:

module.exports = {
  ...require("shared-config-pkg"),
};

and remove the "prettier" key from you package.json file.

yosiat commented 2 years ago

@MunifTanjim I am working on lots (20+) projects that are synced into github, doing this manual change and making sure not committing those changed will be cumbersome..

The change to support this way of work, what it requires from prettier.nvim except from changing config_file_exists function to check for package.json file with prettier key?

MunifTanjim commented 2 years ago

With the latest commit (https://github.com/MunifTanjim/prettier.nvim/commit/643fa3aba695eb1dfcbce8993c3b30a09b91ed6f) you can setup prettier.nvim like this:

prettier.setup({
  ["null-ls"] = {
    condition = function()
      return prettier.config_exists({
        check_package_json = true, 
      })
    end,
    -- other null-ls options
  },
  -- other prettier options
})

And it'll look for "prettier" key in the package.json file.