uktrade/directory-components

View on GitHub

Showing 44 of 44 total issues

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

  self.handleMenuItemKeyDownEvents = function(event) {
    if (event.key === "Escape" || event.key === "Esc") {
      self.closeMenu();
      event.preventDefault();
    }
directory_components/static/directory_components/js/dit.components.header.js on lines 210..227

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

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

  self.handleSubMenuItemKeyDownEvents = function(event) {
    if (event.key === "Escape" || event.key === "Esc") {
      self.closeMenu();
      event.preventDefault();
    }
directory_components/static/directory_components/js/dit.components.header.js on lines 191..208

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

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 header has 212 lines of code (exceeds 25 allowed). Consider refactoring.
Open

dit.components.header = new (function() {
  var self = this;

  self.MENU_BUTTON = "#mobile-menu-button";
  self.MOBILE_NAV = "#great-header-mobile-nav";

    Function lookup has 199 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    dit.components.lookup = (new function() {
    
      /* Performs a data lookup and displays multiple choice results
       * to populate the input value with user choice.
       *

      Function base has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
      Open

      dit.tagging.base = new function() {
          this.init = function(debug_mode) {
              $(document).ready(function() {
                  addTaggingForLinks();
                  addTaggingForVideos();
      Severity: Minor
      Found in directory_components/static/directory_components/js/dit.tagging.js - 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

      Function header has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

      dit.components.header = new (function() {
        var self = this;
      
        self.MENU_BUTTON = "#mobile-menu-button";
        self.MOBILE_NAV = "#great-header-mobile-nav";

      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 base has 147 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      dit.tagging.base = new function() {
          this.init = function(debug_mode) {
              $(document).ready(function() {
                  addTaggingForLinks();
                  addTaggingForVideos();
      Severity: Major
      Found in directory_components/static/directory_components/js/dit.tagging.js - About 5 hrs to fix

        Function cookieNotice has 147 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        dit.components.cookieNotice = function() {
          var COOKIE_NOTICE_ID = 'header-cookie-notice';
          var COOKIE_CLOSE_BUTTON_ID = 'dismiss-cookie-notice';
          var COOKIE_DOMAIN = $('#privacyCookieDomain').attr('value');
          var cookiePreferencesName = 'cookie_preferences_set';

          Function init has 145 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              this.init = function(debug_mode) {
                  $(document).ready(function() {
                      addTaggingForLinks();
                      addTaggingForVideos();
                      addTaggingForForms();
          Severity: Major
          Found in directory_components/static/directory_components/js/dit.tagging.js - About 5 hrs to fix

            Function countrySelector has 130 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            dit.components.countrySelector = (new function() {
              var self = this;
            
              var BANNER = '#country-selector-dialog';
              var BANNER_ID = 'country-selector-dialog';

              File views.py has 377 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import ast
              import re
              import lorem
              
              from unittest.mock import Mock
              Severity: Minor
              Found in demo/views.py - About 5 hrs to fix

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

                    if (arguments.length && activate) {
                      style = document.createElement('style');
                      style.setAttribute('type', 'text/css');
                      style.setAttribute('id', COUNTRY_SUBMIT_ID);
                      style.appendChild(document.createTextNode(rule));
                directory_components/static/directory_components/js/dit.components.languageSelectorDropdown.js on lines 38..47

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

                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

                    if (arguments.length && activate) {
                      style = document.createElement('style');
                      style.setAttribute('type', 'text/css');
                      style.setAttribute('id', LANGUAGE_SUBMIT);
                      style.appendChild(document.createTextNode(rule));
                directory_components/static/directory_components/js/dit.components.countrySelector.js on lines 153..162

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

                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 SelectiveLookup has 99 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  function SelectiveLookup($input, service, options) {
                    var instance = this;
                    var popupId = dit.utils.uniqueString();
                
                    // Configure options.

                  File directory_components.py has 320 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  from bs4 import BeautifulSoup
                  import re
                  
                  from collections import namedtuple
                  
                  
                  Severity: Minor
                  Found in directory_components/templatetags/directory_components.py - About 3 hrs to fix

                    Function multiselectAutocomplete has 85 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    dit.components.multiselectAutocomplete = (function() {
                      function MultiSelectAutocomplete(options) {
                    
                        var selectInputElement = options.selectInputElement;
                        var autocompleteId = selectInputElement.id + '_autocomplete';

                      Function MultiSelectAutocomplete has 80 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        function MultiSelectAutocomplete(options) {
                      
                          var selectInputElement = options.selectInputElement;
                          var autocompleteId = selectInputElement.id + '_autocomplete';
                      
                      

                        Function responsive has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        dit.responsive = dit.responsive || (new function () {
                        
                          // Constants
                          var RESET_EVENT = "dit:responsive:reset";
                          var RESPONSIVE_ELEMENT_ID = "dit-responsive-size";
                        Severity: Major
                        Found in directory_components/static/directory_components/js/dit.responsive.js - About 3 hrs to fix

                          Function cookieNotice has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                          Open

                          dit.components.cookieNotice = function() {
                            var COOKIE_NOTICE_ID = 'header-cookie-notice';
                            var COOKIE_CLOSE_BUTTON_ID = 'dismiss-cookie-notice';
                            var COOKIE_DOMAIN = $('#privacyCookieDomain').attr('value');
                            var cookiePreferencesName = 'cookie_preferences_set';

                          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 code has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                          Open

                          def code(parser, token):
                              # making the node verbatim
                              parameters = token.split_contents()
                              lang = parameters[1]
                              try:
                          Severity: Minor
                          Found in demo/templatetags/demo_tags.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

                          Severity
                          Category
                          Status
                          Source
                          Language