Skip to content

About

prettier plugin to format blocks like objects, allowing single line bodies when it's not preceded with a line break.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

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-blocks

Usage

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 prettier/prettier#4549

License

MIT

About

prettier plugin to format blocks like objects, allowing single line bodies when it's not preceded with a line break.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages