Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
- Loading branch information
1 parent
f5496c7
commit c3c7ba3
Showing
5 changed files
with
678 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
rules/utils/should-add-parentheses-to-spread-element-argument.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const nodeTypesDoNotNeedParentheses = new Set([ | ||
'CallExpression', | ||
'Identifier', | ||
'Literal', | ||
'MemberExpression', | ||
'NewExpression', | ||
'TemplateLiteral', | ||
'ThisExpression' | ||
]); | ||
|
||
/** | ||
Check if parentheses should be added to a `node` when it's used as `argument` of `SpreadElement`. | ||
@param {Node} node - The AST node to check. | ||
@returns {boolean} | ||
*/ | ||
const shouldAddParenthesesToSpreadElementArgument = node => | ||
!nodeTypesDoNotNeedParentheses.has(node.type); | ||
|
||
module.exports = shouldAddParenthesesToSpreadElementArgument; |
Oops, something went wrong.