Showing 176 of 177 total issues

Function multi_phrase_search has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def multi_phrase_search(self, query, query_by=None, *args, **kwargs):
        """
        Given a query as string, runs it through clean_search to get a list of search terms,
        then returns a matching queryset of Contract objects for each of those terms.

Severity: Minor
Found in contracts/models.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 entrypoint has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

def entrypoint(argv):  # type: (List[str]) -> None
    '''
    This is a Docker entrypoint that configures the container to run
    as the same uid of the user on the host container, rather than
    the Docker default of root. Aside from following security best
Severity: Minor
Found in docker_django_management.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

File styleguide.py has 270 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import os.path
from html.parser import HTMLParser
from textwrap import dedent
from inspect import getsourcefile
from importlib import import_module
Severity: Minor
Found in styleguide/templatetags/styleguide.py - About 2 hrs to fix

    Function render has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      render() {
        const [min, max] = this.state.sliderVal;
    
        const rangeId = `${this.props.idPrefix}range`;
        const minId = `${this.props.idPrefix}min`;
    Severity: Major
    Found in frontend/source/js/data-explorer/components/experience.jsx - About 2 hrs to fix

      File email.py has 261 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import re
      from functools import wraps
      from django.core.mail import EmailMultiAlternatives, get_connection
      from django.utils.html import strip_tags
      from django.utils import timezone
      Severity: Minor
      Found in data_capture/email.py - About 2 hrs to fix

        Function populateFormData has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          populateFormData(formData) {
            // IE11 doesn't support FormData.prototype.delete(), so we need to
            // manually construct the FormData ourselves (we used to have
            // the browser construct it for us, and then replace the file).
            for (let i = 0; i < this.elements.length; i++) {
        Severity: Minor
        Found in frontend/source/js/data-capture/ajaxform.js - 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 smart_load_from_upload has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        def smart_load_from_upload(classname: str, f: UploadedFile) -> BasePriceList:
            '''
            Attempt to intelligently load the given Django UploadedFile,
            interpreting it as a price list for the given schedule class name.
        
        
        Severity: Minor
        Found in data_capture/schedules/registry.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 execute_from_command_line has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        def execute_from_command_line(argv):  # type: (List[str]) -> None
            '''
            This is like django.core.management.execute_from_command_line,
            but if the django package is unavailable, the script executes itself
            inside a docker container, where the django package is assumed
        Severity: Minor
        Found in docker_django_management.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 generate_column_index_map_mas has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        def generate_column_index_map_mas(heading_row, field_title_map):
            def find_col_mas(col_title):
                for idx, cell in enumerate(heading_row):
                    Is_Include = True
                    if str(col_title).lower() == 'price offered' and idx == 18:
        Severity: Minor
        Found in data_capture/schedules/spreadsheet_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

        File docker_django_management.py has 253 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        #!/usr/bin/env python
        
        '''
            Docker Django Management v0.1
        
        
        Severity: Minor
        Found in docker_django_management.py - About 2 hrs to fix

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

              if 'description' in context:
                  description = context['description']
              elif 'description' in kwargs:
                  description = kwargs['description']
              else:
          Severity: Major
          Found in data_explorer/templatetags/data_explorer_tags.py and 2 other locations - About 1 hr to fix
          data_explorer/templatetags/data_explorer_tags.py on lines 48..53
          data_explorer/templatetags/data_explorer_tags.py on lines 54..59

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

          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

          Function step_4 has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

          def step_4(request, step):
              gleaned_data = get_deserialized_gleaned_data(request)
          
              if gleaned_data is None:
                  return redirect('data_capture:step_3')
          Severity: Minor
          Found in data_capture/views/price_list_upload.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

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

              if 'title' in context:
                  title = context['title']
              elif 'title' in kwargs:
                  title = kwargs['title']
              else:
          Severity: Major
          Found in data_explorer/templatetags/data_explorer_tags.py and 2 other locations - About 1 hr to fix
          data_explorer/templatetags/data_explorer_tags.py on lines 40..45
          data_explorer/templatetags/data_explorer_tags.py on lines 54..59

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

          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

          Function step_3 has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

          def step_3(request, step, recorder):
              if get_step_form_from_session(2, request) is None:
                  return redirect('data_capture:step_2')
          
              session_pl = request.session[SESSION_KEY]
          Severity: Minor
          Found in data_capture/views/price_list_upload.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

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

              if 'meta_image' in context:
                  meta_image = context['meta_image']
              elif 'meta_image' in kwargs:
                  meta_image = kwargs['meta_image']
              else:
          Severity: Major
          Found in data_explorer/templatetags/data_explorer_tags.py and 2 other locations - About 1 hr to fix
          data_explorer/templatetags/data_explorer_tags.py on lines 40..45
          data_explorer/templatetags/data_explorer_tags.py on lines 48..53

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

          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

          Function checkInputs has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function checkInputs(window, inputs) {
            inputs.singleInputs.forEach((input) => {
              // prevent showing the HTML5 tooltip
              input.addEventListener('invalid', (e) => {
                e.preventDefault();
          Severity: Minor
          Found in frontend/source/js/data-capture/form-validation.js - About 1 hr to fix

            Function get_best_permutations has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

            def get_best_permutations(vocab, lexemes, min_count=1, min_length=4,
                                      max_permutations=8):
                def compare(a, b):
                    a_len = len(a)
                    b_len = len(b)
            Severity: Minor
            Found in data_capture/analysis/vocabulary.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 iter_api_pages has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

            def iter_api_pages(url, start_page=1, end_page=None):
                page = start_page
                while True:
                    if end_page is not None and page > end_page:
                        break
            Severity: Minor
            Found in api/management/commands/load_api_data.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 get_histogram has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

            def get_histogram(values: List[SupportsFloat], num_bins: int=10) -> List[dict]:
                """
                Get a histogram of a list of numeric values.
                Returns array of "bin" dicts with keys `count`, `max`, and `min`.
                """
            Severity: Minor
            Found in api/utils.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

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

                for field, title in field_title_map.items():
                    if isinstance(title, str):
                        title = ColumnTitle(title)
                    col_idx_map[field] = find_col(title)
            Severity: Major
            Found in data_capture/schedules/spreadsheet_utils.py and 1 other location - About 1 hr to fix
            data_capture/schedules/spreadsheet_utils.py on lines 80..83

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

            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

            Severity
            Category
            Status
            Source
            Language