wikimedia/mediawiki-extensions-VisualEditor

View on GitHub
modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js

Summary

Maintainability
C
1 day
Test Coverage

Function getPreviewHtml has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

ve.dm.MWLanguageVariantNode.static.getPreviewHtml = function ( variantInfo, opts ) {
    if ( variantInfo.disabled ) {
        return variantInfo.disabled.t;
    } else if ( variantInfo.name ) {
        return ve.init.platform.getLanguageName( variantInfo.name.t.toLowerCase() );
Severity: Minor
Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.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 getPreviewHtml has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

ve.dm.MWLanguageVariantNode.static.getPreviewHtml = function ( variantInfo, opts ) {
    if ( variantInfo.disabled ) {
        return variantInfo.disabled.t;
    } else if ( variantInfo.name ) {
        return ve.init.platform.getLanguageName( variantInfo.name.t.toLowerCase() );
Severity: Minor
Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js - About 1 hr to fix

    Function matchLanguage has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    ve.dm.MWLanguageVariantNode.static.matchLanguage = function ( items ) {
        const userVariant = mw.config.get( 'wgUserVariant' ),
            fallbacks = mw.config.get( 'wgVisualEditor' ).pageVariantFallbacks,
            languageCodes =
                ( userVariant ? [ userVariant ] : [] ).concat( fallbacks || [] );
    Severity: Minor
    Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js - About 45 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 'oneway';
    Severity: Major
    Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return variantInfo.twoway[ languageIndex ].t;
      Severity: Major
      Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return '';
        Severity: Major
        Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return 'unknown'; // should never happen
          Severity: Major
          Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return variantInfo.oneway[ languageIndex ].t;
            Severity: Major
            Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js - About 30 mins to fix

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

              ve.dm.MWLanguageVariantNode.static.cloneElement = function () {
                  // Parent method
                  const clone = ve.dm.MWLanguageVariantNode.super.static.cloneElement.apply( this, arguments );
                  delete clone.attributes.originalVariantInfo;
                  return clone;
              Severity: Major
              Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js and 1 other location - About 2 hrs to fix
              modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js on lines 296..301

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

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

              ve.dm.MWLanguageVariantNode = function VeDmMWLanguageVariantNode() {
                  // Parent constructor
                  ve.dm.MWLanguageVariantNode.super.apply( this, arguments );
              
                  // Mixin constructors
              Severity: Major
              Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js and 11 other locations - About 2 hrs to fix
              modules/ve-mw/ce/nodes/ve.ce.MWAlienBlockExtensionNode.js on lines 20..26
              modules/ve-mw/ce/nodes/ve.ce.MWImageCaptionNode.js on lines 19..25
              modules/ve-mw/dm/nodes/ve.dm.MWAlienBlockExtensionNode.js on lines 20..26
              modules/ve-mw/dm/nodes/ve.dm.MWAlienInlineExtensionNode.js on lines 19..25
              modules/ve-mw/dm/nodes/ve.dm.MWGalleryNode.js on lines 18..24
              modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js on lines 18..24
              modules/ve-mw/dm/nodes/ve.dm.MWMagicLinkNode.js on lines 18..24
              modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js on lines 18..24
              modules/ve-mw/dm/nodes/ve.dm.MWTableNode.js on lines 19..25
              modules/ve-mw/ui/dialogs/ve.ui.MWExtensionDialog.js on lines 19..25
              modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js on lines 19..25

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

              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.dm.MWLanguageVariantNode.static.getHashObject = function ( dataElement ) {
                  return {
                      type: dataElement.type,
                      variantInfo: dataElement.attributes.variantInfo
                  };
              Severity: Minor
              Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js and 1 other location - About 55 mins to fix
              modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js on lines 69..74

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

              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.dm.MWLanguageVariantNode.prototype.getVariantInfo = function () {
                  return this.element.attributes.variantInfo;
              };
              Severity: Minor
              Found in modules/ve-mw/dm/nodes/ve.dm.MWLanguageVariantNode.js and 1 other location - About 40 mins to fix
              modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js on lines 100..102

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

              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