wikimedia/mediawiki-core

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

Summary

Maintainability
F
1 wk
Test Coverage

File mediawiki.jqueryMsg.js has 852 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
* Experimental advanced wikitext parser-emitter.
* See: https://www.mediawiki.org/wiki/Extension:UploadWizard/MessageParser for docs
*
* @author neilk@wikimedia.org
Severity: Major
Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 2 days to fix

    Function wikiTextToAst has 398 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        wikiTextToAst: function ( input ) {
            var pos,
                regularLiteral, regularLiteralWithoutBar, regularLiteralWithoutSpace, regularLiteralWithSquareBrackets,
                doubleQuote, singleQuote, backslash, anyCharacter, asciiAlphabetLiteral,
                escapedOrLiteralWithoutSpace, escapedOrLiteralWithoutBar, escapedOrRegularLiteral,
    Severity: Major
    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 1 day to fix

      Function wikiTextToAst has a Cognitive Complexity of 74 (exceeds 5 allowed). Consider refactoring.
      Open

          wikiTextToAst: function ( input ) {
              var pos,
                  regularLiteral, regularLiteralWithoutBar, regularLiteralWithoutSpace, regularLiteralWithSquareBrackets,
                  doubleQuote, singleQuote, backslash, anyCharacter, asciiAlphabetLiteral,
                  escapedOrLiteralWithoutSpace, escapedOrLiteralWithoutBar, escapedOrRegularLiteral,
      Severity: Minor
      Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 1 day 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 extlink has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          extlink: function ( nodes ) {
              var $el,
                  arg = nodes[ 0 ],
                  contents = nodes[ 1 ];
              if ( arg instanceof $ && !arg.hasClass( 'mediaWiki_htmlEmitter' ) ) {
      Severity: Minor
      Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.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 replace has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          replace: function ( nodes, replacements ) {
              var index = parseInt( nodes[ 0 ], 10 );
      
              if ( index < replacements.length ) {
                  if ( typeof replacements[ index ] === 'object' ) {
      Severity: Minor
      Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.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 extlink has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          extlink: function ( nodes ) {
              var $el,
                  arg = nodes[ 0 ],
                  contents = nodes[ 1 ];
              if ( arg instanceof $ && !arg.hasClass( 'mediaWiki_htmlEmitter' ) ) {
      Severity: Minor
      Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 1 hr to fix

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

                function html() {
                    // Break into three sequence calls.  That should allow accurate reconstruction of the original HTML, and requiring an exact tag name match.
                    // 1. open through closeHtmlTag
                    // 2. expression
                    // 3. openHtmlEnd through close
        Severity: Minor
        Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 1 hr to fix

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

              plural: function ( nodes ) {
                  var firstChild, firstChildText, explicitPluralFormNumber, formIndex, form,
                      explicitPluralForms = {};
          
                  var count = parseFloat( this.language.convertNumber( textify( nodes[ 0 ] ), true ) );
          Severity: Minor
          Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.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 HtmlEmitter has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function HtmlEmitter( language, magic ) {
              var jmsg = this;
              this.language = language;
              Object.keys( magic || {} ).forEach( function ( key ) {
                  var val = magic[ key ];
          Severity: Minor
          Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 1 hr to fix

            Function plural has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                plural: function ( nodes ) {
                    var firstChild, firstChildText, explicitPluralFormNumber, formIndex, form,
                        explicitPluralForms = {};
            
                    var count = parseFloat( this.language.convertNumber( textify( nodes[ 0 ] ), true ) );
            Severity: Minor
            Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 1 hr to fix

              Function replace has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  replace: function ( nodes, replacements ) {
                      var index = parseInt( nodes[ 0 ], 10 );
              
                      if ( index < replacements.length ) {
                          if ( typeof replacements[ index ] === 'object' ) {
              Severity: Minor
              Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 1 hr to fix

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

                function appendWithoutParsing( $parent, children ) {
                    var i, len;
                
                    if ( !Array.isArray( children ) ) {
                        children = [ children ];
                Severity: Minor
                Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.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 replacements[ index ];
                Severity: Major
                Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return '$' + ( index + 1 );
                  Severity: Major
                  Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 30 mins to fix

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

                    function HtmlEmitter( language, magic ) {
                        var jmsg = this;
                        this.language = language;
                        Object.keys( magic || {} ).forEach( function ( key ) {
                            var val = magic[ key ];
                    Severity: Minor
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

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

                            function makeRegexParser( regex ) {
                                return function () {
                                    var matches = input.slice( pos ).match( regex );
                                    if ( matches === null ) {
                                        return null;
                    Severity: Major
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 2 other locations - About 1 hr to fix
                    resources/lib/CLDRPluralRuleParser/CLDRPluralRuleParser.js on lines 186..198
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 135..147

                    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

                            function makeStringParser( s ) {
                                var len = s.length;
                                return function () {
                                    var result = null;
                                    if ( input.slice( pos, pos + len ) === s ) {
                    Severity: Major
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 1 other location - About 1 hr to fix
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 120..133

                    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

                                function () {
                                    var result = sequence( [
                                        templateName,
                                        nOrMore( 0, templateParam )
                                    ] );
                    Severity: Major
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 1 other location - About 1 hr to fix
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 259..267

                    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

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

                            function replacement() {
                                var result = sequence( [
                                    dollar,
                                    digits
                                ] );
                    Severity: Major
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 1 other location - About 1 hr to fix
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 199..207

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

                    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 ( res === null || pos !== input.length ) {
                                throw new Error( 'Parse error at position ' + pos.toString() + ' in input: ' + input );
                            }
                    Severity: Minor
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 1 other location - About 50 mins to fix
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 300..302

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

                    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 4 locations. Consider refactoring.
                    Open

                            function templateWithReplacement() {
                                var result = sequence( [
                                    templateName,
                                    colon,
                                    replacement
                    Severity: Major
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 3 other locations - About 35 mins to fix
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 234..238
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 240..244
                    resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js on lines 613..620

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

                    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 4 locations. Consider refactoring.
                    Open

                            function templateWithOutReplacement() {
                                var result = sequence( [
                                    templateName,
                                    colon,
                                    paramExpression
                    Severity: Major
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 3 other locations - About 35 mins to fix
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 234..238
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 240..244
                    resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js on lines 605..612

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

                    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

                            function curlyBraceTransformExpressionLiteral() {
                                var result = nOrMore( 1, regularLiteralWithSquareBrackets )();
                                return result === null ? null : result.join( '' );
                            }
                    Severity: Minor
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 1 other location - About 35 mins to fix
                    resources/lib/vue/vue.global.js on lines 6688..6710

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

                    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

                            function start( rootExpression ) {
                                var result = nOrMore( 0, rootExpression )();
                                if ( result === null ) {
                                    return null;
                                }
                    Severity: Minor
                    Found in resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js and 1 other location - About 35 mins to fix
                    resources/lib/jquery.i18n/src/jquery.i18n.parser.js on lines 282..290

                    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

                    There are no issues that match your filters.

                    Category
                    Status