How to use the tsutils.hasModifier 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 palantir / tslint / src / rules / memberOrderingRule.ts View on Github external
function getMemberKind(member: Member): MemberKind | undefined {
    const accessLevel = hasModifier(member.modifiers, ts.SyntaxKind.PrivateKeyword)
        ? "private"
        : hasModifier(member.modifiers, ts.SyntaxKind.ProtectedKeyword)
        ? "protected"
        : "public";
    const membership = hasModifier(member.modifiers, ts.SyntaxKind.StaticKeyword)
        ? "Static"
        : "Instance";

    switch (member.kind) {
        case ts.SyntaxKind.Constructor:
        case ts.SyntaxKind.ConstructSignature:
            // tslint:disable-next-line:prefer-template
            return (MemberKind as any)[accessLevel + "Constructor"] as MemberKind;

        case ts.SyntaxKind.GetAccessor:
        case ts.SyntaxKind.SetAccessor:
            // tslint:disable-next-line:prefer-template
            return (MemberKind as any)[accessLevel + membership + "Accessor"] as MemberKind;

        case ts.SyntaxKind.PropertyDeclaration:
        case ts.SyntaxKind.PropertySignature:
github fossasia / susper.com / node_modules / tslint / lib / rules / noShadowedVariableRule.js View on Github external
break;
                case ts.SyntaxKind.Parameter:
                    if (node.parent.kind !== ts.SyntaxKind.IndexSignature &&
                        !tsutils_1.isThisParameter(node) &&
                        tsutils_1.isFunctionWithBody(node.parent)) {
                        _this.handleBindingName(node.name, false, true);
                    }
                    break;
                case ts.SyntaxKind.ModuleDeclaration:
                    if (_this.options.namespace &&
                        node.parent.kind !== ts.SyntaxKind.ModuleDeclaration &&
                        node.name.kind === ts.SyntaxKind.Identifier &&
                        !tsutils_1.isNodeFlagSet(node, ts.NodeFlags.GlobalAugmentation)) {
                        parentScope.addVariable(node.name, false);
                    }
                    if (tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword)) {
                        _this.onScopeEnd(parentScope);
                        _this.scope = parentScope;
                        return; // don't check any ambient declaration blocks
                    }
                    break;
                case ts.SyntaxKind.ImportClause:
                    if (_this.options.import && node.name !== undefined) {
                        _this.scope.addVariable(node.name, false);
                    }
                    break;
                case ts.SyntaxKind.NamespaceImport:
                case ts.SyntaxKind.ImportSpecifier:
                case ts.SyntaxKind.ImportEqualsDeclaration:
                    if (_this.options.import) {
                        _this.scope.addVariable(node.name, false);
                    }
github fossasia / susper.com / node_modules / tslint / lib / rules / spaceBeforeFunctionParenRule.js View on Github external
function getOption(node, options) {
    switch (node.kind) {
        case ts.SyntaxKind.ArrowFunction:
            return !hasTypeParameters(node) &&
                tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword)
                ? options.asyncArrow
                : undefined;
        case ts.SyntaxKind.Constructor:
            return options.constructor;
        case ts.SyntaxKind.FunctionDeclaration:
        // name is optional for function declaration which is default export (TS will emit error in other cases).
        // Can be handled in the same way as function expression.
        case ts.SyntaxKind.FunctionExpression: {
            var functionName = node.name;
            var hasName = functionName !== undefined && functionName.text !== "";
            return hasName
                ? options.named
                : !hasTypeParameters(node)
                    ? options.anonymous
                    : undefined;
        }
github palantir / tslint / src / rules / completed-docs / classExclusion.ts View on Github external
private shouldLocationBeDocumented(node: ts.Node) {
        if (this.locations.has(ALL)) {
            return true;
        }

        if (hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword)) {
            return this.locations.has(LOCATION_STATIC);
        }

        return this.locations.has(LOCATION_INSTANCE);
    }
github cartant / tslint-etc / source / rules / noUnusedDeclarationRule.ts View on Github external
protected visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void {
    if (this._validate.declarations) {
      const { name } = node;
      if (!tsutils.hasModifier(node.modifiers, ts.SyntaxKind.ExportKeyword)) {
        this.declared(node, name);
        this.setScopedIdentifier(name);
      }
    }
    super.visitInterfaceDeclaration(node);
  }
github fossasia / susper.com / node_modules / tslint / lib / rules / memberOrderingRule.js View on Github external
function getMemberKind(member) {
    var accessLevel = tsutils_1.hasModifier(member.modifiers, ts.SyntaxKind.PrivateKeyword)
        ? "private"
        : tsutils_1.hasModifier(member.modifiers, ts.SyntaxKind.ProtectedKeyword)
            ? "protected"
            : "public";
    switch (member.kind) {
        case ts.SyntaxKind.Constructor:
        case ts.SyntaxKind.ConstructSignature:
            return memberKindForConstructor(accessLevel);
        case ts.SyntaxKind.PropertyDeclaration:
        case ts.SyntaxKind.PropertySignature:
            return methodOrField(isFunctionLiteral(member.initializer));
        case ts.SyntaxKind.MethodDeclaration:
        case ts.SyntaxKind.MethodSignature:
            return methodOrField(true);
        default:
            return undefined;
github cartant / tslint-etc / source / rules / noUnusedDeclarationRule.ts View on Github external
protected visitTypeAliasDeclaration(node: ts.TypeAliasDeclaration): void {
    if (this._validate.declarations) {
      const { name } = node;
      if (!tsutils.hasModifier(node.modifiers, ts.SyntaxKind.ExportKeyword)) {
        this.declared(node, name);
        this.setScopedIdentifier(name);
      }
    }
    super.visitTypeAliasDeclaration(node);
  }
github fossasia / susper.com / node_modules / tslint / lib / rules / objectLiteralShorthandRule.js View on Github external
function handleLonghandMethod(name, initializer, sourceFile) {
    var nameStart = name.getStart(sourceFile);
    var fix = Lint.Replacement.deleteFromTo(name.end, tsutils_1.getChildOfKind(initializer, ts.SyntaxKind.OpenParenToken).pos);
    var prefix = "";
    if (initializer.asteriskToken !== undefined) {
        prefix = "*";
    }
    if (tsutils_1.hasModifier(initializer.modifiers, ts.SyntaxKind.AsyncKeyword)) {
        prefix = "async " + prefix;
    }
    if (prefix !== "") {
        fix = [fix, Lint.Replacement.appendText(nameStart, prefix)];
    }
    return [prefix + sourceFile.text.substring(nameStart, name.end), fix];
}
var templateObject_1;
github JoshuaKGoldberg / TypeStat / src / mutators / builtIn / fixIncompleteTypes / fixIncompleteReactTypes / fixReactPropsFromPropTypes / propTypes / getPropTypesValue.ts View on Github external
const getStaticPropTypes = (node: ts.ClassElement): node is PropTypesMember =>
    ts.isPropertyDeclaration(node) &&
    tsutils.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword) &&
    ts.isIdentifier(node.name) &&
    node.name.text === "propTypes" &&
    node.initializer !== undefined &&
    ts.isObjectLiteralExpression(node.initializer);
github palantir / tslint / src / rules / noUnboundMethodRule.ts View on Github external
function isMethod(node: ts.Node, ignoreStatic: boolean): boolean {
    switch (node.kind) {
        case ts.SyntaxKind.MethodDeclaration:
        case ts.SyntaxKind.MethodSignature:
            return !(ignoreStatic && hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword));
        default:
            return false;
    }
}