Prettier shell script format

Viewed 2914

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

2 Answers

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.

Prettier cannot format bash files. Instead you can try either shell-format or Bash Beautify extensions for VSCode to format your bash scripts.

Related