How to use the tslint.isNodeFlagSet function in tslint

To help you get started, we’ve selected a few tslint 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 jonaskello / tslint-immutable / src / noLetRule.ts View on Github external
function checkDeclarationList(
  declarationList: ts.VariableDeclarationList,
  ctx: Lint.WalkContext
): CheckNodeResult {
  if (Lint.isNodeFlagSet(declarationList, ts.NodeFlags.Let)) {
    // It is a let declaration, now check each variable that is declared
    const invalidVariableDeclarationNodes = [];
    // If the declaration list contains multiple variables, eg. let x = 0, y = 1, mutableZ = 3; then
    // we should only provide one fix for the list even if two variables are invalid.
    // NOTE: When we have a mix of allowed and disallowed variables in the same DeclarationList
    // there is no sure way to know if we should do a fix or not, eg. if ignore-prefix=mutable
    // and the list is "let x, mutableZ", then "x" is invalid but "mutableZ" is valid, should we change
    // "let" to "const" or not? For now we change to const if at least one variable is invalid.
    let addFix = true;
    for (const variableDeclarationNode of declarationList.declarations) {
      if (
        !Ignore.shouldIgnore(
          variableDeclarationNode,
          ctx.options,
          ctx.sourceFile
        )
github microsoft / dtslint / bin / rules / noVarRule.js View on Github external
switch (node.kind) {
            case ts.SyntaxKind.VariableStatement:
                if (!Lint.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword)
                    && !Lint.isBlockScopedVariable(node)
                    && !(node.parent.kind === ts.SyntaxKind.ModuleBlock && isDeclareGlobal(node.parent.parent))
                    && !(node.parent === sourceFile && !ts.isExternalModule(sourceFile) && sourceFile.isDeclarationFile)) {
                    ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
                }
                break;
            case ts.SyntaxKind.ForStatement:
            case ts.SyntaxKind.ForInStatement:
            case ts.SyntaxKind.ForOfStatement: {
                const { initializer } = node;
                if (initializer && initializer.kind === ts.SyntaxKind.VariableDeclarationList &&
                    // tslint:disable-next-line no-bitwise
                    !Lint.isNodeFlagSet(initializer, ts.NodeFlags.Let | ts.NodeFlags.Const)) {
                    ctx.addFailureAtNode(initializer, Rule.FAILURE_STRING);
                }
                break;
            }
        }
        ts.forEachChild(node, cb);
    });
}
github microsoft / dtslint / src / rules / noVarRule.ts View on Github external
if (!Lint.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword)
						&& !Lint.isBlockScopedVariable(node as ts.VariableStatement)
						// Global 'var' declaration OK.
						&& !(node.parent!.kind === ts.SyntaxKind.ModuleBlock && isDeclareGlobal(node.parent!.parent!))
						&& !(node.parent === sourceFile && !ts.isExternalModule(sourceFile) && sourceFile.isDeclarationFile)) {
					ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
				}
				break;

			case ts.SyntaxKind.ForStatement:
			case ts.SyntaxKind.ForInStatement:
			case ts.SyntaxKind.ForOfStatement: {
				const { initializer } = node as ts.ForStatement | ts.ForInStatement | ts.ForOfStatement;
				if (initializer && initializer.kind === ts.SyntaxKind.VariableDeclarationList &&
						// tslint:disable-next-line no-bitwise
						!Lint.isNodeFlagSet(initializer, ts.NodeFlags.Let | ts.NodeFlags.Const)) {
					ctx.addFailureAtNode(initializer, Rule.FAILURE_STRING);
				}
				break;
			}
		}

		ts.forEachChild(node, cb);
	});
}
github jonaskello / tslint-immutable / rules / noLetRule.js View on Github external
NoLetKeywordWalker.prototype.handleInitializerNode = function (node) {
        if (node && node.kind === ts.SyntaxKind.VariableDeclarationList &&
            (Lint.isNodeFlagSet(node, ts.NodeFlags.Let))) {
            this.addFailure(this.createFailure(node.getStart(), "let".length, Rule.FAILURE_STRING));
        }
    };
    return NoLetKeywordWalker;
github jonaskello / tslint-immutable / src / noLetRule.ts View on Github external
function checkForStatements(
  node: ts.Node,
  ctx: Lint.WalkContext
): CheckNodeResult {
  if (
    (utils.isForStatement(node) ||
      utils.isForInStatement(node) ||
      utils.isForOfStatement(node)) &&
    node.initializer &&
    utils.isVariableDeclarationList(node.initializer) &&
    Lint.isNodeFlagSet(node.initializer, ts.NodeFlags.Let)
  ) {
    return checkDeclarationList(node.initializer, ctx);
  }
  return { invalidNodes: [] };
}
github jonaskello / tslint-immutable / rules / noLetRule.js View on Github external
NoLetKeywordWalker.prototype.visitVariableStatement = function (node) {
        if (Lint.isNodeFlagSet(node.declarationList, ts.NodeFlags.Let)) {
            this.addFailure(this.createFailure(node.getStart(), "let".length, Rule.FAILURE_STRING));
        }
        _super.prototype.visitVariableStatement.call(this, node);
    };
    NoLetKeywordWalker.prototype.visitForStatement = function (node) {