
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
prettier-plugin-block-padding
Advanced tools
A Prettier plugin that intelligently adds blank lines around code blocks for better visual grouping
Important Notice: This project is entirely generated by Cursor + Claude 4.5 Sonnet Thinking
A Prettier plugin that intelligently inserts blank lines between specific statements to enhance visual grouping of modules and semantic blocks, without altering Prettier's original style and line-breaking decisions. The plugin works on "statement sequences" based on Prettier 3's estree printer, supports all code blocks (including function bodies, if/for/while statement blocks), and does not rewrite formatting and indentation inside expressions.
namespace/module (TSModuleBlock), ensuring correct line breaks between braces and first/last lines.babel, babel-ts, and typescript parsers, only overriding the "statement concatenation" during the estree printing stage, leaving other formatting to Prettier.In "all code blocks (BlockStatement)", including file top-level (Program), function bodies, if/for/while statement blocks, and TypeScript namespace blocks (TSModuleBlock), the plugin adds an additional blank line between adjacent statements in the following cases:
interface, type, enum (including those wrapped with export)Multi-line Block Statements: When a statement's printed result is multi-line (e.g., if, for, while, do/while, try/catch/finally, switch, function, class, TSModuleDeclaration, etc.), an additional blank line is added between it and adjacent statements.
Multi-line Expression Blocks (New): When the following expressions span multiple lines, an additional blank line is added between them and adjacent statements:
`...`styled`...` () => {}function() {}class {}fn(...)new Class(...)<div>...</div><>...</>Summary: The plugin always ensures "at least one line break between adjacent statements", and when rules are matched, an additional line break is added to form a visual blank line.
Object/array literals, TS type declarations, and multi-line block statements trigger additional whitespace:
const a = 1
const b = {
name: "Tom",
age: 18,
}
if (a) {
const d = 1
}
interface User {
name: string
}
const c = [1, 2, 3]
The plugin also works inside function bodies, if/for/while, and all code blocks:
function foo() {
const a = 1
const b = {
name: "Tom",
age: 18,
}
if (a) {
const x = 1
const y = {
name: "Jerry",
age: 20,
}
}
const c = [1, 2, 3]
}
Template literals, function expressions, etc., spanning multiple lines also add blank lines:
const a = 1
const template = `
hello, world!
this is a multiline template
`
const fn = () => {
console.log("test")
}
const b = 2
const styled = css`
color: red;
font-size: 14px;
`
const c = 3
Single-line template literals, function expressions, etc., do not add blank lines:
const singleTemplate = `hello`
const singleFn = () => console.log("test")
const d = 4
Note: Single-line object/array literals still add blank lines (unconditional rule):
const a = 1
const singleObj = { a: 1 }
const b = 2
npm i -D prettier-plugin-block-padding
Add the plugin to your Prettier configuration (recommended to place at the end of the plugins array to ensure the custom estree printer takes effect):
{
"plugins": ["other-plugins", "prettier-plugin-block-padding"]
}
babel, babel-ts, typescriptThere are serious compatibility issues with the "@ianvs/prettier-plugin-sort-imports" plugin. Please do not use them together!
npx prettier --plugin prettier-plugin-block-padding --parser typescript --write "src/**/*.{ts,tsx,js,jsx}"
Or use the project script (if exists):
npm run test:quick
If you encounter blank line behavior inconsistent with expectations at boundary conditions or specific syntax, feel free to submit a minimal reproducible example for improvement.
FAQs
A Prettier plugin that intelligently adds blank lines around code blocks for better visual grouping
We found that prettier-plugin-block-padding demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.