• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated 5 days ago

Reviews

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

Repository Details

Prettier Pug Plugin

     Prettier           Pug     

Prettier Pug plugin

license: MIT NPM package downloads Code Style: Prettier Build Status

Intro

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

This plugin adds support for the Pug language to Prettier.


Getting started

Simply install prettier and @prettier/plugin-pug as your project’s devDependencies:

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

Usage

npx prettier --write "**/*.pug"
# or
yarn prettier --write "**/*.pug"
# or
pnpm prettier --write "**/*.pug"

Configuration

See documentation

Workaround / Known Issue

There 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!

Example

Issue 114

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 editors

If 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-pug working 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. package.json).

Nevertheless, it is recommended to rely on local copies of prettier and @prettier/plugin-pug as 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.

Installing @prettier/plugin-pug either locally or globally may require you to restart the editor if formatting does not work right away.

Implementation details

This plugin is written in TypeScript and its quality is maintained using Prettier and Vitest.

Contributing

If 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.

To run @prettier/plugin-pug locally:

  • Clone this repository.
  • Execute pnpm install.
  • Execute pnpm run lint to make sure that the code passes formatting and linting.
  • Execute pnpm run test to make sure that TypeScript successfully compiles into JavaScript and all unit tests pass.

Credits

This 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 @fisker for the constant help and support in terms of Prettier Core support.

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.

Thanks to @maoberlehner to acknowledge @prettier/plugin-pug as officially well TTD tested at Vue Amsterdam 2023.

More Repositories

1

prettier

Prettier is an opinionated code formatter.
JavaScript
49,325
star
2

eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.
JavaScript
5,386
star
3

prettier-vscode

Visual Studio Code extension for Prettier
TypeScript
5,130
star
4

prettier-eslint

Code ➡️ prettier ➡️ eslint --fix ➡️ Formatted Code ✨
JavaScript
3,994
star
5

eslint-plugin-prettier

ESLint plugin for Prettier formatting
JavaScript
3,283
star
6

pretty-quick

⚡ Get Pretty Quick
TypeScript
2,211
star
7

vim-prettier

A Vim plugin for Prettier
Vim Script
1,780
star
8

plugin-php

Prettier PHP Plugin
PHP
1,736
star
9

plugin-ruby

Prettier Ruby Plugin
JavaScript
1,462
star
10

tslint-config-prettier

Use TSLint with Prettier without any conflict
TypeScript
1,234
star
11

prettier-atom

An atom package for the prettier formatter.
JavaScript
755
star
12

prettier-eslint-cli

CLI for prettier-eslint
JavaScript
541
star
13

plugin-python

Prettier Python Plugin
JavaScript
517
star
14

prettier-emacs

Minor mode to format JS code on file save
Emacs Lisp
374
star
15

stylelint-config-prettier

Turns off all rules that are unnecessary or might conflict with prettier.
JavaScript
374
star
16

stylelint-prettier

Stylelint plugin for Prettier formatting
JavaScript
346
star
17

plugin-swift

[DEPRECATED] Prettier Swift Plugin - WARNING: The AST parser is not stable yet
JavaScript
274
star
18

tslint-plugin-prettier

Runs Prettier as a TSLint rule and reports differences as individual TSLint issues
TypeScript
235
star
19

plugin-xml

Prettier XML plugin
JavaScript
229
star
20

prettier-browser-extension

Prettier Browser Extension
JavaScript
200
star
21

plugin-lua

Prettier Lua Plugin (WIP)
Lua
78
star
22

prettier-logo

The Prettier logo.
JavaScript
39
star
23

prettier-cli

TypeScript
28
star
24

yaml-unist-parser

A YAML parser that produces output compatible with unist
TypeScript
25
star
25

prettier-synchronized

Synchronous version of Prettier
JavaScript
24
star
26

stylelint-config-prettier-scss

Turns off all CSS and SCSS rules that are unnecessary or might conflict with prettier.
JavaScript
24
star
27

prettier-printer

Library for building and pretty printing text documents
JavaScript
23
star
28

prettier-linter-helpers

Helper functions for exposing prettier changes within linting tools
JavaScript
18
star
29

angular-estree-parser

A parser that converts Angular source code into an ESTree-compatible form
TypeScript
16
star
30

prettier-rpc

Single-file build of prettier with JSON-RPC communication
JavaScript
13
star
31

prettier-regression-testing

Automates the prettier/prettier regression checks with GitHub Actions.
TypeScript
12
star
32

parse-srcset

A spec-conformant JavaScript parser for the HTML5 srcset attribute
JavaScript
9
star
33

plugin-haml

Plugin for the HAML template language
JavaScript
5
star
34

pre-commit

Mirror of Prettier package for pre-commit.
JavaScript
5
star
35

core-test-fixtures

Test fixtures for Prettier core.
JavaScript
2
star
36

is-es5-identifier-name

Check if provided string is an `IdentifierName` as specified in ECMA262 edition 5.1 section 7.6.
JavaScript
2
star
37

html-ua-styles

User agent stylesheet defined in the WHATWG HTML specification.
JavaScript
1
star
38

eslint-plugin-prettier-internal-rules

Wrapper for Prettier internal rules
JavaScript
1
star