Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var cb = function (node) {
var savedScope = _this.scope;
var boundary = utils.isScopeBoundary(node);
if (boundary !== 0 /* None */) {
if (boundary === 1 /* Function */) {
if (node.kind === ts.SyntaxKind.ModuleDeclaration &&
utils.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword)) {
// don't check ambient namespaces
return;
}
_this.scope = new Scope();
if (utils.isFunctionDeclaration(node) ||
utils.isMethodDeclaration(node) ||
utils.isFunctionExpression(node) ||
utils.isArrowFunction(node) ||
utils.isConstructorDeclaration(node)) {
// special handling for function parameters
// each parameter initializer can only reassign preceding parameters of variables of the containing scope
if (node.body !== undefined) {
for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
var param = _a[_i];
cb(param);
_this.settle(savedScope);
}
cb(node.body);
_this.onScopeEnd(savedScope);
}
_this.scope = savedScope;
return;
}
}
else {
var cb = function (node) {
var savedScope = _this.scope;
var boundary = utils.isScopeBoundary(node);
if (boundary !== 0 /* None */) {
if (boundary === 1 /* Function */) {
if (node.kind === ts.SyntaxKind.ModuleDeclaration && utils.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword)) {
// don't check ambient namespaces
return;
}
_this.scope = new Scope();
if (utils.isFunctionDeclaration(node) ||
utils.isMethodDeclaration(node) ||
utils.isFunctionExpression(node) ||
utils.isArrowFunction(node) ||
utils.isConstructorDeclaration(node)) {
// special handling for function parameters
// each parameter initializer can only reassign preceding parameters of variables of the containing scope
if (node.body !== undefined) {
for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) {
var param = _a[_i];
cb(param);
_this.settle(savedScope);
}
cb(node.body);
_this.onScopeEnd(savedScope);
}
_this.scope = savedScope;
return;
}
}
else {
if (options.allowEmptyCatch && node.kind === ts.SyntaxKind.CatchClause) {
return true;
}
if (
options.allowEmptyFunctions &&
(node.kind === ts.SyntaxKind.MethodDeclaration ||
node.kind === ts.SyntaxKind.FunctionDeclaration ||
node.kind === ts.SyntaxKind.FunctionExpression ||
node.kind === ts.SyntaxKind.ArrowFunction)
) {
return true;
}
return (
isConstructorDeclaration(node) &&
/* If constructor is private or protected, the block is allowed to be empty.
The constructor is there on purpose to disallow instantiation from outside the class */
/* The public modifier does not serve a purpose here. It can only be used to allow instantiation of a base class where
the super constructor is protected. But then the block would not be empty, because of the call to super() */
(hasModifier(
node.modifiers,
ts.SyntaxKind.PrivateKeyword,
ts.SyntaxKind.ProtectedKeyword,
) ||
node.parameters.some(isParameterProperty))
);
}
if (exclusions === undefined || exclusions.overloadsSeparateDocs) {
return [node];
}
if (tsutils.isFunctionDeclaration(node) && node.name !== undefined) {
const functionName = node.name.text;
return getSiblings(node).filter(
child =>
tsutils.isFunctionDeclaration(child) &&
child.name !== undefined &&
child.name.text === functionName,
);
}
if (tsutils.isConstructorDeclaration(node)) {
const {
parent: { members },
} = node;
return members.filter(child => tsutils.isConstructorDeclaration(child));
}
if (
tsutils.isMethodDeclaration(node) &&
tsutils.isIdentifier(node.name) &&
tsutils.isClassDeclaration(node.parent)
) {
const methodName = node.name.text;
return node.parent.members.filter(
member =>
function isNonStaticMember(member) {
return (isConstructorWithShorthandProps(member) ||
(!tsutils_1.isConstructorDeclaration(member) &&
!tsutils_1.hasModifier(member.modifiers, ts.SyntaxKind.StaticKeyword)));
}
function hasExtendsClause(declaration) {
function cb(node) {
if (tsutils.isMethodDeclaration(node) ||
tsutils.isConstructorDeclaration(node) ||
tsutils.isArrowFunction(node) ||
tsutils.isFunctionDeclaration(node) ||
tsutils.isFunctionExpression(node)) {
validateParameters(node);
}
return ts.forEachChild(node, cb);
}
return ts.forEachChild(ctx.sourceFile, cb);
function cb(node) {
if (tsutils.isMethodDeclaration(node) ||
tsutils.isConstructorDeclaration(node) ||
tsutils.isArrowFunction(node) ||
tsutils.isFunctionDeclaration(node) ||
tsutils.isFunctionExpression(node)) {
var seenNames_1 = {};
node.parameters.forEach(function (parameter) {
var parameterName = parameter.name.getText();
if (parameterName !== undefined) {
if (seenNames_1[parameterName]) {
ctx.addFailureAt(parameter.name.getStart(), parameterName.length, Rule.FAILURE_STRING + "'" + parameterName + "'");
}
else {
seenNames_1[parameterName] = true;
}
}
});
}
protected visitNode(node: ts.Node): void {
const isScopeBoundary =
tsutils.isBlock(node) ||
tsutils.isArrowFunction(node) ||
tsutils.isConstructorDeclaration(node) ||
tsutils.isFunctionDeclaration(node) ||
tsutils.isGetAccessorDeclaration(node) ||
tsutils.isMethodDeclaration(node) ||
tsutils.isSetAccessorDeclaration(node);
const { _scopes } = this;
if (isScopeBoundary) {
_scopes.push(new Map());
}
super.visitNode(node);
if (isScopeBoundary) {
_scopes.pop();
}
if (tsutils.isSourceFile(node)) {
this.onSourceFileEnd();