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.
npm i -D prettier-plugin-inline-blocksAdd the following to your prettier.config.js:
export default {
plugins: ['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');
}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');
}Attempts to solve prettier/prettier#4549
MIT