wikimedia/mediawiki-extensions-VisualEditor

View on GitHub
modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js

Summary

Maintainability
F
4 days
Test Coverage

File ve.init.mw.DesktopArticleTarget.init.js has 955 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * VisualEditor MediaWiki DesktopArticleTarget init.
 *
 * This file must remain as widely compatible as the base compatibility
 * for MediaWiki itself (see mediawiki/core:/resources/startup.js).
Severity: Major
Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 2 days to fix

    Function activateTarget has 83 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function activateTarget( mode, section, tPromise, modified ) {
            let dataPromise;
    
            updateTabs( true, mode, section === 'new' );
    
    
    Severity: Major
    Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 3 hrs to fix

      Function getTarget has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function getTarget( mode, section ) {
              if ( !targetPromise ) {
                  // The TargetLoader module is loaded in the bottom queue, so it should have been
                  // requested already but it might not have finished loading yet
                  targetPromise = mw.loader.using( 'ext.visualEditor.targetLoader' )
      Severity: Minor
      Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 1 hr to fix

        Function onEditTabClick has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                onEditTabClick: function ( mode, e ) {
                    if ( !init.isUnmodifiedLeftClick( e ) ) {
                        return;
                    }
                    if ( !active && mode === 'source' && !init.isWikitextAvailable ) {
        Severity: Minor
        Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 1 hr to fix

          Function setupEditLinks has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  setupEditLinks: function () {
                      // NWE
                      if ( init.isWikitextAvailable && !isOnlyTabVE() ) {
                          $(
                              // Edit section links, except VE ones when both editors visible
          Severity: Minor
          Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 1 hr to fix

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

                function scrollToSection( section ) {
                    if ( section === '0' || section === 'new' ) {
                        return;
                    }
            
            
            Severity: Minor
            Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                      if (
                          pageCanLoadEditor &&
                          showWikitextWelcome &&
                          // At least one editor is available (T201928)
                          ( init.isVisualAvailable || init.isWikitextAvailable || $( '#wpTextbox1' ).length ) &&
              Severity: Critical
              Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 1 hr to fix

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

                    function setEditorPreference( editor ) {
                        // If visual mode isn't available, don't set the editor preference as the
                        // user has expressed no choice by opening this editor. (T246259)
                        // Strictly speaking the same thing should happen if visual mode is
                        // available but source mode isn't, but that is never the case.
                Severity: Minor
                Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 1 hr to fix

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

                          onEditSectionLinkClick: function ( mode, e, section ) {
                              const link = $( e.target ).closest( 'a' )[ 0 ];
                              if ( !link || !link.href ) {
                                  // Not a real link, probably added by a gadget or another extension (T328094)
                                  return;
                  Severity: Minor
                  Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 1 hr to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                        if ( data && data.action === 'prefer-ve' ) {
                                                            location.href = veEditUrl;
                                                        } else if ( data && data.action === 'multi-tab' ) {
                                                            location.reload();
                                                        }
                    Severity: Major
                    Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                                  if ( section ) {
                                                      // switching from visual via the "add section" tab
                                                      target.switchToWikitextSection( section );
                                                  } else {
                                                      target.editSource();
                      Severity: Major
                      Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 45 mins to fix

                        Consider simplifying this complex logical expression.
                        Open

                                    if (
                                        // Modified click (e.g. ctrl+click)
                                        !init.isUnmodifiedLeftClick( e ) ||
                                        // Not an edit action
                                        !( linkUrl.searchParams.has( 'action' ) || linkUrl.searchParams.has( 'veaction' ) ) ||
                        Severity: Major
                        Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 40 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return null;
                          Severity: Major
                          Found in modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js - About 30 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status