wikimedia/mediawiki-core

View on GitHub
resources/src/mediawiki.util/util.js

Summary

Maintainability
F
5 days
Test Coverage

File util.js has 538 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

var config = require( './config.json' );
var portletLinkOptions = require( './portletLinkOptions.json' );
var infinityValues = require( './infinityValues.json' );
Severity: Major
Found in resources/src/mediawiki.util/util.js - About 1 day to fix

    util has 28 functions (exceeds 20 allowed). Consider refactoring.
    Open

    var util = {
    
        /**
         * Encode the string like PHP's rawurlencode.
         *
    Severity: Minor
    Found in resources/src/mediawiki.util/util.js - About 3 hrs to fix

      Function addPortletLink has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          addPortletLink: function ( portletId, href, text, id, tooltip, accesskey, nextnode ) {
              if ( !portletId ) {
                  // Avoid confusing id="undefined" lookup
                  return null;
              }
      Severity: Minor
      Found in resources/src/mediawiki.util/util.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 addPortletLink has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          addPortletLink: function ( portletId, href, text, id, tooltip, accesskey, nextnode ) {
              if ( !portletId ) {
                  // Avoid confusing id="undefined" lookup
                  return null;
              }
      Severity: Major
      Found in resources/src/mediawiki.util/util.js - About 2 hrs to fix

        Function parseImageUrl has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            parseImageUrl: function ( url ) {
                var name, decodedName, width, urlTemplate;
        
                // thumb.php-generated thumbnails
                // thumb.php?f=<name>&w[idth]=<width>[px]
        Severity: Minor
        Found in resources/src/mediawiki.util/util.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 prettifyIP has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            prettifyIP: function ( ip ) {
                ip = this.sanitizeIP( ip );
                if ( ip === null ) {
                    return null;
                }
        Severity: Minor
        Found in resources/src/mediawiki.util/util.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 parseImageUrl has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            parseImageUrl: function ( url ) {
                var name, decodedName, width, urlTemplate;
        
                // thumb.php-generated thumbnails
                // thumb.php?f=<name>&w[idth]=<width>[px]
        Severity: Minor
        Found in resources/src/mediawiki.util/util.js - About 1 hr to fix

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

              sanitizeIP: function ( ip ) {
                  if ( typeof ip !== 'string' ) {
                      return null;
                  }
                  ip = ip.trim();
          Severity: Minor
          Found in resources/src/mediawiki.util/util.js - 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 sanitizeIP has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              sanitizeIP: function ( ip ) {
                  if ( typeof ip !== 'string' ) {
                      return null;
                  }
                  ip = ip.trim();
          Severity: Minor
          Found in resources/src/mediawiki.util/util.js - About 1 hr to fix

            Function isIPv6Address has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                isIPv6Address: function ( address, allowBlock ) {
                    var block, RE_IPV6_ADD;
            
                    if ( typeof address !== 'string' ) {
                        return false;
            Severity: Minor
            Found in resources/src/mediawiki.util/util.js - About 1 hr to fix

              Function isTemporaryUser has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  isTemporaryUser: function ( username ) {
                      // Just return early if temporary accounts are disabled.
                      if ( !config.AutoCreateTempUser.enabled ) {
                          return false;
                      }
              Severity: Minor
              Found in resources/src/mediawiki.util/util.js - 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 prettifyIP has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  prettifyIP: function ( ip ) {
                      ip = this.sanitizeIP( ip );
                      if ( ip === null ) {
                          return null;
                      }
              Severity: Minor
              Found in resources/src/mediawiki.util/util.js - About 1 hr to fix

                Function addPortlet has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    addPortlet: function ( id, label, before ) {
                        const portlet = document.createElement( 'div' );
                        // These classes should be kept in sync with includes/skins/components/SkinComponentMenu.php.
                        // eslint-disable-next-line mediawiki/class-doc
                        portlet.classList.add( 'mw-portlet', 'mw-portlet-' + id, 'emptyPortlet',
                Severity: Minor
                Found in resources/src/mediawiki.util/util.js - About 1 hr to fix

                  Function isTemporaryUser has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      isTemporaryUser: function ( username ) {
                          // Just return early if temporary accounts are disabled.
                          if ( !config.AutoCreateTempUser.enabled ) {
                              return false;
                          }
                  Severity: Minor
                  Found in resources/src/mediawiki.util/util.js - About 1 hr to fix

                    Function getUrl has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        getUrl: function ( pageName, params ) {
                            var fragmentIdx, url, query, fragment,
                                title = typeof pageName === 'string' ? pageName : mw.config.get( 'wgPageName' );
                    
                            // Find any fragment
                    Severity: Minor
                    Found in resources/src/mediawiki.util/util.js - 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 addPortletLink has 7 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        addPortletLink: function ( portletId, href, text, id, tooltip, accesskey, nextnode ) {
                    Severity: Major
                    Found in resources/src/mediawiki.util/util.js - About 50 mins to fix

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

                          addPortlet: function ( id, label, before ) {
                              const portlet = document.createElement( 'div' );
                              // These classes should be kept in sync with includes/skins/components/SkinComponentMenu.php.
                              // eslint-disable-next-line mediawiki/class-doc
                              portlet.classList.add( 'mw-portlet', 'mw-portlet-' + id, 'emptyPortlet',
                      Severity: Minor
                      Found in resources/src/mediawiki.util/util.js - 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

                      Avoid too many return statements within this function.
                      Open

                              return ip.replace( /(^|:)0+(([0-9A-Fa-f]{1,4}))/g, '$1$2' );
                      Severity: Major
                      Found in resources/src/mediawiki.util/util.js - About 30 mins to fix

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

                                return function () {
                                    var context = this,
                                        args = arguments,
                                        later = function () {
                                            timeout = null;
                        Severity: Major
                        Found in resources/src/mediawiki.util/util.js and 1 other location - About 4 hrs to fix
                        resources/lib/ooui/oojs-ui-core.js on lines 245..261

                        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

                                return function () {
                                    // Check how long it's been since the last time the function was
                                    // called, and whether it's more or less than the requested throttle
                                    // period. If it's less, run the function immediately. If it's more,
                                    // set a timeout for the remaining time -- but don't replace an
                        Severity: Major
                        Found in resources/src/mediawiki.util/util.js and 1 other location - About 2 hrs to fix
                        resources/lib/ooui/oojs-ui-core.js on lines 299..313

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

                        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

                            return encodeURIComponent( String( str ) )
                                .replace( /!/g, '%21' )
                                .replace( /'/g, '%27' )
                                .replace( /\(/g, '%28' )
                                .replace( /\)/g, '%29' )
                        Severity: Major
                        Found in resources/src/mediawiki.util/util.js and 1 other location - About 1 hr to fix
                        resources/src/mediawiki.base/mediawiki.base.js on lines 274..280

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

                        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

                            showPortlet: function ( portletId ) {
                                var portlet = document.getElementById( portletId );
                                if ( portlet ) {
                                    portlet.classList.remove( 'emptyPortlet' );
                                }
                        Severity: Minor
                        Found in resources/src/mediawiki.util/util.js and 1 other location - About 45 mins to fix
                        resources/src/mediawiki.util/util.js on lines 458..463

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

                        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

                            hidePortlet: function ( portletId ) {
                                var portlet = document.getElementById( portletId );
                                if ( portlet ) {
                                    portlet.classList.add( 'emptyPortlet' );
                                }
                        Severity: Minor
                        Found in resources/src/mediawiki.util/util.js and 1 other location - About 45 mins to fix
                        resources/src/mediawiki.util/util.js on lines 481..486

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

                        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