Example #1
0
 def DoNotUseInputTypeButtonCheck(self, line_number, line):
   regex = self.input_api.re.compile("""
       (<input [^>]*  # "<input " followed by anything but ">"
       type="button"  # type="button"
       [^>]*>)        # anything but ">" then ">"
       """,
       self.input_api.re.VERBOSE)
   return regex_check.RegexCheck(self.input_api.re, line_number, line, regex,
       'Use the button element instead of <input type="button">')
Example #2
0
 def I18nContentJavaScriptCaseCheck(self, line_number, line):
     regex = self.input_api.re.compile(
         """
     (?:^|\s)                      # start of line or whitespace
     i18n-content="                # i18n-content="
     ([A-Z][^"]*|[^"]*[-_][^"]*)"  # starts with caps or contains '-' or '_'
     """, self.input_api.re.VERBOSE)
     return regex_check.RegexCheck(self.input_api.re, line_number, line,
                                   regex,
                                   "For i18n-content use javaScriptCase.")
Example #3
0
 def LabelCheck(self, line_number, line):
     regex = self.input_api.re.compile(
         """
     (?:^|\s) # start of line or whitespace
     (for=)   # for=
     """, self.input_api.re.VERBOSE)
     return regex_check.RegexCheck(
         self.input_api.re, line_number, line, regex,
         "Avoid 'for' attribute on <label>. Place the input within the <label>, "
         "or use aria-labelledby for <select>.")
Example #4
0
 def DoNotUseSingleQuotesCheck(self, line_number, line):
   regex = self.input_api.re.compile("""
       <\S+                           # The tag name.
       (?:\s+\S+\$?="[^"]*"|\s+\S+)*  # Correctly quoted or non-value props.
       \s+(\S+\$?='[^']*')            # Find incorrectly quoted (foo='bar').
       [^>]*>                         # To the end of the tag.
       """,
       self.input_api.re.MULTILINE | self.input_api.re.VERBOSE)
   return regex_check.RegexCheck(self.input_api.re, line_number, line, regex,
       'Use double quotes rather than single quotes in HTML properties')
Example #5
0
    def ClassesUseDashFormCheck(self, line_number, line):
        msg = "Classes should use dash-form."
        re = self.input_api.re
        class_regex = re.compile(
            """
        (?:^|\s)                    # start of line or whitespace
        (class="[^"]*[A-Z_][^"]*")  # class contains caps or '_'
        """, re.VERBOSE)

        # $i18n{...} messes with highlighting. Special path for this.
        if "$i18n{" in line:
            match = re.search(class_regex, re.sub("\$i18n{[^}]+}", "", line))
            return "  line %d: %s" % (line_number, msg) if match else ""

        return regex_check.RegexCheck(re, line_number, line, class_regex, msg)
Example #6
0
 def LabelCheck(self, line_number, line):
     return regex_check.RegexCheck(
         self.input_api.re, line_number, line, "(for=)",
         "Avoid 'for' attribute on <label>. Place the input within the <label>, "
         "or use aria-labelledby for <select>.")
Example #7
0
 def RegexCheck(self, line_number, line, regex, message):
     return regex_check.RegexCheck(self.input_api.re, line_number, line,
                                   regex, message)
Example #8
0
 def QuotePolymerBindings(self, line_number, line):
     regex = self.input_api.re.compile(r"=(\[\[|\{\{)")
     return regex_check.RegexCheck(
         self.input_api.re, line_number, line, regex,
         'Please use quotes around Polymer bindings (i.e. attr="[[prop]]")')
Example #9
0
 def DoNotUseBrElementCheck(self, line_number, line):
     regex = r"(<br)"
     return regex_check.RegexCheck(
         self.input_api.re, line_number, line, regex,
         "Do not use <br>; place blocking elements (<div>) as appropriate.")
Example #10
0
 def DoNotCloseSingleTagsCheck(self, line_number, line):
     regex = r"(/>)"
     return regex_check.RegexCheck(self.input_api.re, line_number, line,
                                   regex, "Do not close single tags.")
Example #11
0
 def IncludeCheck(self, line_number, line):
   return regex_check.RegexCheck(self.input_api.re, line_number, line,
       "(</include>|<include.*/>)", "Closing <include> tags is unnecessary.")
Example #12
0
 def IncludeCheck(self, line_number, line):
     return regex_check.RegexCheck(
         self.input_api.re, line_number, line, "(</include>)",
         "</include> is unnecessary. Please remove.")
 def SelfClosingIncludeCheck(self, line_number, line):
     return regex_check.RegexCheck(
         self.input_api.re, line_number, line, '(</include>|<include.*/>)',
         'Closing <include> tags is unnecessary.')
 def DisallowIncludeCheck(self, msg, line_number, line):
     return regex_check.RegexCheck(self.input_api.re, line_number, line,
                                   '^\s*(?:\/[\*\/])?\s*(<include)\s*src=',
                                   msg)
 def DeprecatedMojoBindingsCheck(self, line_number, line):
     return regex_check.RegexCheck(
         self.input_api.re, line_number, line, '(mojo_bindings\.js)',
         'Please use mojo_bindings_lite.js in new code')