-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no-new-buffer
: Use suggestion for unknown arguments (#1037)
- Loading branch information
Showing
8 changed files
with
424 additions
and
116 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
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
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
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
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,17 @@ | ||
'use strict'; | ||
const isNewExpressionWithParentheses = require('./is-new-expression-with-parentheses'); | ||
|
||
function * switchNewExpressionToCallExpression(node, sourceCode, fixer) { | ||
const [start] = node.range; | ||
let end = start + 3; // `3` = length of `new` | ||
const textAfter = sourceCode.text.slice(end); | ||
const [leadingSpaces] = textAfter.match(/^\s*/); | ||
end += leadingSpaces.length; | ||
yield fixer.removeRange([start, end]); | ||
|
||
if (!isNewExpressionWithParentheses(node, sourceCode)) { | ||
yield fixer.insertTextAfter(node, '()'); | ||
} | ||
} | ||
|
||
module.exports = switchNewExpressionToCallExpression; |
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
Oops, something went wrong.