<img alt="Prettier" src="https://cdn.rawgit.com/prettier/prettier-logo/master/images/prettier-icon-light.svg">
<img alt="Pug" src="https://cdn.rawgit.com/pugjs/pug-logo/eec436cee8fd9d1726d7839cbe99d1f694692c0c/SVG/pug-final-logo-_-colour-128.svg" height="210">
Prettier Pug plugin
<img alt="license: MIT" src="https://img.shields.io/github/license/prettier/plugin-pug.svg?style=flat-square">
<img alt="NPM package" src="https://img.shields.io/npm/v/@prettier/plugin-pug.svg?style=flat-square">
<img alt="downloads" src="https://img.shields.io/npm/dt/@prettier/plugin-pug.svg?style=flat-square">
<img alt="Code Style: Prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square">
<img alt="Build Status" src="https://github.com/prettier/plugin-pug/actions/workflows/ci.yml/badge.svg?branch=main">
This plugin adds support for the Pug language to Prettier.
- Getting started
- Workarounds / Known Issues
- Integration with editors
- Implementation details
Getting startedSimply install
@prettier/plugin-pugas your project’s
npm add --save-dev prettier @prettier/plugin-pug # or yarn add --dev prettier @prettier/plugin-pug # or pnpm add --save-dev prettier @prettier/plugin-pug
npx prettier --write "**/*.pug" # or yarn prettier --write "**/*.pug" # or pnpm prettier --write "**/*.pug"
Workaround / Known IssueThere are some code examples that are not formatted well with this plugin and can damage your code.
But there are workarounds for it. These generate even better pug code!
If you have tags at the top/root that are indented, they will lose indentation due to a technical limitation of pug.
Please check these before committing after running this plugin for the first time and fix them manually.
Integration with editorsIf you are using a text editor that supports Prettier integration (e.g. Atom), you can have all Prettier perks for your Pug code too!
Use VSCode extension to get support for VSCode.
In order to get
@prettier/plugin-pugworking in projects that do not have local npm dependencies, you can install this plugin globally:
npm install --global prettier @prettier/plugin-pug
In this case, you might need to check the settings of your editor’s Prettier extension to make sure that a globally installed Prettier is used when it is not found in project dependencies (i.e.
Nevertheless, it is recommended to rely on local copies of
@prettier/plugin-pugas this reduces the chance of formatting conflicts between project collaborators. This may happen if different global versions of Prettier or its Pug plugin are used.
@prettier/plugin-pugeither locally or globally may require you to restart the editor if formatting does not work right away.
Implementation detailsThis plugin is written in TypeScript and its quality is maintained using Prettier and Vitest.
ContributingIf you’re interested in contributing to the development of Prettier for Pug, you can follow the CONTRIBUTING guide from Prettier, as it all applies to this repository too.
- Clone this repository.
pnpm run lintto make sure that the code passes formatting and linting.
CreditsThis project was inspired by https://github.com/gicentre/prettier-plugin-elm.
Many thanks also to @j-f1, @lipis and @azz for the help in transferring this repository to the prettier organization.
Thanks to @Peilonrayz, who gave me the idea to rewrite the printer into a class and thus make the code a lot more maintainable.
Thanks to @lehni, @SkyaTura and @shadowgate15 for the massive contribution and the introduction of many new features into the project.