wikimedia/mediawiki-extensions-Translate

View on GitHub
resources/js/ext.translate.special.pagemigration.js

Summary

Maintainability
D
2 days
Test Coverage

File ext.translate.special.pagemigration.js has 378 lines of code (exceeds 250 allowed). Consider refactoring.
Open

( function () {
    'use strict';
    var noOfSourceUnits, noOfTranslationUnits,
        pageName = '',
        langCode = '',
Severity: Minor
Found in resources/js/ext.translate.special.pagemigration.js - About 5 hrs to fix

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

        function importHandler( e ) {
            var $errorBox = $( '.mw-tpm-sp-error__message' ),
                $messageBox = $( '.mw-tpm-sp-instructions' );
    
            e.preventDefault();
    Severity: Minor
    Found in resources/js/ext.translate.special.pagemigration.js - About 1 hr to fix

      Function alignHeaders has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function alignHeaders( units, translationUnits ) {
              // The content does not have information about the page title. Add an empty string
              // at the beginning of the translationUnits array to match the length of units and
              // translationUnits.
              if ( units.length && units[ 0 ].identifier === 'Page_display_title' ) {
      Severity: Minor
      Found in resources/js/ext.translate.special.pagemigration.js - About 1 hr to fix

        Function getSourceUnits has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function getSourceUnits( page ) {
                var api = new mw.Api();
        
                return api.get( {
                    action: 'query',
        Severity: Minor
        Found in resources/js/ext.translate.special.pagemigration.js - About 1 hr to fix

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

              function getFuzzyTimestamp( pageTitle ) {
                  var api = new mw.Api();
          
                  // This api call returns the timestamp of FuzzyBot's edit
                  return api.get( {
          Severity: Minor
          Found in resources/js/ext.translate.special.pagemigration.js - About 1 hr to fix

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

                function createNewUnit( sourceText, targetText ) {
                    var $newUnit = $( '<div>' ).addClass( 'mw-tpm-sp-unit row' );
                    var $sourceUnit = $( '<textarea>' ).addClass( 'mw-tpm-sp-unit__source five columns' )
                        .prop( 'readonly', true ).attr( 'tabindex', '-1' ).val( sourceText );
                    var $target = $( '<div>' ).addClass( 'five columns' );
            Severity: Minor
            Found in resources/js/ext.translate.special.pagemigration.js - About 1 hr to fix

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

                  function saveHandler() {
                      var list = [];
              
                      $( '.mw-tpm-sp-error__message' ).addClass( 'hide' );
                      if ( noOfSourceUnits < noOfTranslationUnits ) {
              Severity: Minor
              Found in resources/js/ext.translate.special.pagemigration.js - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                                    if ( i !== 0 ) {
                                        translationUnits[ i - 1 ] += '\n' + mergeText;
                                    } else {
                                        matchText = mergeText + matchText;
                                    }
                Severity: Major
                Found in resources/js/ext.translate.special.pagemigration.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      while ( emptyCount !== 0 ) {
                                          mergeText += translationUnits.splice( i, 1 ).toString() + '\n';
                                          emptyCount += 1;
                                      }
                  Severity: Major
                  Found in resources/js/ext.translate.special.pagemigration.js - About 45 mins to fix

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

                                if ( obj === undefined || obj.missing === '' ) {
                                    $errorBox.text( mw.msg( 'pm-page-does-not-exist', pageTitle ) ).removeClass( 'hide' );
                                    return $.Deferred().reject();
                                }
                    Severity: Major
                    Found in resources/js/ext.translate.special.pagemigration.js and 2 other locations - About 40 mins to fix
                    resources/js/ext.translate.special.pagemigration.js on lines 59..62
                    resources/js/ext.translate.special.pagemigration.js on lines 103..114

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 49.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

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

                                if ( obj.revisions === undefined ) {
                                    $errorBox.text( mw.msg( 'pm-old-translations-missing', pageTitle ) ).removeClass( 'hide' );
                                    return $.Deferred().reject();
                                } else {
                                    // FB over here refers to FuzzyBot
                    Severity: Major
                    Found in resources/js/ext.translate.special.pagemigration.js and 2 other locations - About 40 mins to fix
                    resources/js/ext.translate.special.pagemigration.js on lines 59..62
                    resources/js/ext.translate.special.pagemigration.js on lines 97..100

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 49.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

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

                                if ( obj === undefined || obj.missing ) {
                                    $errorBox.text( mw.msg( 'pm-page-does-not-exist', pageTitle ) ).removeClass( 'hide' );
                                    return $.Deferred().reject();
                                }
                    Severity: Major
                    Found in resources/js/ext.translate.special.pagemigration.js and 2 other locations - About 40 mins to fix
                    resources/js/ext.translate.special.pagemigration.js on lines 97..100
                    resources/js/ext.translate.special.pagemigration.js on lines 103..114

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 49.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status