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);
}
}
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);
}
}
}
Aggregations