Search in sources :

Example 1 with AssignmentLike

use of org.sonar.uast.helpers.AssignmentLike in project sonar-go by SonarSource.

the class WrongAssignmentOperatorCheck method visitNode.

@Override
public void visitNode(UastNode node) {
    AssignmentLike assignmentLike = AssignmentLike.from(node);
    if (assignmentLike == null) {
        return;
    }
    if (assignmentLike.isMultiple()) {
        List<AssignmentLike> couples = assignmentLike.assignmentsTuples();
        if (couples.size() != 1) {
            // not relevant for multiple assignment form
            return;
        }
        assignmentLike = couples.get(0);
    }
    UastNode.Token variableLastToken = assignmentLike.target().lastToken();
    UastNode operator = assignmentLike.operator();
    UastNode expression = assignmentLike.value();
    UastNode.Token expressionFirstToken = expression.firstToken();
    if (noSpacingBetween(operator.lastToken(), expressionFirstToken) && spacingBetween(variableLastToken, operator.firstToken()) && expression.is(UastNode.Kind.UNARY_MINUS, UastNode.Kind.UNARY_PLUS, UastNode.Kind.LOGICAL_COMPLEMENT)) {
        String msg;
        if (expression.is(UastNode.Kind.LOGICAL_COMPLEMENT)) {
            msg = "Add a space between \"=\" and \"!\" to avoid confusion.";
        } else {
            msg = String.format("Was \"%s=\" meant instead?", expressionFirstToken.value);
        }
        reportIssue(assignmentLike.node(), msg);
    }
}
Also used : AssignmentLike(org.sonar.uast.helpers.AssignmentLike) UastNode(org.sonar.uast.UastNode)

Example 2 with AssignmentLike

use of org.sonar.uast.helpers.AssignmentLike in project sonar-go by SonarSource.

the class NoHardcodedCredentialsCheck method visitNode.

@Override
public void visitNode(UastNode node) {
    AssignmentLike assignment = AssignmentLike.from(node);
    if (assignment != null) {
        LiteralLike assignmentValue = LiteralLike.from(assignment.value());
        if (assignmentValue != null && !removeQuotes(assignmentValue.value()).isEmpty()) {
            testPattern(assignment.target(), targetPattern);
            testPattern(assignment.value(), valuePattern);
        }
    }
}
Also used : AssignmentLike(org.sonar.uast.helpers.AssignmentLike) LiteralLike(org.sonar.uast.helpers.LiteralLike)

Aggregations

AssignmentLike (org.sonar.uast.helpers.AssignmentLike)2 UastNode (org.sonar.uast.UastNode)1 LiteralLike (org.sonar.uast.helpers.LiteralLike)1