All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cflint.plugins.core.BooleanExpressionChecker Maven / Gradle / Ivy

Go to download

A static code analysis tool for ColdFusion (in the spirit of FindBugs and Lint). With CFLint, you are able to analyze your ColdFusion code base for code violations.

There is a newer version: 1.5.0
Show newest version
package com.cflint.plugins.core;

import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;

import cfml.parsing.cfscript.CFBinaryExpression;
import cfml.parsing.cfscript.CFExpression;

public class BooleanExpressionChecker extends CFLintScannerAdapter {
	protected int lastLineNo = -1;

	// Reset the last line number
	@Override
	public void startFile(final String fileName, final BugList bugs) {
		super.startFile(fileName, bugs);
		lastLineNo = -1;
	}

	@Override
	public void expression(final CFExpression expression, final Context context, final BugList bugs) {
		if (expression instanceof CFBinaryExpression) {
			final String code = expression.Decompile(0).toLowerCase();

			if (hasExplicitBooleanCheck(code)) {
				final int lineNo = currentLine(expression, context);

				// Only report issue once per line
				if (lastLineNo != lineNo) {
					context.addMessage("EXPLICIT_BOOLEAN_CHECK", null);
					lastLineNo = lineNo;
				}
			}
		}

	}

	protected boolean hasExplicitBooleanCheck(final String code) {
		return code.contains("== true") || code.contains("eq true") || code.contains("is true")
				|| code.contains("!= true") || code.contains("== false") || code.contains("eq false")
				|| code.contains("is false") || code.contains("!= false");
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy