Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
prettier-plugin-astro
Advanced tools
The prettier-plugin-astro package is a plugin for Prettier that adds support for formatting Astro files. Astro is a modern static site builder that allows you to use components from various frameworks like React, Vue, and Svelte. This plugin ensures that your Astro files are consistently formatted according to Prettier's rules.
Formatting Astro Components
This feature allows you to format Astro components, ensuring that the HTML, JavaScript, and any other embedded code are properly indented and styled according to Prettier's rules.
<!-- Example Astro Component -->
---
const title = 'Hello, World!'
---
<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{title}</h1>
</body>
</html>
Formatting Embedded JavaScript
This feature ensures that any JavaScript code embedded within your Astro files is formatted correctly, maintaining consistency and readability.
<!-- Example Astro Component with JS -->
---
const items = [1, 2, 3, 4, 5]
---
<ul>
{items.map(item => (
<li key={item}>{item}</li>
))}
</ul>
Formatting Embedded CSS
This feature ensures that any CSS code embedded within your Astro files is formatted according to Prettier's rules, making your styles consistent and easy to read.
<!-- Example Astro Component with CSS -->
<style>
h1 {
color: blue;
}
</style>
<h1>Hello, World!</h1>
The prettier-plugin-svelte package is a Prettier plugin that adds support for formatting Svelte files. Like prettier-plugin-astro, it ensures that your Svelte components are consistently formatted. However, it is specific to Svelte and does not support the multi-framework nature of Astro.
The prettier-plugin-vue package is a Prettier plugin that adds support for formatting Vue.js single-file components (SFCs). It ensures that your Vue components are consistently formatted, but it is specific to Vue.js and does not support the multi-framework nature of Astro.
Official Prettier plugin adding support for formatting .astro
files.
npm i --save-dev prettier-plugin-astro prettier
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.
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.
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.
Most options from Prettier will work with the plugin and can be set in a configuration file or through CLI flags.
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> |
.prettierrc.cjs
{
astroAllowShorthand: false;
}
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.
Astro is generously supported by Netlify, Storyblok, and several other amazing organizations.
0.10.0
synckit
, improving performance and reducing the dependency count of the pluginFAQs
A Prettier Plugin for formatting Astro files
The npm package prettier-plugin-astro receives a total of 129,253 weekly downloads. As such, prettier-plugin-astro popularity was classified as popular.
We found that prettier-plugin-astro demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.