un-ts / prettier

:package: Opinionated but Incredible Prettier plugins.
https://prettier.vercel.app
MIT License
274 stars 25 forks source link

[prettier-plugin-sh]: automatic parser detection for `.husky/*` files. #347

Open kachkaev opened 8 months ago

kachkaev commented 8 months ago

πŸ‘‹ folks, thanks for this plugin!

WDYT of supporting some common file patterns out of the box, e.g. .husky/*? This glob could go somewhere here: https://github.com/un-ts/prettier/blob/3548bb2517aa7b115ec0d397c1e1779493d73d19/scripts/languages.ts#L6-L37

I have a few projects that use husky as well as prettier-plugin-sh. Files like .husky/pre-commit contain shell scripts but they are not assigned sh parser by Prettier out of the box. So I have to do this in prettier.config.js:

/** @type {import("prettier").Options} */
const config = {
  plugins: ["prettier-plugin-sh"],

  overrides: [
    {
      files: ".husky/*",
      options: {
        parser: "sh",
      },
    },
  ],
};

export default config;

It’d be cool to avoid overrides in this trivial case, which I guess could be done by tweaking the plugin. Happy to submit a PR if this makes sense.

JounQin commented 8 months ago

πŸ‘ PR welcome.

Actually, this plugin should detect hashbang automatically.

(Besides, I recommend to use https://github.com/toplenboren/simple-git-hooks over husky actually. Never mind.