parameters: (self, contents, scope, module_doc)
docstring: check the documentation for consistency with the code (arguments to
          getopt() and others). This is only approximative, but should catch cases
          where an option was added and not documented.
docstring_summary: check the documentation for consistency with the code (arguments to
          getopt() and others). This is only approximative, but should catch cases
          where an option was added and not documented.
docstring_tokens: check the documentation for consistency with the code ( arguments to getopt () and others ) . This is only approximative but should catch cases where an option was added and not documented .
function: def _do_consistency_check(self, contents, scope, module_doc):
          """
          check the documentation for consistency with the code (arguments to
          getopt() and others). This is only approximative, but should catch cases
          where an option was added and not documented.
          """
  
          # search all option chars in getopt() calls, combine them & compare
          # against the documented set
          getopt_args = re.findall(r"\b(px4_|)getopt\b.*\"([a-zA-Z:]+)\"", contents)
          # there could be several getopt calls and it is not simple to find which
          # command it belongs to, so combine all into a single string
          getopt_args = reduce(lambda a, b: a + b[1], getopt_args, '').replace(':', '')
  
          # some modules don't use getopt or parse the options in another file,
          # so only check if both lists are not empty
          if len(getopt_args) > 0 and len(module_doc.options()) > 0:
              # sort & remove duplicates
              sorted_getopt_args = ''.join(set(sorted(getopt_args)))
              sorted_module_options = ''.join(set(sorted(module_doc.options())))
              if sorted_getopt_args != sorted_module_options:
                  failed = True
  
                  # do one more test: check if strcmp(..."-x"... is used instead
                  if len(sorted_getopt_args) < len(sorted_module_options):
                      failed = False
                      # iterate options that are only in module doc
                      for c in set(sorted_module_options) - set(sorted_getopt_args):
                          if len(re.findall(r"\bstrcmp\b.*\"-"+c+r"\"", contents)) == 0:
                              failed = True
  
                  if failed:
                      print(("Warning: documentation inconsistency in %s:" % scope))
                      print((" Documented options       : %s" % sorted_module_options))
                      print((" Options found in getopt(): %s" % sorted_getopt_args))
                      self._consistency_checks_failure = True
  
  
          # now check the commands: search for strcmp(argv[i], "command".
          # this will also find the value arguments, so append them too to the
          # module doc strings
          commands = re.findall(r"\bstrcmp\b.*argv\[.*\"(.+)\"", contents) + \
                     re.findall(r"\bstrcmp\b.*\"(.+)\".*argv\[", contents) + \
                     re.findall(r"\bstrcmp\b.*\bverb\b.*\"(.+)\"", contents)
  
          doc_commands = module_doc.all_commands() + \
                  [x for value in module_doc.all_values() for x in value.split('|')]
  
          for command in commands:
              if len(command) == 2 and command[0] == '-':
                  continue # skip options
  
              if command in ['start', 'stop', 'status']:
                  continue # handled in the base class
  
              if not command in doc_commands:
                  print(("Warning: undocumented command '%s' in %s" %(command, scope)))
                  self._consistency_checks_failure = True
  
          # limit the maximum line length in the module doc string
          max_line_length = 120
          module_doc = module_doc.documentation()
          verbatim_mode = False
          line_nr = 0
          for line in module_doc.split('\n'):
              line_nr += 1
              if line.strip().startswith('```'):
                  # ignore preformatted blocks
                  verbatim_mode = not verbatim_mode
              elif not verbatim_mode:
                  if not 'www.' in line and not 'http' in line:
                      if len(line) > max_line_length:
                          print(('Line too long (%i > %i) in %s:' % (len(line), max_line_length, scope)))
                          print((' '+line))
                          self._consistency_checks_failure = True
function_tokens: def _do_consistency_check ( self , contents , scope , module_doc ) : # search all option chars in getopt() calls, combine them & compare # against the documented set getopt_args = re . findall ( r"\b(px4_|)getopt\b.*\"([a-zA-Z:]+)\"" , contents ) # there could be several getopt calls and it is not simple to find which # command it belongs to, so combine all into a single string getopt_args = reduce ( lambda a , b : a + b [ 1 ] , getopt_args , '' ) . replace ( ':' , '' ) # some modules don't use getopt or parse the options in another file, # so only check if both lists are not empty if len ( getopt_args ) > 0 and len ( module_doc . options ( ) ) > 0 : # sort & remove duplicates sorted_getopt_args = '' . join ( set ( sorted ( getopt_args ) ) ) sorted_module_options = '' . join ( set ( sorted ( module_doc . options ( ) ) ) ) if sorted_getopt_args != sorted_module_options : failed = True # do one more test: check if strcmp(..."-x"... is used instead if len ( sorted_getopt_args ) < len ( sorted_module_options ) : failed = False # iterate options that are only in module doc for c in set ( sorted_module_options ) - set ( sorted_getopt_args ) : if len ( re . findall ( r"\bstrcmp\b.*\"-" + c + r"\"" , contents ) ) == 0 : failed = True if failed : print ( ( "Warning: documentation inconsistency in %s:" % scope ) ) print ( ( " Documented options       : %s" % sorted_module_options ) ) print ( ( " Options found in getopt(): %s" % sorted_getopt_args ) ) self . _consistency_checks_failure = True # now check the commands: search for strcmp(argv[i], "command". # this will also find the value arguments, so append them too to the # module doc strings commands = re . findall ( r"\bstrcmp\b.*argv\[.*\"(.+)\"" , contents ) + re . findall ( r"\bstrcmp\b.*\"(.+)\".*argv\[" , contents ) + re . findall ( r"\bstrcmp\b.*\bverb\b.*\"(.+)\"" , contents ) doc_commands = module_doc . all_commands ( ) + [ x for value in module_doc . all_values ( ) for x in value . split ( '|' ) ] for command in commands : if len ( command ) == 2 and command [ 0 ] == '-' : continue # skip options if command in [ 'start' , 'stop' , 'status' ] : continue # handled in the base class if not command in doc_commands : print ( ( "Warning: undocumented command '%s' in %s" % ( command , scope ) ) ) self . _consistency_checks_failure = True # limit the maximum line length in the module doc string max_line_length = 120 module_doc = module_doc . documentation ( ) verbatim_mode = False line_nr = 0 for line in module_doc . split ( '\n' ) : line_nr += 1 if line . strip ( ) . startswith ( '```' ) : # ignore preformatted blocks verbatim_mode = not verbatim_mode elif not verbatim_mode : if not 'www.' in line and not 'http' in line : if len ( line ) > max_line_length : print ( ( 'Line too long (%i > %i) in %s:' % ( len ( line ) , max_line_length , scope ) ) ) print ( ( ' ' + line ) ) self . _consistency_checks_failure = True