Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: add "multiline" option to padding-line-between-statements (#9642) #9644

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/rules/padding-line-between-statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ You can supply any number of configurations. If an statement pair matches multip
- `"if"` is `if` statements.
- `"import"` is `import` declarations.
- `"let"` is `let` variable declarations.
- `"multiline"` is any multiline statement.
- `"multiline-block-like"` is block like statements. This is the same as `block-like` type, but only the block is multiline.
- `"return"` is `return` statements.
- `"switch"` is `switch` statements.
Expand Down
14 changes: 13 additions & 1 deletion lib/rules/padding-line-between-statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ function isBlockLikeStatement(sourceCode, node) {
);
}

/**
* Check whether the given node spans multiple lines or not.
* @param {ASTNode} node The node to check.
* @returns {boolean} `true` if the node is multiline.
*/
function isMultilineStatement(node) {
return node.loc.start.line !== node.loc.end.line;
}

/**
* Check whether the given node is a directive or not.
* @param {ASTNode} node The node to check.
Expand Down Expand Up @@ -353,9 +362,12 @@ const StatementTypes = {
node.type === "ExpressionStatement" &&
!isDirectivePrologue(node, sourceCode)
},
multiline: {
test: node => isMultilineStatement(node)
},
"multiline-block-like": {
test: (node, sourceCode) =>
node.loc.start.line !== node.loc.end.line &&
isMultilineStatement(node) &&
isBlockLikeStatement(sourceCode, node)
},

Expand Down