Search in sources :

Example 96 with CFLintResult

use of com.cflint.api.CFLintResult in project CFLint by cflint.

the class TestCFBugs_VarScoper method testVarScoperCharOffset.

@Test
public void testVarScoperCharOffset() throws CFLintScanException {
    String src = "<cfscript>component {\r\n" + "public any function process(){\r\n" + "   x=123;\r\n" + "}\r\n" + "}</cfscript>";
    CFLintResult lintresult = cfBugs.scan(src, "test");
    List<BugInfo> list = lintresult.getIssues().get("MISSING_VAR");
    assertEquals(1, list.size());
    assertEquals("test", list.get(0).getFilename());
    assertEquals("process", list.get(0).getFunction());
    assertEquals(3, list.get(0).getLine());
    assertEquals(4, list.get(0).getColumn());
    assertEquals(58, src.indexOf('x'));
    assertEquals(58, list.get(0).getOffset());
}
Also used : CFLintResult(com.cflint.api.CFLintResult) Test(org.junit.Test)

Example 97 with CFLintResult

use of com.cflint.api.CFLintResult in project CFLint by cflint.

the class TestCFBugs_VarScoper_TagAttr method runTagAttrTest.

public void runTagAttrTest(final String tag, final String attr, final String variable) throws CFLintScanException {
    final String cfcSrc = "<cfcomponent>\r\n" + "<cffunction name=\"test\">\r\n" + "   <" + tag + " " + attr + "=\"" + variable + "\">\r\n" + "	</" + tag + ">\r\n" + "</cffunction>\r\n" + "</cfcomponent>";
    CFLintResult lintresult = cfBugs.scan(cfcSrc, "test");
    assertEquals(1, lintresult.getIssues().size());
    List<BugInfo> result = lintresult.getIssues().values().iterator().next();
    assertEquals(1, result.size());
    assertEquals("MISSING_VAR", result.get(0).getMessageCode());
    assertEquals(variable, result.get(0).getVariable());
    assertEquals(3, result.get(0).getLine());
}
Also used : CFLintResult(com.cflint.api.CFLintResult)

Example 98 with CFLintResult

use of com.cflint.api.CFLintResult in project CFLint by cflint.

the class TestCFBugs_VariableNames method nameIsTemporyTag.

@Test
public void nameIsTemporyTag() throws CFLintScanException {
    final String tagSrc = "<cfcomponent>\r\n" + "<cffunction name=\"test\">\r\n" + "	<cfset temp = \"Fred\">\r\n" + "	<cfset name.temp = \"Fred\">\r\n" + "	<cfset obj = \"Fred\">\r\n" + "	<cfset struct = \"Fred\">\r\n" + "	<cfset tempName = \"Fred\">\r\n" + "	<cfset nameObj = \"Fred\">\r\n" + "	<cfset nameString = \"Fred\">\r\n" + "</cffunction>\r\n" + "</cfcomponent>";
    CFLintResult lintresult = cfBugs.scan(tagSrc, "test");
    final List<BugInfo> result = lintresult.getIssues().get("VAR_IS_TEMPORARY");
    assertEquals(6, result.size());
    assertEquals("VAR_IS_TEMPORARY", result.get(0).getMessageCode());
    assertEquals(3, result.get(0).getLine());
    assertEquals("VAR_IS_TEMPORARY", result.get(1).getMessageCode());
    assertEquals(5, result.get(1).getLine());
    assertEquals("VAR_IS_TEMPORARY", result.get(2).getMessageCode());
    assertEquals(6, result.get(2).getLine());
    assertEquals("VAR_IS_TEMPORARY", result.get(3).getMessageCode());
    assertEquals(7, result.get(3).getLine());
    assertEquals("VAR_IS_TEMPORARY", result.get(4).getMessageCode());
    assertEquals(8, result.get(4).getLine());
    assertEquals("VAR_IS_TEMPORARY", result.get(5).getMessageCode());
    assertEquals(9, result.get(5).getLine());
}
Also used : CFLintResult(com.cflint.api.CFLintResult) Test(org.junit.Test)

Example 99 with CFLintResult

use of com.cflint.api.CFLintResult in project CFLint by cflint.

the class TestCFBugs_VariableNames method nameTooShortScript.

@Test
public void nameTooShortScript() throws CFLintScanException {
    final String scriptSrc = "component {\r\n" + "function test() {\r\n" + "	a = \"Fred\";\r\n" + "	b = \"Smith\";\r\n" + "	last.a = \"Fred\";\r\n" + "}\r\n" + "}";
    CFLintResult lintresult = cfBugs.scan(scriptSrc, "test");
    final List<BugInfo> result = lintresult.getIssues().values().iterator().next();
    assertEquals(2, result.size());
    assertEquals("VAR_TOO_SHORT", result.get(0).getMessageCode());
    assertEquals(3, result.get(0).getLine());
    assertEquals("VAR_TOO_SHORT", result.get(1).getMessageCode());
    assertEquals(4, result.get(1).getLine());
}
Also used : CFLintResult(com.cflint.api.CFLintResult) Test(org.junit.Test)

Example 100 with CFLintResult

use of com.cflint.api.CFLintResult in project CFLint by cflint.

the class TestCFBugs_VariableNames method testUpercaseNameScript.

@Test
public void testUpercaseNameScript() throws CFLintScanException {
    final String scriptSrc = "component {\r\n" + "function test() {\r\n" + "	var FIRSTNAME = \"Fred\";\r\n" + "	LAST_NAME = \"Smith\";\r\n" + "	names = {};\r\n" + "	name.FIRST = \"Fred\";\r\n" + "	NAMES[1] = \"Fred\";\r\n" + "	local.NAME = \"Fred\";\r\n" + "}\r\n" + "}";
    CFLintResult lintresult = cfBugs.scan(scriptSrc, "test");
    final List<BugInfo> result = lintresult.getIssues().values().iterator().next();
    assertEquals(1, result.size());
    assertEquals("VAR_ALLCAPS_NAME", result.get(0).getMessageCode());
    assertEquals(8, result.get(0).getLine());
}
Also used : CFLintResult(com.cflint.api.CFLintResult) Test(org.junit.Test)

Aggregations

CFLintResult (com.cflint.api.CFLintResult)298 Test (org.junit.Test)289 List (java.util.List)70 CFLintAPI (com.cflint.api.CFLintAPI)2 StringWriter (java.io.StringWriter)2 Ignore (org.junit.Ignore)2 CFLintConfiguration (com.cflint.config.CFLintConfiguration)1 CFLintConfigurationException (com.cflint.exception.CFLintConfigurationException)1 CFLintScanException (com.cflint.exception.CFLintScanException)1 MarshallerException (com.cflint.xml.MarshallerException)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 JAXBException (javax.xml.bind.JAXBException)1 TransformerException (javax.xml.transform.TransformerException)1