Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
NewExpression(node) {
// Only indent the arguments if the NewExpression has parens (e.g. `new Foo(bar)` or `new Foo()`, but not `new Foo`
if (node.arguments.length > 0 ||
(eslint_utils_1.isClosingParenToken(sourceCode.getLastToken(node)) &&
eslint_utils_1.isOpeningParenToken(sourceCode.getLastToken(node, 1)))) {
addFunctionCallIndent(node);
}
},
'ObjectExpression, ObjectPattern'(node) {
tokens.forEach(nextToken => {
// Accumulate a list of parenthesis pairs
if (isOpeningParenToken(nextToken)) {
parenStack.push(nextToken);
} else if (isClosingParenToken(nextToken)) {
parenPairs.unshift({ left: parenStack.pop()!, right: nextToken });
}
});
NewExpression(node) {
// Only indent the arguments if the NewExpression has parens (e.g. `new Foo(bar)` or `new Foo()`, but not `new Foo`
if (
node.arguments.length > 0 ||
(isClosingParenToken(sourceCode.getLastToken(node)!) &&
isOpeningParenToken(sourceCode.getLastToken(node, 1)!))
) {
addFunctionCallIndent(node);
}
},
tokens.forEach(nextToken => {
// Accumulate a list of parenthesis pairs
if (eslint_utils_1.isOpeningParenToken(nextToken)) {
parenStack.push(nextToken);
}
else if (eslint_utils_1.isClosingParenToken(nextToken)) {
parenPairs.unshift({ left: parenStack.pop(), right: nextToken });
}
});
parenPairs.forEach(pair => {
function addBlocklessNodeIndent(node) {
if (node.type !== 'BlockStatement') {
const lastParentToken = sourceCode.getTokenBefore(node, eslint_utils_1.isNotOpeningParenToken);
let firstBodyToken = sourceCode.getFirstToken(node);
let lastBodyToken = sourceCode.getLastToken(node);
while (eslint_utils_1.isOpeningParenToken(sourceCode.getTokenBefore(firstBodyToken)) &&
eslint_utils_1.isClosingParenToken(sourceCode.getTokenAfter(lastBodyToken))) {
firstBodyToken = sourceCode.getTokenBefore(firstBodyToken);
lastBodyToken = sourceCode.getTokenAfter(lastBodyToken);
}
offsets.setDesiredOffsets([firstBodyToken.range[0], lastBodyToken.range[1]], lastParentToken, 1);
/*
* For blockless nodes with semicolon-first style, don't indent the semicolon.
* e.g.
* if (foo) bar()
* ; [1, 2, 3].map(foo)
*/
const lastToken = sourceCode.getLastToken(node);
if (lastToken &&
node.type !== 'EmptyStatement' &&
eslint_utils_1.isSemicolonToken(lastToken)) {
offsets.setDesiredOffset(lastToken, lastParentToken, 0);
}
function addBlocklessNodeIndent(node: TSESTree.Node): void {
if (node.type !== AST_NODE_TYPES.BlockStatement) {
const lastParentToken = sourceCode.getTokenBefore(
node,
isNotOpeningParenToken,
)!;
let firstBodyToken = sourceCode.getFirstToken(node)!;
let lastBodyToken = sourceCode.getLastToken(node)!;
while (
isOpeningParenToken(sourceCode.getTokenBefore(firstBodyToken)!) &&
isClosingParenToken(sourceCode.getTokenAfter(lastBodyToken)!)
) {
firstBodyToken = sourceCode.getTokenBefore(firstBodyToken)!;
lastBodyToken = sourceCode.getTokenAfter(lastBodyToken)!;
}
offsets.setDesiredOffsets(
[firstBodyToken.range[0], lastBodyToken.range[1]],
lastParentToken,
1,
);
/*
* For blockless nodes with semicolon-first style, don't indent the semicolon.
* e.g.
* if (foo) bar()
* ; [1, 2, 3].map(foo)