Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prettier/plugin-pug

Package Overview
Dependencies
Maintainers
11
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prettier/plugin-pug

Prettier Pug Plugin

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
increased by21.21%
Maintainers
11
Weekly downloads
 
Created
Source

   Prettier      Pug  

Prettier Pug plugin

license: MIT NPM package downloads code style: Prettier Build Status

Please note that the plugin ecosystem in Prettier is still beta, which may make @prettier/plugin-pug not ready for production use yet.


Plugin for Prettier to format pug code

You can disable code formatting for a particular code block by adding <!-- prettier-ignore --> before ```pug.

Pug code with custom formatting:

<!-- prettier-ignore -->
```pug
div.text( color =   "primary",  disabled  ="true"  )
```

Prettified code:

```pug
.text(color="primary", disabled)
```

Getting started

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

cd /path/to/project

## initialise an npm project if you haven’t done it yet
npm init
## or
yarn init

## add Prettier and its Pug plugin to project’s dev dependencies
npm install --dev prettier @prettier/plugin-pug
## or
yarn add --dev prettier @prettier/plugin-pug

Usage

## format all pug files in your project
./node_modules/.bin/prettier --write "**/*.pug"
## or
yarn prettier --write "**/*.pug"

Prettier Options

  • printWidth
    Currently not very accurate, but works
  • singleQuote
    If you want to configure different quotes for pug than for js code, you can use prettier's override.
    {
      "singleQuote": true,
      "overrides": [
        {
          "files": "*.pug",
          "options": {
            "parser": "pug",
            "singleQuote": true
          }
        }
      ]
    }
    
  • tabWidth
    Use spaces for indentation
  • useTabs
    Use tab for indentation Overrides tabWidth

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 of this plugin in VSCode extension seems to be blocked by prettier/prettier-vscode#395. Feel free to help!

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

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 yarn install.
  • Execute yarn lint to make sure that the code passes formatting and linting.
  • Execute yarn test to make sure that TypeScript successfully compiles into JavaScript and 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 repos to the prettier orga.

Keywords

FAQs

Package last updated on 21 Aug 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc