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) {
function getFirstToken(element) {
let token = sourceCode.getTokenBefore(element);
while (eslint_utils_1.isOpeningParenToken(token) && token !== startToken) {
token = sourceCode.getTokenBefore(token);
}
return sourceCode.getTokenAfter(token);
}
// Run through all the tokens in the list, and offset them by one indent level (mainly for comments, other things will end up overridden)
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);
}
},
function getConfigForFunction(
node:
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression,
): FuncOption {
if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) {
// Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar
if (
node.async &&
isOpeningParenToken(sourceCode.getFirstToken(node, { skip: 1 })!)
) {
return overrideConfig.asyncArrow ?? baseConfig;
}
} else if (isNamedFunction(node)) {
return overrideConfig.named ?? baseConfig;
// `generator-star-spacing` should warn anonymous generators. E.g. `function* () {}`
} else if (!node.generator) {
return overrideConfig.anonymous ?? baseConfig;
}
return 'ignore';
}
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 });
}
});
function getFirstToken(element: TSESTree.Node): TSESTree.Token {
let token = sourceCode.getTokenBefore(element)!;
while (isOpeningParenToken(token) && token !== startToken) {
token = sourceCode.getTokenBefore(token)!;
}
return sourceCode.getTokenAfter(token)!;
}
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()
ArrowFunctionExpression(node) {
const firstToken = sourceCode.getFirstToken(node)!;
if (isOpeningParenToken(firstToken)) {
const openingParen = firstToken;
const closingParen = sourceCode.getTokenBefore(
node.body,
isClosingParenToken,
)!;
parameterParens.add(openingParen);
parameterParens.add(closingParen);
addElementListIndent(
node.params,
openingParen,
closingParen,
options.FunctionExpression.parameters!,
);
}
addBlocklessNodeIndent(node.body);
ArrowFunctionExpression(node) {
const firstToken = sourceCode.getFirstToken(node);
if (eslint_utils_1.isOpeningParenToken(firstToken)) {
const openingParen = firstToken;
const closingParen = sourceCode.getTokenBefore(node.body, eslint_utils_1.isClosingParenToken);
parameterParens.add(openingParen);
parameterParens.add(closingParen);
addElementListIndent(node.params, openingParen, closingParen, options.FunctionExpression.parameters);
}
addBlocklessNodeIndent(node.body);
},
AssignmentExpression(node) {