@sosoba/prettier-plugin-expressions
v1.0.0
Published
Prettier plugin which which improves the readability of expressions by surrounding them with brackets
Maintainers
Readme
@sosoba/prettier-plugin-expressions
This is a prettier plugin which improves the readability of expressions by surrounding them with bracket even if they are not necessary for calculating machines.
| 🆘 raw Prettier style | ✅ with this plugin | Discusion |
| ------------------------ | -------------------------- | ------------------------------------------------ |
| 1 + 2 * 3 + 4 / 2 | 1 + (2 * 3) + (4 / 2) | https://github.com/prettier/prettier/issues/187 |
| condA && condB ? 1 : 0 | (condA && condB) ? 1 : 0 | https://github.com/prettier/prettier/issues/3805 |
Installation
Prerequisites: Prettier (^3).
Add plugin as develompment-only dependency:
npm install --save-dev @sosoba/prettier-plugin-expressions # or yarn, pnpm etc.Configuration
Add plugin in a manner appropriate to the configuration method chosen in the project and enable desired options. Ex.:
.prettierrc.yaml:
plugins:
- '@sosoba/prettier-plugin-expressions'
parenthesesInExpressionsWithMixedOperators: true
parenthesesAroundConditionalInTernaryExpression: true.prettierrc.json:
{
"plugins": ["@sosoba/prettier-plugin-expressions"],
"parenthesesInExpressionsWithMixedOperators": true,
"parenthesesAroundConditionalInTernaryExpression": true
}