Disallow or enforce spaces inside of blocks after opening block and before closing block (block-spacing)

The --fix option on the command line can automatically fix some of the problems reported by this rule.

Rule Details

This rule enforces consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line.

Options

This rule has a string option:

always

Examples of incorrect code for this rule with the default "always" option:

/*eslint block-spacing: "error"*/

function foo() {return true;}
if (foo) { bar = 0;}
function baz() {let i = 0;
    return i;
}

Examples of correct code for this rule with the default "always" option:

/*eslint block-spacing: "error"*/

function foo() { return true; }
if (foo) { bar = 0; }

never

Examples of incorrect code for this rule with the "never" option:

/*eslint block-spacing: ["error", "never"]*/

function foo() { return true; }
if (foo) { bar = 0;}

Examples of correct code for this rule with the "never" option:

/*eslint block-spacing: ["error", "never"]*/

function foo() {return true;}
if (foo) {bar = 0;}

When Not To Use It

If you don't want to be notified about spacing style inside of blocks, you can safely disable this rule.

Version

This rule was introduced in ESLint 1.2.0.

Resources

Js中文网,专注分享前端最新技术、大厂面试题、聊点程序员轶事、职场感悟,做前端技术的传播者.

加入前端布道师交流群

扫描二维码回复 加群 学习,与大厂大佬讨论技术.

BAT面试题大全