18F/domain-scan

View on GitHub
utils/scan_utils.py

Summary

Maintainability
D
1 day
Test Coverage

File scan_utils.py has 534 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import argparse
import codecs
import csv
import datetime
import errno
Severity: Major
Found in utils/scan_utils.py - About 1 day to fix

    Function _df_path has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def _df_path(arg: Path, domain_suffix: Union[str, None]=None) -> Iterable[str]:
        if arg.suffix == ".csv":
            with arg.open(encoding='utf-8', newline='') as csvfile:
                for row in csv.reader(csvfile):
                    if (not row) or (not row[0]) or (row[0].lower() == "domain") or (row[0].lower() == "domain name"):
    Severity: Minor
    Found in utils/scan_utils.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function build_scan_options_parser has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def build_scan_options_parser() -> ArgumentParser:
        """ Builds the argparse parser object. """
        parser = ArgumentParser(prefix_chars="--")
        parser.add_argument("domains", help="".join([
            "Either a comma-separated list of domains or the url of a CSV ",
    Severity: Minor
    Found in utils/scan_utils.py - About 1 hr to fix

      Function handle_domains_argument has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def handle_domains_argument(domains: str, cache_dir: Path) -> Union[Path, str]:
          # `domains` can be either a path or a domain name.
          # It can also be a URL, and if it is we want to download it now,
          # and then adjust the value to be the path of the cached download.
          # Note that the cache_dir is basically guaranteed to exist by the time
      Severity: Minor
      Found in utils/scan_utils.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Avoid deeply nested control flow statements.
      Open

                          if domain_suffix.startswith("."):
                              sep = ""
                          yield "%s%s%s" % (domain, sep, domain_suffix)
      Severity: Major
      Found in utils/scan_utils.py - About 45 mins to fix

        Function write_rows has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def write_rows(rows, domain, base_domain, scanner, csv_writer, meta={}):
        Severity: Minor
        Found in utils/scan_utils.py - About 45 mins to fix

          Function data_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def data_for(domain, operation, cache_dir="./cache"):
              path = cache_path(domain, operation, cache_dir=cache_dir)
              if os.path.exists(path):
                  raw = read(path)
                  data = json.loads(raw)
          Severity: Minor
          Found in utils/scan_utils.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function _get_action_from_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def _get_action_from_name(self, name):
                  """Given a name, get the Action instance registered with this parser.
                  If only it were made available in the ArgumentError object. It is
                  passed as its first arg...
                  """
          Severity: Minor
          Found in utils/scan_utils.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          There are no issues that match your filters.

          Category
          Status