alot/widgets/globals.py

Summary

Maintainability
D
2 days
Test Coverage

Function keypress has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

    def keypress(self, size, key):
        # if we tabcomplete
        if key in ['tab', 'shift tab'] and self.completer:
            # if not already in completion mode
            if self.completions is None:
Severity: Minor
Found in alot/widgets/globals.py - About 7 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

File globals.py has 307 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright (C) 2011-2012  Patrick Totzke <patricktotzke@gmail.com>
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file

"""
Severity: Minor
Found in alot/widgets/globals.py - About 3 hrs to fix

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

        def __init__(self, completer, on_exit,
    Severity: Minor
    Found in alot/widgets/globals.py - About 45 mins to fix

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

          def __init__(self, choices, callback, cancel=None, select=None,
      Severity: Minor
      Found in alot/widgets/globals.py - About 45 mins to fix

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

            def __init__(self, choices, callback, cancel=None, select=None,
                         separator=' ', choices_to_return=None):
                self.choices = choices
                self.choices_to_return = choices_to_return or {}
                self.callback = callback
        Severity: Minor
        Found in alot/widgets/globals.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

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

                elif key in ('meta delete', 'meta backspace', 'ctrl w'):
                    end_pos = self.edit_pos
                    start_pos = self.move_to_next_word(forward=False)
                    if start_pos is not None:
                        self.edit_text = (self.edit_text[:start_pos] +
        Severity: Major
        Found in alot/widgets/globals.py and 1 other location - About 3 hrs to fix
        alot/widgets/globals.py on lines 199..205

        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 69.

        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

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

                elif key == 'meta d':
                    start_pos = self.edit_pos
                    end_pos = self.move_to_next_word(forward=True)
                    if end_pos is not None:
                        self.edit_text = (self.edit_text[:start_pos] +
        Severity: Major
        Found in alot/widgets/globals.py and 1 other location - About 3 hrs to fix
        alot/widgets/globals.py on lines 206..212

        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 69.

        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

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

                for key, value in lines:
                    if len(key) > max_key_len:
                        max_key_len = len(key)
        Severity: Minor
        Found in alot/widgets/globals.py and 1 other location - About 30 mins to fix
        alot/widgets/thread.py on lines 137..139

        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 32.

        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

        Missing whitespace around arithmetic operator
        Open

                    self.set_edit_pos(min(self.edit_pos+1, len(self.edit_text)))
        Severity: Minor
        Found in alot/widgets/globals.py by pep8

        Surround operators with a single space on either side.

        - Always surround these binary operators with a single space on
          either side: assignment (=), augmented assignment (+=, -= etc.),
          comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
          Booleans (and, or, not).
        
        - If operators with different priorities are used, consider adding
          whitespace around the operators with the lowest priorities.
        
        Okay: i = i + 1
        Okay: submitted += 1
        Okay: x = x * 2 - 1
        Okay: hypot2 = x * x + y * y
        Okay: c = (a + b) * (a - b)
        Okay: foo(bar, key='word', *args, **kwargs)
        Okay: alpha[:-i]
        
        E225: i=i+1
        E225: submitted +=1
        E225: x = x /2 - 1
        E225: z = x **y
        E225: z = 1and 1
        E226: c = (a+b) * (a-b)
        E226: hypot2 = x*x + y*y
        E227: c = a|b
        E228: msg = fmt%(errno, errmsg)

        Line break after binary operator
        Open

                        self.edit_text = (self.edit_text[:start_pos] +
        Severity: Minor
        Found in alot/widgets/globals.py by pep8

        Avoid breaks after binary operators.

        The preferred place to break around a binary operator is before the
        operator, not after it.
        
        W504: (width == 0 +\n height == 0)
        W504: (width == 0 and\n height == 0)
        W504: var = (1 &\n       ~2)
        
        Okay: foo(\n    -x)
        Okay: foo(x\n    [])
        Okay: x = '''\n''' + ''
        Okay: x = '' + '''\n'''
        Okay: foo(x,\n    -y)
        Okay: foo(x,  # comment\n    -y)
        
        The following should be W504 but unary_context is tricky with these
        Okay: var = (1 /\n       -2)
        Okay: var = (1 +\n       -1 +\n       -2)

        Missing whitespace around arithmetic operator
        Open

                    self.set_edit_pos(max(self.edit_pos-1, 0))
        Severity: Minor
        Found in alot/widgets/globals.py by pep8

        Surround operators with a single space on either side.

        - Always surround these binary operators with a single space on
          either side: assignment (=), augmented assignment (+=, -= etc.),
          comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
          Booleans (and, or, not).
        
        - If operators with different priorities are used, consider adding
          whitespace around the operators with the lowest priorities.
        
        Okay: i = i + 1
        Okay: submitted += 1
        Okay: x = x * 2 - 1
        Okay: hypot2 = x * x + y * y
        Okay: c = (a + b) * (a - b)
        Okay: foo(bar, key='word', *args, **kwargs)
        Okay: alpha[:-i]
        
        E225: i=i+1
        E225: submitted +=1
        E225: x = x /2 - 1
        E225: z = x **y
        E225: z = 1and 1
        E226: c = (a+b) * (a-b)
        E226: hypot2 = x*x + y*y
        E227: c = a|b
        E228: msg = fmt%(errno, errmsg)

        Missing whitespace around arithmetic operator
        Open

                                      self.edit_text[self.edit_pos+1:])
        Severity: Minor
        Found in alot/widgets/globals.py by pep8

        Surround operators with a single space on either side.

        - Always surround these binary operators with a single space on
          either side: assignment (=), augmented assignment (+=, -= etc.),
          comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
          Booleans (and, or, not).
        
        - If operators with different priorities are used, consider adding
          whitespace around the operators with the lowest priorities.
        
        Okay: i = i + 1
        Okay: submitted += 1
        Okay: x = x * 2 - 1
        Okay: hypot2 = x * x + y * y
        Okay: c = (a + b) * (a - b)
        Okay: foo(bar, key='word', *args, **kwargs)
        Okay: alpha[:-i]
        
        E225: i=i+1
        E225: submitted +=1
        E225: x = x /2 - 1
        E225: z = x **y
        E225: z = 1and 1
        E226: c = (a+b) * (a-b)
        E226: hypot2 = x*x + y*y
        E227: c = a|b
        E228: msg = fmt%(errno, errmsg)

        Line break after binary operator
        Open

                        self.edit_text = (self.edit_text[:start_pos] +
        Severity: Minor
        Found in alot/widgets/globals.py by pep8

        Avoid breaks after binary operators.

        The preferred place to break around a binary operator is before the
        operator, not after it.
        
        W504: (width == 0 +\n height == 0)
        W504: (width == 0 and\n height == 0)
        W504: var = (1 &\n       ~2)
        
        Okay: foo(\n    -x)
        Okay: foo(x\n    [])
        Okay: x = '''\n''' + ''
        Okay: x = '' + '''\n'''
        Okay: foo(x,\n    -y)
        Okay: foo(x,  # comment\n    -y)
        
        The following should be W504 but unary_context is tricky with these
        Okay: var = (1 /\n       -2)
        Okay: var = (1 +\n       -1 +\n       -2)

        Line break after binary operator
        Open

                    self.edit_text = (self.edit_text[:self.edit_pos] +
        Severity: Minor
        Found in alot/widgets/globals.py by pep8

        Avoid breaks after binary operators.

        The preferred place to break around a binary operator is before the
        operator, not after it.
        
        W504: (width == 0 +\n height == 0)
        W504: (width == 0 and\n height == 0)
        W504: var = (1 &\n       ~2)
        
        Okay: foo(\n    -x)
        Okay: foo(x\n    [])
        Okay: x = '''\n''' + ''
        Okay: x = '' + '''\n'''
        Okay: foo(x,\n    -y)
        Okay: foo(x,  # comment\n    -y)
        
        The following should be W504 but unary_context is tricky with these
        Okay: var = (1 /\n       -2)
        Okay: var = (1 +\n       -1 +\n       -2)

        There are no issues that match your filters.

        Category
        Status