How to use the tsutils.isMethodDeclaration function in tsutils

To help you get started, we’ve selected a few tsutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fossasia / susper.com / node_modules / tslint / lib / rules / preferConstRule.js View on Github external
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;
github nativescript-rtl / ui / node_modules / tslint / lib / rules / preferConstRule.js View on Github external
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;
github microsoft / tslint-microsoft-contrib / reactUnusedPropsAndStateRule.js View on Github external
function cb(node) {
        if (tsutils.isClassDeclaration(node)) {
            classDeclarations.push(node);
            return;
        }
        if (tsutils.isConstructorDeclaration(node)) {
            if (node.parameters.length > 0) {
                propsAlias = node.parameters[0].name.text;
            }
            ts.forEachChild(node, cb);
            propsAlias = undefined;
            return;
        }
        if (tsutils.isMethodDeclaration(node)) {
            var methodName = node.name.text;
            if (/componentWillReceiveProps|shouldComponentUpdate|componentWillUpdate|componentDidUpdate/.test(methodName) &&
                node.parameters.length > 0) {
                propsAlias = node.parameters[0].name.text;
            }
            if (/shouldComponentUpdate|componentWillUpdate|componentDidUpdate/.test(methodName) && node.parameters.length > 1) {
                stateAlias = node.parameters[1].name.text;
            }
            ts.forEachChild(node, cb);
            propsAlias = undefined;
            stateAlias = undefined;
            return;
        }
        if (tsutils.isInterfaceDeclaration(node)) {
            if (ctx.options.propsInterfaceRegex.test(node.name.text)) {
                propNodes = getTypeElementData(node);
github microsoft / tslint-microsoft-contrib / maxFuncBodyLengthRule.js View on Github external
function cb(node) {
        if (tsutils.isCallExpression(node)) {
            var functionName = AstUtils_1.AstUtils.getFunctionName(node);
            if (ignoreParametersToFunctionRegex && ignoreParametersToFunctionRegex.test(functionName)) {
                node.arguments.forEach(function (argument) {
                    ignoreNodes.push(argument);
                });
            }
        }
        if (tsutils.isArrowFunction(node) ||
            tsutils.isMethodDeclaration(node) ||
            tsutils.isFunctionDeclaration(node) ||
            tsutils.isFunctionExpression(node) ||
            tsutils.isConstructorDeclaration(node)) {
            validate(node);
        }
        if (tsutils.isClassDeclaration(node)) {
            currentClassName = (node.name && node.name.text) || 'default';
        }
        return ts.forEachChild(node, cb);
    }
    return ts.forEachChild(ctx.sourceFile, cb);
github microsoft / tslint-microsoft-contrib / functionNameRule.js View on Github external
function cb(node) {
        if (tsutils.isMethodDeclaration(node)) {
            var name_1 = node.name.getText();
            if (AstUtils_1.AstUtils.hasComputedName(node)) {
            }
            else if (AstUtils_1.AstUtils.isPrivate(node)) {
                if (!privateMethodRegex.test(name_1) && validateStatics === VALIDATE_PRIVATE_STATICS_AS_PRIVATE) {
                    ctx.addFailureAt(node.name.getStart(), node.name.getWidth(), "Private method name does not match " + privateMethodRegex + ": " + name_1);
                }
            }
            else if (AstUtils_1.AstUtils.isProtected(node)) {
                if (!protectedMethodRegex.test(name_1) && validateStatics === VALIDATE_PRIVATE_STATICS_AS_PRIVATE) {
                    ctx.addFailureAt(node.name.getStart(), node.name.getWidth(), "Protected method name does not match " + protectedMethodRegex + ": " + name_1);
                }
            }
            else if (AstUtils_1.AstUtils.isStatic(node)) {
                if (!staticMethodRegex.test(name_1)) {
                    ctx.addFailureAt(node.name.getStart(), node.name.getWidth(), "Static method name does not match " + staticMethodRegex + ": " + name_1);
github microsoft / tslint-microsoft-contrib / noMissingVisibilityModifiersRule.js View on Github external
function cb(node) {
        if (tsutils.isPropertyDeclaration(node)) {
            if (isMissingVisibilityModifier(node)) {
                var failureString = 'Field missing visibility modifier: ' + getFailureCodeSnippet(node);
                ctx.addFailureAt(node.getStart(), node.getWidth(), failureString);
            }
        }
        if (tsutils.isMethodDeclaration(node)) {
            if (isMissingVisibilityModifier(node)) {
                var failureString = 'Method missing visibility modifier: ' + getFailureCodeSnippet(node);
                ctx.addFailureAt(node.getStart(), node.getWidth(), failureString);
            }
        }
        return ts.forEachChild(node, cb);
    }
    return ts.forEachChild(ctx.sourceFile, cb);
github fossasia / susper.com / node_modules / tslint / lib / rules / objectLiteralShorthandRule.js View on Github external
return ts.forEachChild(ctx.sourceFile, function cb(node) {
        if (tsutils_1.isShorthandPropertyAssignment(node)) {
            ctx.addFailureAtNode(node.name, Rule.SHORTHAND_ASSIGNMENT, Lint.Replacement.appendText(node.getStart(ctx.sourceFile), node.name.text + ": "));
        }
        else if (tsutils_1.isMethodDeclaration(node) &&
            node.parent.kind === ts.SyntaxKind.ObjectLiteralExpression) {
            ctx.addFailureAtNode(node.name, Rule.SHORTHAND_ASSIGNMENT, fixShorthandMethodDeclaration(node, ctx.sourceFile));
        }
        return ts.forEachChild(node, cb);
    });
}
github microsoft / tslint-microsoft-contrib / missingOptionalAnnotationRule.js View on Github external
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);
github microsoft / tslint-microsoft-contrib / reactNoDangerousHtmlRule.js View on Github external
function cb(node) {
        if (tsutils.isMethodDeclaration(node)) {
            currentMethodName = node.name.getText();
            ts.forEachChild(node, cb);
            currentMethodName = '';
            return;
        }
        if (tsutils.isPropertyAssignment(node)) {
            var keyNode = node.name;
            if (keyNode.kind === ts.SyntaxKind.Identifier) {
                if (keyNode.text === 'dangerouslySetInnerHTML') {
                    addFailureIfNotSuppressed(node, keyNode);
                }
            }
        }
        else if (tsutils.isJsxElement(node)) {
            handleJsxOpeningElement(node.openingElement);
        }
github palantir / tslint / src / rules / objectLiteralShorthandRule.ts View on Github external
const [name, fix] = handleLonghandMethod(node.name, node.initializer, ctx.sourceFile);
            ctx.addFailure(
                node.getStart(ctx.sourceFile),
                getChildOfKind(node.initializer, ts.SyntaxKind.OpenParenToken, ctx.sourceFile)!.pos,
                Rule.getLonghandMethodErrorMessage(`{${name}() {...}}`),
                fix,
            );
        } else if (!enforceShorthandProperties && isShorthandPropertyAssignment(node)) {
            ctx.addFailureAtNode(
                node.name,
                Rule.getDisallowedShorthandErrorMessage(ctx.options),
                Lint.Replacement.appendText(node.getStart(ctx.sourceFile), `${node.name.text}: `),
            );
        } else if (
            !enforceShorthandMethods &&
            isMethodDeclaration(node) &&
            node.parent.kind === ts.SyntaxKind.ObjectLiteralExpression
        ) {
            ctx.addFailureAtNode(
                node.name,
                Rule.getDisallowedShorthandErrorMessage(ctx.options),
                fixShorthandMethodDeclaration(node, ctx.sourceFile),
            );
        }
        return ts.forEachChild(node, cb);
    });
}