Skip to main content

space-before-blocks

<admonition title="Deprecated" type="warning"> Formatting rules now live in <a href="https://eslint.style">eslint-stylistic</a>. <a href="https://eslint.style/rules/ts/space-before-blocks">@stylistic/ts/space-before-blocks</a> is the replacement for this rule. <br /> See <a href="/blog/deprecating-formatting-rules">Deprecating Formatting Rules</a> for more information. </admonition>

Enforce consistent spacing before blocks.

🔧

Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.

This rule extends the base eslint/space-before-blocks rule. It adds support for interfaces and enums.

enum Breakpoint{
Large,
Medium,
}

interface State{
currentBreakpoint: Breakpoint;
}
Open in Playground

How to Use

.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"space-before-blocks": "off",
"@typescript-eslint/space-before-blocks": "error"
}
};

Try this rule in the playground ↗

Options

See eslint/space-before-blocks options.

In case a more specific options object is passed these blocks will follow classes configuration option.

Resources

Taken with ❤️ from ESLint core.