wikimedia/mediawiki-extensions-VisualEditor

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

Summary

Maintainability
F
1 wk
Test Coverage

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

/*!
 * VisualEditor MediaWiki Initialization DesktopArticleTarget class.
 *
 * @copyright See AUTHORS.txt
 * @license The MIT License (MIT); see LICENSE.txt
Severity: Major
Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 2 days to fix

    Function restorePage has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () {
        // Restore any previous redirectMsg/redirectsub
        this.setRealRedirectInterface();
        if ( this.$originalCategories ) {
            $( '#catlinks' ).replaceWith( this.$originalCategories );
    Severity: Minor
    Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 3 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 teardown has 59 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism ) {
        // Event tracking
        let abortType, abortedMode;
        if ( trackMechanism ) {
            if ( this.activating ) {
    Severity: Major
    Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 2 hrs to fix

      Function restorePage has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () {
          // Restore any previous redirectMsg/redirectsub
          this.setRealRedirectInterface();
          if ( this.$originalCategories ) {
              $( '#catlinks' ).replaceWith( this.$originalCategories );
      Severity: Minor
      Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

        Function VeInitMwDesktopArticleTarget has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config ) {
            // Parent constructor
            ve.init.mw.DesktopArticleTarget.super.call( this, config );
        
            // Parent constructor bound key event handlers, but we don't want them bound until
        Severity: Minor
        Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

          Function switchToFallbackWikitextEditor has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = function ( modified ) {
              const oldId = mw.config.get( 'wgRevisionId' ) || $( 'input[name=parentRevId]' ).val();
              const prefPromise = mw.libs.ve.setEditorPreference( 'wikitext' );
          
              if ( !modified ) {
          Severity: Minor
          Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

            Function onWindowPopState has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

            ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
                if ( !this.verifyPopState( e.state ) ) {
                    // Ignore popstate events fired for states not created by us
                    // This also filters out the initial fire in Chrome (T59901).
                    return;
            Severity: Minor
            Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.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 onWindowPopState has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
                if ( !this.verifyPopState( e.state ) ) {
                    // Ignore popstate events fired for states not created by us
                    // This also filters out the initial fire in Chrome (T59901).
                    return;
            Severity: Minor
            Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

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

              ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism ) {
                  // Event tracking
                  let abortType, abortedMode;
                  if ( trackMechanism ) {
                      if ( this.activating ) {
              Severity: Minor
              Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.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 loadFail has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( code, errorDetails ) {
                  // Parent method
                  ve.init.mw.DesktopArticleTarget.super.prototype.loadFail.apply( this, arguments );
              
                  if ( this.wikitextFallbackLoading ) {
              Severity: Minor
              Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

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

                ve.init.mw.DesktopArticleTarget.prototype.setupNewSection = function ( surface ) {
                    if ( surface.getMode() === 'source' && this.section === 'new' ) {
                        if ( !this.sectionTitle ) {
                            this.sectionTitle = new OO.ui.TextInputWidget( {
                                $element: $( '<h2>' ),
                Severity: Minor
                Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.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 updateHistoryState has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                ve.init.mw.DesktopArticleTarget.prototype.updateHistoryState = function () {
                    const veaction = this.getDefaultMode() === 'visual' ? 'edit' : 'editsource',
                        section = this.section;
                
                    // Push veaction=edit(source) url in history (if not already present).
                Severity: Minor
                Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.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 updateHistoryState has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                ve.init.mw.DesktopArticleTarget.prototype.updateHistoryState = function () {
                    const veaction = this.getDefaultMode() === 'visual' ? 'edit' : 'editsource',
                        section = this.section;
                
                    // Push veaction=edit(source) url in history (if not already present).
                Severity: Minor
                Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

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

                  ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () {
                      if ( !this.activating ) {
                          // Activation was aborted before we got here. Do nothing
                          // TODO are there things we need to clean up?
                          return;
                  Severity: Minor
                  Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

                    Function setupToolbar has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    ve.init.mw.DesktopArticleTarget.prototype.setupToolbar = function ( surface ) {
                        const mode = surface.getMode(),
                            wasSetup = !!this.toolbar;
                    
                        ve.track( 'trace.setupToolbar.enter', { mode: mode } );
                    Severity: Minor
                    Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

                      Function maybeShowWelcomeDialog has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      ve.init.mw.DesktopArticleTarget.prototype.maybeShowWelcomeDialog = function () {
                          const editorMode = this.getDefaultMode(),
                              windowManager = this.getSurface().dialogs;
                      
                          this.welcomeDialogPromise = ve.createDeferred();
                      Severity: Minor
                      Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js - About 1 hr to fix

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

                        ve.init.mw.DesktopArticleTarget.prototype.maybeShowMetaDialog = function () {
                            if ( this.welcomeDialogPromise ) {
                                // Pop out the notices when the welcome dialog is closed
                                this.welcomeDialogPromise
                                    .always( () => {
                        Severity: Minor
                        Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.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

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

                        ve.init.mw.DesktopArticleTarget.prototype.afterActivate = function () {
                            $( 'html' ).removeClass( 've-activating' ).addClass( 've-active' );
                        
                            // Disable TemplateStyles in the original content
                            // (We do this here because toggling 've-active' class above hides it)
                        Severity: Minor
                        Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.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

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

                        ve.init.mw.DesktopArticleTarget.prototype.setupSkinTabs = function () {
                            if ( this.isViewPage ) {
                                const namespaceNumber = mw.config.get( 'wgNamespaceNumber' );
                                const namespaceName = mw.config.get( 'wgCanonicalNamespace' );
                                const isTalkNamespace = mw.Title.isTalkNamespace( namespaceNumber );
                        Severity: Minor
                        Found in modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.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 2 locations. Consider refactoring.
                        Open

                        ve.init.mw.DesktopArticleTarget.prototype.switchToWikitextEditor = function () {
                            // Parent method
                            ve.init.mw.DesktopArticleTarget.super.prototype.switchToWikitextEditor.apply( this, arguments );
                        
                            if ( this.isModeAvailable( 'source' ) ) {
                        modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js on lines 1381..1388

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

                        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

                        ve.init.mw.DesktopArticleTarget.prototype.switchToVisualEditor = function () {
                            // Parent method
                            ve.init.mw.DesktopArticleTarget.super.prototype.switchToVisualEditor.apply( this, arguments );
                        
                            if ( this.isModeAvailable( 'visual' ) ) {
                        modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js on lines 1393..1400

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

                        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

                        ve.init.mw.DesktopArticleTarget.prototype.unbindHandlers = function () {
                            ve.init.mw.DesktopArticleTarget.super.prototype.unbindHandlers.call( this );
                            if ( this.onWatchToggleHandler ) {
                                mw.hook( 'wikipage.watchlistChange' ).remove( this.onWatchToggleHandler );
                            }
                        modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js on lines 363..368

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

                        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

                        ve.init.mw.DesktopArticleTarget.prototype.bindHandlers = function () {
                            ve.init.mw.DesktopArticleTarget.super.prototype.bindHandlers.call( this );
                            if ( this.onWatchToggleHandler ) {
                                mw.hook( 'wikipage.watchlistChange' ).add( this.onWatchToggleHandler );
                            }
                        modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js on lines 373..378

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

                        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

                        ve.init.mw.DesktopArticleTarget.prototype.setupToolbarSaveButton = function () {
                            this.toolbarSaveButton = this.toolbar.getToolGroupByName( 'save' ).items[ 0 ];
                        };
                        modules/ve-mw/init/targets/ve.init.mw.MobileArticleTarget.js on lines 490..492

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

                        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

                                case 'mwCategory': {
                                    const metaList = this.getSurface().getModel().getDocument().getMetaList();
                                    this.rebuildCategories( metaList.getItemsInGroup( 'mwCategory' ) );
                                    break;
                                }
                        modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js on lines 754..758

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

                        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

                                case 'mwCategory': {
                                    const metaList = this.getSurface().getModel().getDocument().getMetaList();
                                    this.rebuildCategories( metaList.getItemsInGroup( 'mwCategory' ) );
                                    break;
                                }
                        modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js on lines 774..778

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

                        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