Skip to content

Commit

Permalink
Expanded ignore handling. Closes cflint#285
Browse files Browse the repository at this point in the history
  • Loading branch information
denuno authored and TheRealAgentK committed Jun 11, 2017
1 parent 1f8413a commit 84adbc8
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ private void process(final CFScriptStatement expression, Context context) {
}
} else if (expression instanceof CFExpressionStatement) {
scanExpression(expression, context, elem);
registerRuleOverrides(context, (CFExpressionStatement) expression);
process(((CFExpressionStatement) expression).getExpression(), elem, context);
} else if (expression instanceof CFPropertyStatement) {
try{
Expand Down Expand Up @@ -701,6 +702,35 @@ protected void registerRuleOverrides(Context context, final Token functionToken)
}
}
}

/**
* @param context
* @param functionToken Register any overrides from single-line comments.
* @param context The current context.
* @param expression the expression statement to check
*/
protected void registerRuleOverrides(Context context, final CFExpressionStatement expression) {
if(expression.getTokens() == null) {
return;
}
Iterable<Token> tokens = expression.getTokens().getTokens();
for (Token currentTok : tokens) {
System.out.println(currentTok.toString());
if (currentTok.getLine() == expression.getExpression().getLine()) {
if (currentTok.getChannel() == Token.HIDDEN_CHANNEL && currentTok.getType() == CFSCRIPTLexer.LINE_COMMENT) {
final String commentText = currentTok.getText().replaceFirst("^//\\s*", "").trim();
if (commentText.startsWith("cflint ")) {
Pattern pattern = Pattern.compile("cflint\\s+ignore:([\\w,]+).*");
final Matcher matcher = pattern.matcher(commentText);
if (matcher.matches()) {
String ignoreCodes = matcher.group(1);
context.ignore(Arrays.asList(ignoreCodes.split(",\\s*")));
}
}
}
}
}
}

/**
* Register any overrides from comment elements before functions/components.
Expand All @@ -722,7 +752,7 @@ protected void applyRuleOverrides(Context context, Element commentElement) {
}
}
}

/**
* Return the exception message, or its class name
*
Expand Down Expand Up @@ -926,7 +956,9 @@ protected void reportRule(final Element elem, final Object expression, final Con
bug.setLine(msg.getLine());
bug.setColumn(0);
}
bugs.add(bug);
if (context != null && !context.isSuppressed(bug)) {
bugs.add(bug);
}
}
}
}
Expand Down

0 comments on commit 84adbc8

Please sign in to comment.