prettier / pre-commit

Mirror of Prettier package for pre-commit.
5 stars 6 forks source link

Not possible to use plugins? #16

Open OJFord opened 4 years ago

OJFord commented 4 years ago

I'm trying to use prettier-plugin-svelte, but I think it's detected from being installed rather than in package.json(?) and so since there's no (good) way to put it in the pre-commit environment, it isn't picked up?

fisker commented 4 years ago

Will this work use additional_dependencies ?

- repo: https://github.com/prettier/pre-commit
  rev: main
  hooks:
    - id: prettier
      additional_dependencies:
        - prettier-plugin-svelte:1.4.1
joao-p-marques commented 4 years ago

Hi. I am having the same issue. When I try to install @prettier/plugin-xml, I get:

Executable `prettier` not found

My pre-commit config:

  - repo: https://github.com/prettier/pre-commit
    rev: v2.1.2
    hooks:
      - id: prettier
        name: prettier + plugin-xml
        additional_dependencies:
          - "@prettier/plugin-xml@0.12.0"
        args:
          - --plugin=@prettier/plugin-xm

It works fine without the plugin.

I am trying to migrate from https://github.com/prettier/prettier to https://github.com/prettier/pre-commit

joao-p-marques commented 4 years ago

This should be fixed with the PRs mentioned above.

Seems like the problem was that, in https://github.com/prettier/pre-commit/blob/main/.pre-commit-hooks.yaml, hook is defining additional_dependencies and args, that are needed for prettier to work. However, if we need to define more in our hook, the will be rewritten.

Moving them to separate definitions should work.

In the meantime, another workaround is to copy the needed values:

  - repo: https://github.com/prettier/pre-commit
    rev: v2.1.2
    hooks:
      - id: prettier
        name: prettier + plugin-xml
        additional_dependencies:
          - prettier@2.1.2
          - "@prettier/plugin-xml@0.12.0"
        args:
          - --write
          - --list-different
          - --ignore-unknown
          - --plugin=@prettier/plugin-xml
fisker commented 4 years ago

It's also possible to use plugins in config file

{
  "plugins": [
    "@prettier/plugin-xml",
    "path/to/your/plugin"
  ]
}