@SuppressWarnings("unchecked") private void checkAttributes(final Element element, final CFLintConfiguration configuration) { for (String tagInfo : (List<String>)configuration.getParameter(this,"usedTagAttributes", List.class)) { final String[] parts = (tagInfo + "//").split("/"); if (element.getName() != null && parts[0].equalsIgnoreCase(element.getName())) { final String name = element.getAttributeValue(parts[1]); if (name != null && localVariables.containsKey(name.toLowerCase())) { localVariables.put(name.toLowerCase(), new VarInfo(name, true)); } } } }
@Override public void element(final Element element, final Context context, final BugList bugs) { final String tagName = element.getName(); if (tagName.equals(CF.CFQUERY)) { String queryGuts = element.getContent().toString().replaceAll("\\s+", ""); queryGuts = queryGuts.toLowerCase(); if (queryGuts.contains(selectStar)) { context.addMessage("SQL_SELECT_STAR", null); } } } }
private TemplateNode parseElement(Element elem) { if (elem.getName().indexOf(':') > 0) { return parseComponent(elem); } else { return parseDomElement(elem); } }
/** * Parse a CF component tag declaration to see if it's missing a hint. */ @Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFCOMPONENT)) { final String hint = element.getAttributeValue(CF.HINT); if (hint == null || hint.trim().isEmpty()) { context.addMessage(COMPONENT_HINT_MISSING, context.calcComponentName()); } } }
private boolean containsOnlyInlineLevelChildElements(final Element element) { // returns true if the element contains only inline-level elements except for SCRIPT elements. final Collection<Element> childElements=element.getChildElements(); if (childElements.isEmpty()) return true; for (Element childElement : childElements) { final String elementName=childElement.getName(); if (elementName==HTMLElementName.SCRIPT || !HTMLElements.getInlineLevelElementNames().contains(elementName)) return false; if (!containsOnlyInlineLevelChildElements(childElement)) return false; } return true; } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if ("script".equals(element.getName())) { final String src = element.getStartTag().toString(); if (!src.matches(".*src=.*")) { context.addMessage("AVOID_USING_INLINE_JS", null); } } } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if ("script".equals(element.getName())) { final String src = element.getStartTag().toString(); if (!src.matches(".*src=.*")) { context.addMessage("AVOID_USING_INLINE_JS", null); } } } }
@Override public void element(final Element element, final Context context, final BugList bugs) { final String elementName = element.getName(); if (elementName.equals(CF.CFCOMPONENT)) { // this includes whitespace-change it final int total = element.getContent().toString().split("\\n").length; checkSize(LENGTH_THRESHOLD, "EXCESSIVE_COMPONENT_LENGTH", context, 1, 0, total, bugs); } } }
/** * Parse a CF argument tag to see if the argument hint is missing. */ @Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFARGUMENT)) { final String name = element.getAttributeValue(CF.NAME); final String hint = element.getAttributeValue(CF.HINT); if (hint == null || hint.length() == 0) { context.addMessage("ARG_HINT_MISSING", name); } } }
private static ElementHandler getElementHandler(final Element element) { if (element.getStartTag().getStartTagType().isServerTag()) return RemoveElementHandler.INSTANCE; // hard-coded configuration does not include server tags in child element hierarchy, so this is normally not executed. ElementHandler elementHandler=ELEMENT_HANDLERS.get(element.getName()); return (elementHandler!=null) ? elementHandler : StandardInlineElementHandler.INSTANCE; }
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFFUNCTION) && !trivalFunction(context.getFunctionName())) { functionCount++; checkNumberFunctions(functionCount, 1, 0, context, bugs, null); } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFFUNCTION) && !trivalFunction(context.getFunctionName())) { functionCount++; checkNumberFunctions(functionCount, 1, 0, context, bugs, null); } }
@Override public void element(final Element element, final Context context, final BugList bugs) { final String tagName = element.getName(); final String cfmlTagCheck = context.getConfiguration().getParameter(this,"tagName"); final String scope = context.getConfiguration().getParameter(this,"scope"); if (cfmlTagCheck != null && tagName.matches(cfmlTagCheck)) { if (scope == null || scope.equals(CF.COMPONENT) && context.isInComponent()) { context.addMessage("AVOID_USING_" + tagName.toUpperCase() + "_TAG", tagName); } } } }
@Override public void element(final Element element, final Context context, final BugList bugs) { final String tagName = element.getName(); final String cfmlTagCheck = context.getConfiguration().getParameter(this,"tagName"); final String scope = context.getConfiguration().getParameter(this,"scope"); if (cfmlTagCheck != null && tagName.matches(cfmlTagCheck)) { if (scope == null || scope.equals(CF.COMPONENT) && context.isInComponent()) { context.addMessage("AVOID_USING_" + tagName.toUpperCase() + "_TAG", tagName); } } } }
/** * Parse CF component tag declaration to see if the component name is invalid. */ @Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFCOMPONENT)) { final String name = context.getFilename().replace(".cfc", ""); checkNameForBugs(context, actualFileName(name), context.getFilename(), context.startLine(), element.getBegin(), bugs); } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFFUNCTION)) { final int begLine = element.getSource().getRow(element.getBegin()); final String functionType = element.getAttributeValue("returnType"); checkReturnType(functionType, begLine, context, bugs); } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFFUNCTION)) { final int begLine = element.getSource().getRow(element.getBegin()); final String functionType = element.getAttributeValue("returnType"); checkReturnType(functionType, begLine, context, bugs); } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFCOMPONENT)) { final String name = context.getComponentName(); final String nameAttribute = element.getAttributeValue(CF.NAME); if (nameAttribute != null) { didYouMeanDisplayName(name, element.getSource().getRow(element.getBegin()), context.offset() + element.getBegin(), context, bugs); } } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFCOMPONENT)) { final String name = context.getComponentName(); final String nameAttribute = element.getAttributeValue(CF.NAME); if (nameAttribute != null) { didYouMeanDisplayName(name, element.getSource().getRow(element.getBegin()), context.offset() + element.getBegin(), context, bugs); } } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFARGUMENT)) { final String name = element.getAttributeValue(CF.NAME); final boolean required = CFTool.toBoolean(element.getAttributeValue(CF.REQUIRED)); final String defaultExpr = element.getAttributeValue(CF.DEFAULT); if (!required && defaultExpr == null) { element.getSource().getRow(element.getBegin()); element.getSource().getColumn(element.getBegin()); context.addMessage("ARG_DEFAULT_MISSING", name); } } }