prettier-plugin-inline-blocks
v0.0.3
Published
A prettier plugin to format single-line block statements like objects
Readme
prettier-plugin-inline-blocks
A Prettier plugin to format blocks (e.g. function bodies, for/while/do loops, switch statements, etc.) like objects, allowing single line bodies when it's not preceded with a line break.
Installation
npm i -D prettier-plugin-inline-blocksUsage
Add the following to your prettier.config.js:
export default {
plugins: ['prettier-plugin-inline-blocks'],
};Example
With prettier-plugin-inline-blocks
After format, blocks not starting with line breaks are retained:
class A {
#name = '';
set name(value) { this.#name = value; }
get name() { return this.#name; }
}
function foo() { console.log('hello'); }
function bar() {
console.log('hello');
}Without prettier-plugin-inline-blocks
After format, all blocks are expanded with new lines:
class A {
#name = '';
set name(value) {
this.#name = value;
}
get name() {
return this.#name;
}
}
function foo() {
console.log('hello');
}
function bar() {
console.log('hello');
}Appendix
Attempts to solve https://github.com/prettier/prettier/issues/4549
License
MIT
