Skip to content

Latest commit

 

History

History
131 lines (78 loc) · 2.57 KB

no-multiple-empty-lines.md

File metadata and controls

131 lines (78 loc) · 2.57 KB
规则名 规则类型
no-multiple-empty-lines
layout

Some developers prefer to have multiple blank lines removed, while others feel that it helps improve readability. Whitespace is useful for separating logical sections of code, but excess whitespace takes up more of the screen.

规则详解

This rule aims to reduce the scrolling required when reading through your code. It will warn when the maximum amount of empty lines has been exceeded.

配置项

This rule has an object option:

  • "max" (default: 2) enforces a maximum number of consecutive empty lines.
  • "maxEOF" enforces a maximum number of consecutive empty lines at the end of files.
  • "maxBOF" enforces a maximum number of consecutive empty lines at the beginning of files.

max

选项 { "max": 2 } 默认值的 错误 代码示例:

/*eslint no-multiple-empty-lines: "error"*/

var foo = 5;


var bar = 3;

选项 { "max": 2 } 默认值的 正确 代码示例:

::: correct

/*eslint no-multiple-empty-lines: "error"*/

var foo = 5;

var bar = 3;

maxEOF

选项 { max: 2, maxEOF: 0 }错误 代码示例:

/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/

var foo = 5;

var bar = 3;

选项 { max: 2, maxEOF: 0 }正确 代码示例:

::: correct

/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/

var foo = 5;

var bar = 3;

Note: Although this ensures zero empty lines at the EOF, most editors will still show one empty line at the end if the file ends with a line break, as illustrated below. There is no empty line at the end of a file after the last \n, although editors may show an additional line. A true additional line would be represented by \n\n.

Incorrect:

1    /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/
2    
3    var foo = 5;
4    
5    
6    var bar = 3;
7    
8

Correct:

1    /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/
2    
3    var foo = 5;
4    
5    
6    var bar = 3;
7

maxBOF

选项 { max: 2, maxBOF: 1 }错误 代码示例:

/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1 }]*/

var foo = 5;

var bar = 3;

选项 { max: 2, maxBOF: 1 }正确 代码示例:

::: correct

/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1}]*/

var foo = 5;

var bar = 3;

禁用建议

If you do not care about extra blank lines, turn this off.