Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kachkaev opened this issue Feb 2, 2024 · 1 comment
Open

Comments

@kachkaev
Copy link

kachkaev commented Feb 2, 2024

👋 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:

const EXTRA_SH_LANGUAGES: SupportLanguage[] = [
{
name: 'JvmOptions',
since: '0.1.0',
parsers: ['sh'],
extensions: ['.vmoptions'],
filenames: ['jvm.options'],
vscodeLanguageIds: ['jvmoptions'],
},
{
name: 'hosts',
since: '0.1.0',
parsers: ['sh'],
filenames: ['hosts'],
vscodeLanguageIds: ['hosts'],
},
{
name: 'dotenv',
since: '0.1.0',
parsers: ['sh'],
extensions: ['.env'],
filenames: ['.env.*'],
vscodeLanguageIds: ['dotenv'],
},
{
name: 'nvmrc',
since: '0.14.0',
parsers: ['sh'],
extensions: ['.node-version', '.nvmrc'],
filenames: ['.node-version', '.nvmrc'],
},
]

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
Copy link
Member

JounQin commented Feb 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants