Example #1
0
  private void validate(XmlElement node, IFile file) throws CoreException {
    // We need to be very smart about html attribute validation, as lots of html code
    // uses older attributes, or makes up their own custom attributes.
    // We should probably look for typos of the common attributes.
    if (DartCoreDebug.ENABLE_HTML_VALIDATION) {
      if (node.getAttributes().size() > 0) {
        List<String> validAttributes = HtmlKeywords.getAttributes(node.getLabel());

        if (!validAttributes.isEmpty()) {
          for (XmlAttribute attribute : node.getAttributes()) {
            String name = attribute.getName();

            // A common pattern with data-binding frameworks.
            if (name.startsWith("ng-")) {
              continue;
            }

            // A data attribute.
            if (name.startsWith("data-")) {
              continue;
            }

            if (!validAttributes.contains(name)) {
              if (!HtmlKeywords.isValidEventAttribute(name)) {
                int charStart = attribute.getStartToken().getLocation();
                String message =
                    "\""
                        + name
                        + "\" is not a valid attribute for the "
                        + "<"
                        + node.getLabel()
                        + "> element.";

                MarkerUtilities.createWarningMarker(
                    file,
                    message,
                    attribute.getStartToken().getLineNumber(),
                    charStart,
                    charStart + name.length());
              }
            }
          }
        }
      }
    }

    for (XmlNode child : node.getChildren()) {
      if (child instanceof XmlElement) {
        validate((XmlElement) child, file);
      }
    }
  }