prettier-plugin-brace-style

A Prettier plugin that can apply ESLint's brace-style rules.

MIT 26 个版本
安装
npm install prettier-plugin-brace-style
yarn add prettier-plugin-brace-style
pnpm add prettier-plugin-brace-style
bun add prettier-plugin-brace-style
README

prettier-plugin-brace-style

A Prettier plugin that can apply ESLint's brace-style rules.

A use case for this plugin.

Installation[^1]

npm install -D prettier prettier-plugin-brace-style

[^1]: If your version of prettier-plugin-brace-style is less than 0.5.0, you will also need to install @prettier/sync.

Configuration

JSON example:

{
  "plugins": ["prettier-plugin-brace-style"]
}

JS example (CommonJS module):

module.exports = {
  plugins: ['prettier-plugin-brace-style'],
  braceStyle: 'stroustrup',
};

JS example (ES module):

export default {
  plugins: ['prettier-plugin-brace-style'],
  braceStyle: 'allman',
};

Markdown/MDX Override

This plugin does not support Markdown and MDX, but if this plugin supports a language inside code blocks (e.g. Vue), unintended formatting may occur inside the code blocks.

To prevent unintended formatting, you can use configuration overrides for Markdown and MDX.

JSON example:

{
  "plugins": ["prettier-plugin-brace-style"],
  "braceStyle": "stroustrup",
  "overrides": [
    {
      "files": ["*.md", "*.mdx"],
      "options": {
        "plugins": []
      }
    }
  ]
}

Options

Brace Style

Enforces consistent brace style for blocks. Same as ESLint, you can select one of 1tbs (default), stroustrup, allman.

  • 1tbs example:

    if (condition) {
      statement1;
    } else {
      statement2;
    }
    
  • stroustrup example:

    if (condition) {
      statement1;
    }
    else {
      statement2;
    }
    
  • allman example:

    if (condition)
    {
      statement1;
    }
    else
    {
      statement2;
    }
    
Default CLI Override API Override
"1tbs" --brace-style <1tbs|stroustrup|allman> braceStyle: "<1tbs|stroustrup|allman>"

Version correlation with sibling plugins

Starting with 0.6.0, when there is a minor release on one side, I plan to reflect that change on the other side as well if possible.

Version correlation.

Compatibility with other Prettier plugins

If more than one Prettier plugin can handle the text you want to format, Prettier will only use the last of those plugins.

In this case, you can configure it as follows by adding prettier-plugin-merge to apply those plugins sequentially.

JSON example:

{
  "plugins": [
    "@trivago/prettier-plugin-sort-imports",
    "prettier-plugin-brace-style",
    "prettier-plugin-merge"
  ],
  "braceStyle": "stroustrup"
}

Stargazers over time

Stargazers over time

版本列表
0.10.3 2026-07-07
0.10.2 2026-06-24
0.10.1 2026-03-26
0.10.0 2026-02-24
0.9.0 2026-01-17
0.8.2 2025-12-06
0.8.1 2025-07-27
0.8.0 2025-06-27
0.7.3 2025-05-06
0.7.2 2025-01-09
0.7.1 2024-12-14
0.7.0 2024-08-16
0.6.2 2024-05-15
0.6.1 2024-05-11
0.6.0 2024-03-02
0.5.0 2024-01-17
0.4.1 2024-01-05
0.4.0 2023-12-30
0.3.2 2023-10-19
0.3.1 2023-09-27
0.3.0 2023-09-23
0.2.2 2023-09-09
0.2.1 2023-08-26
0.2.0 2023-08-13
0.1.1 2023-06-25
0.1.0 2023-06-19