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) |
prettier/prettier#187 |
condA && condB ? 1 : 0 |
(condA && condB) ? 1 : 0 |
prettier/prettier#3805 |
Prerequisites: Prettier (^3).
Add plugin as develompment-only dependency:
npm install --save-dev @sosoba/prettier-plugin-expressions # or yarn, pnpm etc.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
}