@Override public void leaveNode(AstNode astNode) { if (CheckUtils.isFunction(astNode)) { stack.pop(); } }
private static boolean containsImplicitReturnOfUndefined(FunctionTree tree) { BlockTree body = (BlockTree) tree.body(); FunctionReturns functionReturns = FunctionReturns.getFunctionReturns(body); return functionReturns.containsImplicitReturn() || functionReturns.containsReturnWithoutValue(); }
private static boolean hasWindowLikeName(ExpressionTree tree) { String str = CheckUtils.asString(tree); return str.contains("window") || str.contains("Window"); }
private static Optional<ClassTree> getEnclosingType(Tree tree) { final Tree classBoundary = CheckUtils.getFirstAncestor(tree, Kind.CLASS_DECLARATION, Kind.CLASS_EXPRESSION, Kind.OBJECT_LITERAL); if (classBoundary.is(Kind.OBJECT_LITERAL)) { return Optional.empty(); } else { return Optional.ofNullable((ClassTree) classBoundary); } }
private static boolean isTruthyLiteral(Tree tree, boolean isTruthy) { ExpressionTree conditionWithoutParentheses = CheckUtils.removeParenthesis((ExpressionTree) tree); return isTruthy && conditionWithoutParentheses.is( Kind.ARRAY_LITERAL, Kind.OBJECT_LITERAL, Kind.NEW_EXPRESSION, Kind.NUMERIC_LITERAL, Kind.STRING_LITERAL); }
@Override public void init() { subscribeTo(CheckUtils.iterationStatementsArray()); subscribeTo( EcmaScriptGrammar.ITERATION_STATEMENT, Kind.FUNCTION_EXPRESSION, Kind.FUNCTION_DECLARATION, Kind.GENERATOR_FUNCTION_EXPRESSION, Kind.GENERATOR_DECLARATION); }
@Override public void init() { subscribeTo(CheckUtils.functionNodesArray()); }
@Override public void leaveNode(AstNode astNode) { if (CheckUtils.isIterationStatement(astNode)) { stack.push(stack.pop() - 1); } else { stack.pop(); } }
public void addIssue(Tree tree, String message) { getContext().addIssue(this, tree, message); }
public static Tree parentIgnoreParentheses(Tree tree) { Tree parent = tree.parent(); if (parent.is(Kind.PARENTHESISED_EXPRESSION)) { return parentIgnoreParentheses(parent); } return parent; }
private static boolean hasWindowLikeName(ExpressionTree tree) { String str = CheckUtils.asString(tree); return str.contains("window") || str.contains("Window"); }
@CheckForNull private static MethodDeclarationTree getEnclosingConstructor(Tree tree) { FunctionTree function = (FunctionTree) CheckUtils.getFirstAncestor(tree, KindSet.FUNCTION_KINDS); if (function != null && isConstructor(function)) { return (MethodDeclarationTree) function; } return null; }
@Override public void leaveNode(AstNode astNode) { if (CheckUtils.isFunction(astNode)) { stack.pop(); } }
public static ExpressionTree removeParenthesis(ExpressionTree expressionTree) { if (expressionTree.is(Tree.Kind.PARENTHESISED_EXPRESSION)) { return removeParenthesis(((ParenthesisedExpressionTree) expressionTree).expression()); } return expressionTree; }
@Override public void init() { subscribeTo(CheckUtils.iterationStatementsArray()); subscribeTo( Kind.BREAK_STATEMENT, Kind.CONTINUE_STATEMENT, Kind.SWITCH_STATEMENT, Kind.LABELLED_STATEMENT); subscribeTo(FUNCTION_NODES); }
@Override public void init() { subscribeTo( Kind.VAR_DECLARATION, Kind.LET_DECLARATION, Kind.CONST_DECLARATION); subscribeTo(CheckUtils.functionNodesArray()); }
private static String getName(AccessorMethodDeclarationTree tree) { return CheckUtils.asString(tree.name()); } }
private static boolean insideCondition(SyntaxToken token) { Tree treeWithCondition = CheckUtils.getFirstAncestor(token, Kind.IF_STATEMENT, Kind.WHILE_STATEMENT, Kind.DO_WHILE_STATEMENT, Kind.FOR_STATEMENT, Kind.CONDITIONAL_EXPRESSION); if (treeWithCondition == null) { return false; } Tree condition = ((ConditionalTree) treeWithCondition).condition(); return condition != null && condition.isAncestorOf(token); } }
private void raiseIssue(ExpressionTree expression, int operandsNumber, ExpressionTree expressionResult) { String lastCase = CheckUtils.asString(expressionResult); String msg = String.format(MESSAGE, operandsNumber, lastCase); addIssue(expression, msg); }
private static boolean isCollectionWrite(Usage usage) { ExpressionStatementTree expressionStatement = (ExpressionStatementTree) CheckUtils.getFirstAncestor(usage.identifierTree(), Kind.EXPRESSION_STATEMENT); if (expressionStatement != null) { return isElementWrite(expressionStatement, usage) || isWritingMethodCall(expressionStatement, usage) || isVariableWrite(expressionStatement, usage); } return false; }