wikimedia/mediawiki-core

View on GitHub
resources/src/jquery/jquery.suggestions.js

Summary

Maintainability
F
6 days
Test Coverage

File jquery.suggestions.js has 479 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * This plugin provides a generic way to add suggestions to a text box.
 * Provided by the jquery.suggestions ResourceLoader module.
 *
 * Set options:
Severity: Minor
Found in resources/src/jquery/jquery.suggestions.js - About 7 hrs to fix

    Function suggestions has 142 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        $.fn.suggestions = function () {
            // Multi-context fields
            var args = arguments;
    
            $( this ).each( function () {
    Severity: Major
    Found in resources/src/jquery/jquery.suggestions.js - About 5 hrs to fix

      Function configure has 140 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function configure( context, property, value ) {
      
              // Validate creation using fallback values
              switch ( property ) {
                  case 'fetch':
      Severity: Major
      Found in resources/src/jquery/jquery.suggestions.js - About 5 hrs to fix

        Function update has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function update( context, delayed ) {
                function maybeFetch() {
                    if ( typeof context.config.update.before === 'function' ) {
                        context.config.update.before.call( context.data.$textbox );
                    }
        Severity: Major
        Found in resources/src/jquery/jquery.suggestions.js - About 2 hrs to fix

          Function keypress has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function keypress( e, context, key ) {
                  // eslint-disable-next-line no-jquery/no-sizzle
                  var wasVisible = context.data.$container.is( ':visible' ),
                      preventDefault = false;
          
          
          Severity: Major
          Found in resources/src/jquery/jquery.suggestions.js - About 2 hrs to fix

            Function highlight has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function highlight( context, $result, updateTextbox ) {
                    var $selected = context.data.$container.find( '.suggestions-result-current' );
                    if ( !$result.get || $selected.get( 0 ) !== $result.get( 0 ) ) {
                        if ( $result === 'prev' ) {
                            // eslint-disable-next-line no-jquery/no-class-state
            Severity: Major
            Found in resources/src/jquery/jquery.suggestions.js - About 2 hrs to fix

              Function maybeFetch has 48 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      function maybeFetch() {
                          if ( typeof context.config.update.before === 'function' ) {
                              context.config.update.before.call( context.data.$textbox );
                          }
              
              
              Severity: Minor
              Found in resources/src/jquery/jquery.suggestions.js - About 1 hr to fix

                Function expandFrom has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                                        context.config.expandFrom = ( function ( expandFrom ) {
                                            var regionWidth, docWidth, regionCenter, docCenter,
                                                isRTL = $( document.documentElement ).css( 'direction' ) === 'rtl',
                                                $region = context.config.$region;
                
                
                Severity: Minor
                Found in resources/src/jquery/jquery.suggestions.js - About 1 hr to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if ( $result.length === 0 && context.data.$container.find( '.suggestions-special' ).html() !== '' ) {
                                          // No suggestion exists, go to the special one directly
                                          $result = context.data.$container.find( '.suggestions-special' );
                                      }
                  Severity: Major
                  Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if ( context.data.$container.find( '.suggestions-special' ).html() !== '' ) {
                                                $result = context.data.$container.find( '.suggestions-special' );
                                            } else {
                                                $result = context.data.$container.find( '.suggestions-results .suggestions-result' ).last();
                                            }
                    Severity: Major
                    Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                                      if ( $region.data( 'searchsuggest-expand-dir' ) ) {
                                                          // If the markup explicitly contains a direction, use it.
                                                          expandFrom = $region.data( 'searchsuggest-expand-dir' );
                                                      } else {
                                                          regionWidth = $region.outerWidth();
                      Severity: Major
                      Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                    if ( childrenWidth > $result.width() && childrenWidth > expWidth ) {
                                                        // factor in any padding, margin, or border space on the parent
                                                        expWidth = childrenWidth + ( context.data.$container.width() - $result.width() );
                                                    }
                        Severity: Major
                        Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                          if ( $el.css( 'position' ) === 'fixed' ) {
                                                              return true;
                                                          }
                          Severity: Major
                          Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                if ( !( $result.length && $result.hasClass( 'suggestions-result' ) ) ) {
                                                    // there is something in the DOM between selected element and the wrapper, bypass it
                                                    $result = $selected.parents( '.suggestions-results > *' ).next().find( '.suggestions-result' ).eq( 0 );
                                                }
                            Severity: Major
                            Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                  if ( $selected.hasClass( 'suggestions-special' ) ) {
                                                      $result = $( [] );
                                                  } else if (
                                                      $result.length === 0 &&
                                                      context.data.$container.find( '.suggestions-special' ).html() !== ''
                              Severity: Major
                              Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                            if ( context.config.highlightInput ) {
                                                                $result.highlightText( context.data.prevText, { method: 'prefixPlusComboHighlight' } );
                                                            }
                                Severity: Major
                                Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                              if ( typeof context.config.result.render === 'function' ) {
                                                                  context.config.result.render.call( $result, context.config.suggestions[ i ], context );
                                                              } else {
                                                                  $result.text( text );
                                                              }
                                  Severity: Major
                                  Found in resources/src/jquery/jquery.suggestions.js - About 45 mins to fix

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

                                                    } else if ( $selected.is( '.suggestions-special' ) ) {
                                                        if ( typeof context.config.special.select === 'function' ) {
                                                            // Allow the callback to decide whether to prevent default or not
                                                            if ( context.config.special.select.call( $selected, context.data.$textbox, 'keyboard' ) === true ) {
                                                                preventDefault = false;
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 2 hrs to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 558..565

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

                                    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

                                                    } else {
                                                        if ( typeof context.config.result.select === 'function' ) {
                                                            // Allow the callback to decide whether to prevent default or not
                                                            if ( context.config.result.select.call( $selected, context.data.$textbox, 'keyboard' ) === true ) {
                                                                preventDefault = false;
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 2 hrs to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 551..558

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

                                    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 ( !( e.which !== 1 || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) ) {
                                                                        // This will hide the link we're just clicking on, which causes problems
                                                                        // when done synchronously in at least Firefox 3.6 (T64858).
                                                                        setTimeout( function () {
                                                                            hide( context );
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 2 hrs to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 703..709

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

                                    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 ( !( e.which !== 1 || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) ) {
                                                                        // This will hide the link we're just clicking on, which causes problems
                                                                        // when done synchronously in at least Firefox 3.6 (T64858).
                                                                        setTimeout( function () {
                                                                            hide( context );
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 2 hrs to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 671..677

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

                                    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

                                                            $( '<div>' ).addClass( 'suggestions-results' )
                                                                // Can't use click() because the container div is hidden when the
                                                                // textbox loses focus. Instead, listen for a mousedown followed
                                                                // by a mouseup on the same div.
                                                                .on( 'mousedown', function ( e ) {
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 1 hr to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 684..713

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

                                    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

                                                            $( '<div>' ).addClass( 'suggestions-special' )
                                                                // Can't use click() because the container div is hidden when the
                                                                // textbox loses focus. Instead, listen for a mousedown followed
                                                                // by a mouseup on the same div.
                                                                .on( 'mousedown', function ( e ) {
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 1 hr to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 651..681

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

                                    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 ( $result.length === 0 && context.data.$container.find( '.suggestions-special' ).html() !== '' ) {
                                                            // No suggestion exists, go to the special one directly
                                                            $result = context.data.$container.find( '.suggestions-special' );
                                                        }
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 1 hr to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 277..283

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

                                    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

                                                        } else if (
                                                            $result.length === 0 &&
                                                            context.data.$container.find( '.suggestions-special' ).html() !== ''
                                                        ) {
                                                            // We were at the last item, jump to the specials!
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 1 hr to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 262..265

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

                                    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 ( typeof context.config.special.select === 'function' ) {
                                                                        context.config.special.select.call( $special, context.data.$textbox, 'mouse' );
                                                                    }
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 1 hr to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 667..669

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

                                    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 ( typeof context.config.result.select === 'function' ) {
                                                                        context.config.result.select.call( $result, context.data.$textbox, 'mouse' );
                                                                    }
                                    Severity: Major
                                    Found in resources/src/jquery/jquery.suggestions.js and 1 other location - About 1 hr to fix
                                    resources/src/jquery/jquery.suggestions.js on lines 699..701

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

                                    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