• Stars
    star
    476
  • Rank 92,280 (Top 2 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Prettier plugin for Astro

Prettier Plugin for Astro

Official Prettier plugin adding support for formatting .astro files.

Installation

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

Recommended configuration

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

module.exports = {
  plugins: [require.resolve('prettier-plugin-astro')],
  overrides: [
    {
      files: '*.astro',
      options: {
        parser: 'astro',
      },
    },
  ],
};

Alternatively, for use inside a non-JS config file, the require.resolve call can be changed to a direct path, such as plugins: ["./node_modules/prettier-plugin-astro"].

To customize formatting behavior, see the Configuration section below.

Using in VS Code

Note If you're using Astro's VS Code extension, Prettier and this plugin are already included. Only follow the guide below to format using Prettier's official extension.

First 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} />)

Default CLI Override API 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 generously supported by Netlify, Storyblok, and several other amazing organizations.

❀️ Sponsor Astro! ❀️

sponsors

More Repositories

1

astro

The web framework for content-driven websites. ⭐️ Star to support our work!
TypeScript
45,685
star
2

starlight

🌟 Build beautiful, accessible, high-performance documentation websites with Astro
TypeScript
4,627
star
3

docs

Astro documentation
MDX
1,303
star
4

storefront

Astro for ecommerce πŸ’°
TypeScript
561
star
5

compiler

The Astro compiler. Written in Go. Distributed as WASM.
Go
482
star
6

astro.build

MDX
384
star
7

roadmap

Ideas, suggestions, and formal RFC proposals for the Astro project.
291
star
8

language-tools

Language tools for Astro
TypeScript
262
star
9

houston.astro.build

Experimental AI assistant trained on the Astro docs
Astro
248
star
10

blog-tutorial-demo

Astro
157
star
11

action

A GitHub Action that deploys your Astro project to GitHub Pages
152
star
12

houston-vscode

Visual Studio Code theme featuring cool blues, minty greens, and soft purples
CSS
131
star
13

adapters

Home for Astro's core maintained adapters
TypeScript
63
star
14

cli-kit

JavaScript
52
star
15

github-pages

Automatically deploy an Astro site to GitHub Pages
Astro
35
star
16

astro.new

Astro
33
star
17

wormhole

TypeScript
25
star
18

astro-repl

TypeScript
24
star
19

.github

Community health files for the @withastro organization
17
star
20

contribute.docs.astro.build

An entire Starlight site for the Astro Docs contributor guides.
MDX
17
star
21

site-kit

Styles, components, and tooling config for use in *.astro.build websites
JavaScript
16
star
22

esnext-conf-2020

Pika Presents: ESNEXT CONF 2020
HTML
12
star
23

view-transitions-demo

Astro
11
star
24

automation

Centralized repo for GitHub actions for the `withastro` org
11
star
25

studio-templates

Astro
11
star
26

houston-discord

TypeScript
9
star
27

astro-playground

TypeScript
7
star
28

action-studio

TypeScript
7
star
29

astro-ecosystem-ci

Astro Ecosystem CI
TypeScript
6
star
30

server-islands

Server islands demo
Astro
6
star
31

ASTRO-E2

beep boop beep boop
JavaScript
5
star
32

templates

A mirror of the examples from the main monorepo
Astro
5
star
33

astro-og-image

JavaScript
4
star
34

support-docs

A Starlight site for the Astro Support contributor guides.
CSS
3
star
35

withastro.github.io

HTML
2
star