Search code examples
javascriptbashshellvisual-studio-codeprettier

Prettier shell script format


Can I format template literal embedded shell script with Prettier ?

Example:

Before formating:

import {bash} from 'random-bash-runner'

await bash`
a_bash_command argument1 \
     main-dev \
argument4 --database=name --quiet`

After formatting:

import {bash} from 'random-bash-runner'

await bash`
  a_bash_command argument1 \
    main-dev \
    argument4 l \
    --database=name --quiet
`

Thanks


Solution

  • Prettier can, with the setting --embedded-language-formatting=auto (see here), format templates.

    However, the languages it can format (from it's extension page on VSCode) are:

    JavaScript · TypeScript · Flow · JSX · JSON
    CSS · SCSS · Less
    HTML · Vue · Angular
    GraphQL · Markdown · YAML
    

    So I'm afraid no, this cannot be accomplished by Prettier as bash or shell are not on this list.