Esempio n. 1
0
    def __init__(self):
        self.project_name = None
        self.cpp_header_map = {}
        self.cpp_src_map = {}
        self.python_map = {}
        pylint_disable = [
            'superfluous-parens', 'too-many-instance-attributes',
            'too-few-public-methods'
        ]
        # setup pylint
        self.pylint_opts = [
            '--extension-pkg-whitelist=numpy',
            '--disable=' + ','.join(pylint_disable)
        ]

        self.pylint_cats = set(['error', 'warning', 'convention', 'refactor'])
        # setup cpp lint
        cpplint_args = ['.', '--extensions=' + (','.join(CXX_SUFFIX))]
        _ = cpplint.ParseArguments(cpplint_args)
        cpplint._SetFilters(','.join([
            '-build/c++11', '-build/namespaces', '-build/include,',
            '+build/include_what_you_use', '+build/include_order'
        ]))
        cpplint._SetCountingStyle('toplevel')
        cpplint._line_length = 100
Esempio n. 2
0
    def __init__(self):
        self.project_name = None
        self.cpp_header_map = {}
        self.cpp_src_map = {}
        self.python_map = {}
        pylint_disable = ["superfluous-parens", "too-many-instance-attributes", "too-few-public-methods"]
        # setup pylint
        self.pylint_opts = ["--extension-pkg-whitelist=numpy", "--disable=" + ",".join(pylint_disable)]

        self.pylint_cats = set(["error", "warning", "convention", "refactor"])
        # setup cpp lint
        cpplint_args = [".", "--extensions=" + (",".join(CXX_SUFFIX))]
        _ = cpplint.ParseArguments(cpplint_args)
        cpplint._SetFilters(
            ",".join(
                [
                    "-build/c++11",
                    "-build/namespaces",
                    "-build/include,",
                    "+build/include_what_you_use",
                    "+build/include_order",
                ]
            )
        )
        cpplint._SetCountingStyle("toplevel")
        cpplint._line_length = 100
def CheckChangeLintsClean(input_api, output_api, source_file_filter=None):
  """Checks that all '.cc' and '.h' files pass cpplint.py."""
  _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$')
  result = []

  # Initialize cpplint.
  import cpplint
  # Access to a protected member _XX of a client class
  # pylint: disable=W0212
  cpplint._cpplint_state.ResetErrorCounts()

  # Justifications for each filter:
  #
  # - build/include       : Too many; fix in the future.
  # - build/include_order : Not happening; #ifdefed includes.
  # - build/namespace     : I'm surprised by how often we violate this rule.
  # - readability/casting : Mistakes a whole bunch of function pointer.
  # - runtime/int         : Can be fixed long term; volume of errors too high
  # - runtime/virtual     : Broken now, but can be fixed in the future?
  # - whitespace/braces   : We have a lot of explicit scoping in chrome code.
  cpplint._SetFilters('-build/include,-build/include_order,-build/namespace,'
                      '-readability/casting,-runtime/int,-runtime/virtual,'
                      '-whitespace/braces')

  # Replace <hash_map> and <hash_set> as headers that need to be included
  # with "base/hash_tables.h" instead.
  cpplint._re_pattern_templates = [
    (a, b, 'base/hash_tables.h')
      if header in ('<hash_map>', '<hash_set>') else (a, b, header)
    for (a, b, header) in cpplint._re_pattern_templates
  ]

  # We currently are more strict with normal code than unit tests; 4 and 5 are
  # the verbosity level that would normally be passed to cpplint.py through
  # --verbose=#. Hopefully, in the future, we can be more verbose.
  files = [f.AbsoluteLocalPath() for f in
           input_api.AffectedSourceFiles(source_file_filter)]
  for file_name in files:
    if _RE_IS_TEST.match(file_name):
      level = 5
    else:
      level = 4

    cpplint.ProcessFile(file_name, level)

  if cpplint._cpplint_state.error_count > 0:
    if input_api.is_committing:
      res_type = output_api.PresubmitError
    else:
      res_type = output_api.PresubmitPromptWarning
    result = [res_type('Changelist failed cpplint.py check.')]

  return result
Esempio n. 4
0
def _CheckApprovedFilesLintClean(input_api,
                                 output_api,
                                 source_file_filter=None):
    """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
  This check is based on _CheckChangeLintsClean in
  depot_tools/presubmit_canned_checks.py but has less filters and only checks
  added files."""
    result = []

    # Initialize cpplint.
    import cpplint
    # Access to a protected member _XX of a client class
    # pylint: disable=W0212
    cpplint._cpplint_state.ResetErrorCounts()

    lint_filters = cpplint._Filters()
    lint_filters.extend(BLACKLIST_LINT_FILTERS)
    cpplint._SetFilters(','.join(lint_filters))

    # Create a platform independent whitelist for the CPPLINT_DIRS.
    whitelist_dirs = [
        input_api.os_path.join(*path.split('/')) for path in CPPLINT_DIRS
    ]

    # Use the strictest verbosity level for cpplint.py (level 1) which is the
    # default when running cpplint.py from command line.
    # To make it possible to work with not-yet-converted code, we're only applying
    # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
    verbosity_level = 1
    files = []
    for f in input_api.AffectedSourceFiles(source_file_filter):
        # Note that moved/renamed files also count as added.
        if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs,
                                                   f.LocalPath()):
            files.append(f.AbsoluteLocalPath())

    for file_name in files:
        cpplint.ProcessFile(file_name, verbosity_level)

    if cpplint._cpplint_state.error_count > 0:
        if input_api.is_committing:
            # TODO(kjellander): Change back to PresubmitError below when we're
            # confident with the lint settings.
            res_type = output_api.PresubmitPromptWarning
        else:
            res_type = output_api.PresubmitPromptWarning
        result = [res_type('Changelist failed cpplint.py check.')]

    return result
Esempio n. 5
0
def CheckChangeLintsClean(input_api, output_api, source_file_filter=None):
    """Checks that all '.cc' and '.h' files pass cpplint.py."""
    _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$')
    result = []

    # Initialize cpplint.
    import cpplint
    # Access to a protected member _XX of a client class
    # pylint: disable=W0212
    cpplint._cpplint_state.ResetErrorCounts()

    # Justifications for each filter:
    #
    # - build/include       : Too many; fix in the future.
    # - build/include_order : Not happening; #ifdefed includes.
    # - build/namespace     : I'm surprised by how often we violate this rule.
    # - readability/casting : Mistakes a whole bunch of function pointer.
    # - runtime/int         : Can be fixed long term; volume of errors too high
    # - runtime/virtual     : Broken now, but can be fixed in the future?
    # - whitespace/braces   : We have a lot of explicit scoping in chrome code.
    cpplint._SetFilters('-build/include,-build/include_order,-build/namespace,'
                        '-readability/casting,-runtime/int,-runtime/virtual,'
                        '-whitespace/braces')

    # We currently are more strict with normal code than unit tests; 4 and 5 are
    # the verbosity level that would normally be passed to cpplint.py through
    # --verbose=#. Hopefully, in the future, we can be more verbose.
    files = [
        f.AbsoluteLocalPath()
        for f in input_api.AffectedSourceFiles(source_file_filter)
    ]
    for file_name in files:
        if _RE_IS_TEST.match(file_name):
            level = 5
        else:
            level = 4

        cpplint.ProcessFile(file_name, level)

    if cpplint._cpplint_state.error_count > 0:
        if input_api.is_committing:
            res_type = output_api.PresubmitError
        else:
            res_type = output_api.PresubmitPromptWarning
        result = [res_type('Changelist failed cpplint.py check.')]

    return result
Esempio n. 6
0
def _CheckApprovedFilesLintClean(input_api, output_api,
                                 source_file_filter=None):
  """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
  This check is based on _CheckChangeLintsClean in
  depot_tools/presubmit_canned_checks.py but has less filters and only checks
  added files."""
  result = []

  # Initialize cpplint.
  import cpplint
  # Access to a protected member _XX of a client class
  # pylint: disable=W0212
  cpplint._cpplint_state.ResetErrorCounts()

  lint_filters = cpplint._Filters()
  lint_filters.extend(BLACKLIST_LINT_FILTERS)
  cpplint._SetFilters(','.join(lint_filters))

  # Create a platform independent whitelist for the CPPLINT_DIRS.
  whitelist_dirs = [input_api.os_path.join(*path.split('/'))
                    for path in CPPLINT_DIRS]

  # Use the strictest verbosity level for cpplint.py (level 1) which is the
  # default when running cpplint.py from command line.
  # To make it possible to work with not-yet-converted code, we're only applying
  # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
  verbosity_level = 1
  files = []
  for f in input_api.AffectedSourceFiles(source_file_filter):
    # Note that moved/renamed files also count as added.
    if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()):
      files.append(f.AbsoluteLocalPath())

  for file_name in files:
    cpplint.ProcessFile(file_name, verbosity_level)

  if cpplint._cpplint_state.error_count > 0:
    if input_api.is_committing:
      # TODO(kjellander): Change back to PresubmitError below when we're
      # confident with the lint settings.
      res_type = output_api.PresubmitPromptWarning
    else:
      res_type = output_api.PresubmitPromptWarning
    result = [res_type('Changelist failed cpplint.py check.')]

  return result
Esempio n. 7
0
def _CheckApprovedFilesLintClean(input_api,
                                 output_api,
                                 source_file_filter=None):
    """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
  This check is based on _CheckChangeLintsClean in
  depot_tools/presubmit_canned_checks.py but has less filters and only checks
  added files."""
    result = []

    # Initialize cpplint.
    import cpplint
    # Access to a protected member _XX of a client class
    # pylint: disable=W0212
    cpplint._cpplint_state.ResetErrorCounts()

    # Justifications for each filter:
    #
    # - build/header_guard  : WebRTC coding style says they should be prefixed
    #                         with WEBRTC_, which is not possible to configure in
    #                         cpplint.py.
    cpplint._SetFilters('-build/header_guard')

    # Use the strictest verbosity level for cpplint.py (level 1) which is the
    # default when running cpplint.py from command line.
    # To make it possible to work with not-yet-converted code, we're only applying
    # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
    verbosity_level = 1
    files = []
    for f in input_api.AffectedSourceFiles(source_file_filter):
        # Note that moved/renamed files also count as added.
        if f.Action() == 'A':
            files.append(f.AbsoluteLocalPath())

    for file_name in files:
        cpplint.ProcessFile(file_name, verbosity_level)

    if cpplint._cpplint_state.error_count > 0:
        if input_api.is_committing:
            # TODO(kjellander): Change back to PresubmitError below when we're
            # confident with the lint settings.
            res_type = output_api.PresubmitPromptWarning
        else:
            res_type = output_api.PresubmitPromptWarning
        result = [res_type('Changelist failed cpplint.py check.')]

    return result
Esempio n. 8
0
def _CheckApprovedFilesLintClean(input_api, output_api,
                                 source_file_filter=None):
  """Checks that all new or whitelisted .cc and .h files pass cpplint.py.
  This check is based on _CheckChangeLintsClean in
  depot_tools/presubmit_canned_checks.py but has less filters and only checks
  added files."""
  result = []

  # Initialize cpplint.
  import cpplint
  # Access to a protected member _XX of a client class
  # pylint: disable=W0212
  cpplint._cpplint_state.ResetErrorCounts()

  # Justifications for each filter:
  #
  # - build/header_guard  : WebRTC coding style says they should be prefixed
  #                         with WEBRTC_, which is not possible to configure in
  #                         cpplint.py.
  cpplint._SetFilters('-build/header_guard')

  # Use the strictest verbosity level for cpplint.py (level 1) which is the
  # default when running cpplint.py from command line.
  # To make it possible to work with not-yet-converted code, we're only applying
  # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
  verbosity_level = 1
  files = []
  for f in input_api.AffectedSourceFiles(source_file_filter):
    # Note that moved/renamed files also count as added for svn.
    if (f.Action() == 'A'):
      files.append(f.AbsoluteLocalPath())

  for file_name in files:
    cpplint.ProcessFile(file_name, verbosity_level)

  if cpplint._cpplint_state.error_count > 0:
    if input_api.is_committing:
      # TODO(kjellander): Change back to PresubmitError below when we're
      # confident with the lint settings.
      res_type = output_api.PresubmitPromptWarning
    else:
      res_type = output_api.PresubmitPromptWarning
    result = [res_type('Changelist failed cpplint.py check.')]

  return result
Esempio n. 9
0
def CheckChangeLintsClean(input_api, output_api, source_file_filter=None):
  """Checks that all ".cc" and ".h" files pass cpplint.py."""
  _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$')
  result = []

  # Initialize cpplint.
  import cpplint
  cpplint._cpplint_state.ResetErrorCounts()

  # Justifications for each filter:
  #
  # - build/include       : Too many; fix in the future.
  # - build/include_order : Not happening; #ifdefed includes.
  # - build/namespace     : I'm surprised by how often we violate this rule.
  # - readability/casting : Mistakes a whole bunch of function pointer.
  # - runtime/int         : Can be fixed long term; volume of errors too high
  # - runtime/virtual     : Broken now, but can be fixed in the future?
  # - whitespace/braces   : We have a lot of explicit scoping in chrome code.
  cpplint._SetFilters("-build/include,-build/include_order,-build/namespace,"
                      "-readability/casting,-runtime/int,-runtime/virtual,"
                      "-whitespace/braces")

  # We currently are more strict with normal code than unit tests; 4 and 5 are
  # the verbosity level that would normally be passed to cpplint.py through
  # --verbose=#. Hopefully, in the future, we can be more verbose.
  files = [f.AbsoluteLocalPath() for f in
           input_api.AffectedSourceFiles(source_file_filter)]
  for file_name in files:
    if _RE_IS_TEST.match(file_name):
      level = 5
    else:
      level = 4

    cpplint.ProcessFile(file_name, level)

  if cpplint._cpplint_state.error_count > 0:
    if input_api.is_committing:
      res_type = output_api.PresubmitError
    else:
      res_type = output_api.PresubmitPromptWarning
    result = [res_type("Changelist failed cpplint.py check.")]

  return result
Esempio n. 10
0
 def __init__(self):
     self.project_name = None
     self.cpp_header_map = {}
     self.cpp_src_map = {}
     self.python_map = {}
     # setup pylint
     self.pylint_opts = ['--extension-pkg-whitelist=numpy',
                         '-d', 'superfluous-parens']
     self.pylint_cats = set(['error', 'warning', 'convention'])
     # setup cpp lint
     cpplint_args = ['.', '--extensions=' + (','.join(CXX_SUFFIX))]
     _ = cpplint.ParseArguments(cpplint_args)
     cpplint._SetFilters(','.join(['-build/c++11',
                                   '-build/namespaces',
                                   '-build/include,',
                                   '+build/include_what_you_use',
                                   '+build/include_order']))
     cpplint._SetCountingStyle('toplevel')
     cpplint._line_length = 100
Esempio n. 11
0
    def __init__(self):
        self.project_name = None
        self.cpp_header_map = {}
        self.cpp_src_map = {}
        self.python_map = {}
        pylint_disable = ['superfluous-parens',
                          'too-many-instance-attributes',
                          'too-few-public-methods']
        # setup pylint
        self.pylint_opts = ['--extension-pkg-whitelist=numpy',
                            '--disable=' + ','.join(pylint_disable)]

        self.pylint_cats = set(['error', 'warning', 'convention', 'refactor'])
        # setup cpp lint
        cpplint_args = ['.', '--extensions=' + (','.join(CXX_SUFFIX))]
        _ = cpplint.ParseArguments(cpplint_args)
        cpplint._SetFilters(','.join(['-build/c++11',
                                      '-build/namespaces',
                                      '-build/include',
                                      '-build/header_guard',
                                      '+build/include_what_you_use',
                                      '+build/include_order']))
        cpplint._SetCountingStyle('toplevel')
        cpplint._line_length = 100
Esempio n. 12
0
 def __init__(self):
     self.cpp_header_map = {}
     self.cpp_src_map = {}
     self.python_map = {}
     # setup pylint
     self.pylint_opts = ["--extension-pkg-whitelist=numpy", "-d", "superfluous-parens"]
     self.pylint_cats = set(["error", "warning", "convention"])
     # setup cpp lint
     cpplint_args = ["."]
     _ = cpplint.ParseArguments(cpplint_args)
     cpplint._SetFilters(
         ",".join(
             [
                 "-build/header_guard",
                 "-build/c++11",
                 "-build/namespaces",
                 "-build/include,",
                 "+build/include_what_you_use",
                 "+build/include_order",
             ]
         )
     )
     cpplint._SetCountingStyle("toplevel")
     cpplint._line_length = 100
Esempio n. 13
0
def ParseArguments(args):
    """Parses the command line arguments.

  This may set the output format and verbosity level as side-effects.

  Args:
    args: The command line arguments:

  Returns:
    The list of filenames to lint.
  """
    try:
        (opts, filenames) = getopt.getopt(args, '', [
            'help', 'output=', 'verbose=', 'v=', 'version', 'counting=',
            'filter=', 'cfg=', 'third-rule-path=', 'root=', 'repository=',
            'linelength=', 'extensions=', 'exclude=', 'recursive', 'headers=',
            'quiet'
        ])
    except getopt.GetoptError:
        cpplint.PrintUsage('Invalid arguments.')

    verbosity = cpplint._VerboseLevel()
    output_format = cpplint._OutputFormat()
    filters = ''
    quiet = cpplint._Quiet()
    counting_style = ''
    recursive = False

    for (opt, val) in opts:
        if opt == '--help':
            cpplint.PrintUsage(None)
        if opt == '--version':
            cpplint.PrintVersion()
        elif opt == '--output':
            if val not in ('emacs', 'vs7', 'eclipse', 'junit', 'codecc'):
                cpplint.PrintUsage(
                    'The only allowed output formats are emacs, vs7, eclipse, codecc '
                    'and junit.')
            output_format = val
        elif opt == '--quiet':
            quiet = True
        elif opt == '--verbose' or opt == '--v':
            verbosity = int(val)
        elif opt == '--filter':
            filters = val
            if not filters:
                cpplint.PrintCategories()
        elif opt == '--cfg':
            filters = config_fliter(val)
            if not filters:
                cpplint.PrintCategories()
        elif opt == '--third-rule-path':
            global thirdRuleSet
            thirdRuleSet = third_rules_set(val)
        elif opt == '--counting':
            if val not in ('total', 'toplevel', 'detailed'):
                cpplint.PrintUsage(
                    'Valid counting options are total, toplevel, and detailed')
            counting_style = val
        elif opt == '--root':
            cpplint._root = val
        elif opt == '--repository':
            cpplint._repository = val
        elif opt == '--linelength':
            try:
                cpplint._line_length = int(val)
            except ValueError:
                cpplint.PrintUsage('Line length must be digits.')
        elif opt == '--exclude':
            if not cpplint._excludes:
                cpplint._excludes = set()
            cpplint._excludes.update(glob.glob(val))
        elif opt == '--extensions':
            try:
                cpplint._valid_extensions = set(val.split(','))
            except ValueError:
                cpplint.PrintUsage('Extensions must be comma seperated list.')
        elif opt == '--headers':
            cpplint.ProcessHppHeadersOption(val)
        elif opt == '--recursive':
            recursive = True

    if not filenames:
        cpplint.PrintUsage('No files were specified.')

    if recursive:
        filenames = cpplint._ExpandDirectories(filenames)

    if cpplint._excludes:
        filenames = cpplint._FilterExcludedFiles(filenames)

    cpplint._SetOutputFormat(output_format)
    cpplint._SetQuiet(quiet)
    cpplint._SetVerboseLevel(verbosity)
    cpplint._SetFilters(filters)
    cpplint._SetCountingStyle(counting_style)
    return filenames