0.6.0 • Published 2 months ago

prettier-plugin-brace-style v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

prettier-plugin-brace-style

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

A use case for this plugin.

Installation

For Prettier v2:

npm install -D prettier@^2 prettier-plugin-brace-style

For Prettier v3:^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',
};

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;
    }
DefaultCLI OverrideAPI Override
"1tbs"--brace-style <1tbs\|stroustrup\|allman>braceStyle: "<1tbs\|stroustrup\|allman>"

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"
}
0.6.0

2 months ago

0.5.0

4 months ago

0.4.1

4 months ago

0.4.0

4 months ago

0.3.2

7 months ago

0.3.0

7 months ago

0.3.1

7 months ago

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

9 months ago

0.1.1

10 months ago

0.1.0

11 months ago