enclose-io/compiler

View on GitHub
lts/tools/inspector_protocol/code_generator.py

Summary

Maintainability
F
2 mos
Test Coverage

File code_generator.py has 540 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Severity: Major
Found in lts/tools/inspector_protocol/code_generator.py - About 1 day to fix

    Function read_config has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def read_config():
        # pylint: disable=W0703
        def json_to_object(data, output_base):
            def json_object_hook(object_dict):
                items = [(k, os.path.join(output_base, v) if k == "path" else v) for (k, v) in object_dict.items()]
    Severity: Minor
    Found in lts/tools/inspector_protocol/code_generator.py - About 4 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 main has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():
        jinja_dir, config_file, config = read_config()
    
        protocol = Protocol(config)
    
    
    Severity: Minor
    Found in lts/tools/inspector_protocol/code_generator.py - About 3 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 generate_used_types has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def generate_used_types(self):
            all_refs = set()
            for domain in self.json_api["domains"]:
                domain_name = domain["domain"]
                if "commands" in domain:
    Severity: Minor
    Found in lts/tools/inspector_protocol/code_generator.py - About 3 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 patch_full_qualified_refs has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def patch_full_qualified_refs(self):
            def patch_full_qualified_refs_in_domain(json, domain_name):
                if isinstance(json, list):
                    for item in json:
                        patch_full_qualified_refs_in_domain(item, domain_name)
    Severity: Minor
    Found in lts/tools/inspector_protocol/code_generator.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 create_type_definitions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def create_type_definitions(self):
            imported_namespace = "::".join(self.config.imported.namespace) if self.config.imported else ""
            self.type_definitions = {}
            self.type_definitions["number"] = create_primitive_type_definition("number")
            self.type_definitions["integer"] = create_primitive_type_definition("integer")
    Severity: Minor
    Found in lts/tools/inspector_protocol/code_generator.py - About 1 hr 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 create_notification_types has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def create_notification_types(self):
            for domain in self.json_api["domains"]:
                if "events" in domain:
                    for event in domain["events"]:
                        event_type = dict()
    Severity: Minor
    Found in lts/tools/inspector_protocol/code_generator.py - About 1 hr 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 main has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def main():
        jinja_dir, config_file, config = read_config()
    
        protocol = Protocol(config)
    
    
    Severity: Minor
    Found in lts/tools/inspector_protocol/code_generator.py - About 1 hr to fix

      Function all_references has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def all_references(self, json):
              refs = set()
              if isinstance(json, list):
                  for item in json:
                      refs |= self.all_references(item)
      Severity: Minor
      Found in lts/tools/inspector_protocol/code_generator.py - About 45 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 check_options has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def check_options(self, options, domain, name, include_attr, exclude_attr, default):
      Severity: Minor
      Found in lts/tools/inspector_protocol/code_generator.py - About 45 mins to fix

        Function check_options has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def check_options(self, options, domain, name, include_attr, exclude_attr, default):
                for rule in options:
                    if rule.domain != domain:
                        continue
                    if include_attr and hasattr(rule, include_attr):
        Severity: Minor
        Found in lts/tools/inspector_protocol/code_generator.py - About 35 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 generate_type_dependencies has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def generate_type_dependencies(self):
                dependencies = dict()
                domains_with_types = (x for x in self.json_api["domains"] if "types" in x)
                for domain in domains_with_types:
                    domain_name = domain["domain"]
        Severity: Minor
        Found in lts/tools/inspector_protocol/code_generator.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

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

        Severity: Major
        Found in lts/tools/inspector_protocol/code_generator.py and 1 other location - About 1 mo to fix
        current/tools/inspector_protocol/code_generator.py on lines 0..690

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 5297.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status