0.13.0 • Published 4 months ago

prettier-plugin-astro v0.13.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Prettier Plugin for Astro

Official Prettier plugin adding support for formatting .astro files.

Installation

First install Prettier and the plugin:

npm i --save-dev prettier prettier-plugin-astro

Then add the plugin to your Prettier configuration:

// .prettierrc.mjs
/** @type {import("prettier").Config} */
export default {
  plugins: ['prettier-plugin-astro'],
};

Recommended configuration

For optimal compatibility with the different package managers and Prettier plugins, we recommend manually specifying the parser to use for Astro files in your Prettier config as shown in the example below:

// .prettierrc.mjs
/** @type {import("prettier").Config} */
export default {
  plugins: ['prettier-plugin-astro'],
  overrides: [
    {
      files: '*.astro',
      options: {
        parser: 'astro',
      },
    },
  ],
};

To customize formatting behavior, see the Configuration section below.

Formatting with the VS Code Prettier extension directly

Note The Astro VS Code extension uses Prettier and this plugin (prettier-plugin-astro) to format your code. You will only need to install the VS Code Prettier extension separately for formatting if:

  • You are not using Astro's VS Code extension.
  • You want to use features of the Prettier extension that not supported by Astro's own VS Code extension, such as the toolbar panel showing Prettier's status.

Install the VS Code Prettier extension and add the following settings to your VS Code configuration:

{
  "prettier.documentSelectors": ["**/*.astro"],
  "[astro]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

The settings above ensure that VS Code is aware that Prettier can be used for Astro files, and sets Prettier as the default formatter for Astro files.

Reporting issues

When submitting issues about formatting your .astro files in VS Code, please specify which extension you are using to format your files: Astro's own extension or the Prettier extension.

Configuration

Most options from Prettier will work with the plugin and can be set in a configuration file or through CLI flags.

Astro Allow Shorthand

Set if attributes with the same name as their expression should be formatted to the short form automatically (for example, if enabled <element name={name} /> will become simply <element {name} />)

DefaultCLI OverrideAPI Override
false--astro-allow-shorthand <bool>astroAllowShorthand: <bool>

Example .prettierrc.cjs

{
  astroAllowShorthand: false;
}

Contributing

Pull requests of any size and any skill level are welcome, no contribution is too small. Changes to the Astro Prettier Plugin are subject to Astro Governance and should adhere to the Astro Style Guide.

See CONTRIBUTING.md for instructions on how to set up your development environment.

Sponsors

Astro is free, open source software made possible by these wonderful sponsors.

❤️ Sponsor Astro! ❤️

0.13.0

4 months ago

0.12.3

4 months ago

0.12.1

7 months ago

0.12.2

6 months ago

0.11.0

10 months ago

0.12.0

9 months ago

0.11.1

9 months ago

0.10.0

11 months ago

0.9.1

12 months ago

0.9.0

12 months ago

0.8.1

12 months ago

0.8.0

1 year ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.5

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.1.0-next.5

2 years ago

0.1.0

2 years ago

0.3.0

2 years ago

0.1.2

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.1.3

2 years ago

0.1.0-next.3

2 years ago

0.1.0-next.4

2 years ago

0.1.0-next.0

2 years ago

0.1.0-next.1

2 years ago

0.1.0-next.2

2 years ago

0.0.12

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.1

3 years ago