wikimedia/mediawiki-extensions-UniversalLanguageSelector

View on GitHub

Showing 108 of 269 total issues

Function launchULS has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

function launchULS( $trigger, languagesObject, forCLS ) {
    var ulsConfig = {
        /**
         * Language selection handler
         *
Severity: Minor
Found in resources/js/ext.uls.launch.js - About 2 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 prepareMoreLanguages has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        prepareMoreLanguages: function () {
            var $languages, $moreLanguagesButton,
                displaySettings = this;

            $languages = this.$template.find( 'div.uls-ui-languages' );
Severity: Major
Found in resources/js/ext.uls.displaysettings.js - About 2 hrs to fix

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

        function initInterlanguageEntryPoint() {
            var $pLang = $( '#p-lang' );
    
            var $trigger = $( '<button>' )
                .addClass( 'uls-settings-trigger' )
    Severity: Minor
    Found in resources/js/ext.uls.interface.js - About 1 hr to fix

      Function init has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function init() {
              if (!isBrowser || api.initialized) {
                  return;
              }
              var testRange;
      Severity: Minor
      Found in lib/rangy/rangy-core.js - About 1 hr to fix

        Function renderInputmethodOption has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                renderInputmethodOption: function ( imeId, selected ) {
                    var $imeLabel, name, description, $helplink, inputmethod, $inputMethodItem;
        
                    if ( imeId !== 'system' && !$.ime.sources[ imeId ] ) {
                        // imeId not known for jquery.ime.
        Severity: Minor
        Found in resources/js/ext.uls.inputsettings.js - About 1 hr to fix

          Method search has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function search( $searchKey, $typos = 0, $userLanguage = null ) {
                  $results = [];
                  $searchKey = mb_strtolower( $searchKey );
          
                  if ( mb_strlen( $searchKey ) > 100 ) {
          Severity: Minor
          Found in data/LanguageNameSearch.php - About 1 hr to fix

            Function renderRegion has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    renderRegion: function ( $region, languages, itemsPerColumn, columnsPerRow ) {
                        var columnsClasses, i, lastItem, currentScript, nextScript, force,
                            languagesCount = languages.length,
                            items = [],
                            columns = [],
            Severity: Minor
            Found in lib/jquery.uls/src/jquery.uls.lcd.js - About 1 hr to fix

              Function addIme has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  mw.ime.addIme = function ( $input ) {
                      var imeselector;
              
                      $input.ime( {
                          languages: mw.ime.getIMELanguageList(),
              Severity: Minor
              Found in resources/js/ext.uls.ime.js - About 1 hr to fix

                Function addEmptyState has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    function addEmptyState( uls ) {
                        var $emptyStateContainer = $( '<section>' ).addClass( 'uls-empty-state' );
                
                        function openActionsMenuEventHandler( event ) {
                            event.stopPropagation();
                Severity: Minor
                Found in resources/js/ext.uls.interface.js - About 1 hr to fix

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

                      public static function getCodepoint( $str ) {
                          $values = [];
                          $lookingFor = 1;
                          $strLen = strlen( $str );
                          $number = 0;
                  Severity: Minor
                  Found in data/LanguageNameSearch.php - 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 setLanguage has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      mw.uls.setLanguage = function ( language ) {
                          var api = new mw.Api();
                  
                          function changeLanguageAnon() {
                              if ( mw.config.get( 'wgULSAnonCanChangeLanguage' ) ) {
                  Severity: Minor
                  Found in resources/js/ext.uls.common.js - About 1 hr to fix

                    Method onBeforePageDisplay has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function onBeforePageDisplay( $out, $skin ): void {
                            $unsupportedSkins = [ 'minerva', 'apioutput' ];
                            if ( in_array( $skin->getSkinName(), $unsupportedSkins, true ) ) {
                                return;
                            }
                    Severity: Minor
                    Found in includes/Hooks.php - About 1 hr to fix

                      Function apply has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              apply: function () {
                                  if ( !this.dirty ) {
                                      // No changes to save in this module.
                                      return;
                                  }
                      Severity: Minor
                      Found in resources/js/ext.uls.displaysettings.js - About 1 hr to fix

                        Function clickHandler has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                var clickHandler = function ( e ) {
                                    var languagesettings = $trigger.data( 'languagesettings' ),
                                        languageSettingsOptions;
                        
                                    if ( languagesettings ) {
                        Severity: Minor
                        Found in resources/js/ext.uls.interface.js - About 1 hr to fix

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

                              mw.webfonts.setup = function () {
                                  // Initialize webfonts
                                  var mediawikiFontRepository = $.webfonts.repository;
                          
                                  mediawikiFontRepository.base = mw.config.get( 'wgULSFontRepositoryBasePath' );
                          Severity: Minor
                          Found in resources/js/ext.uls.webfonts.js - About 1 hr to fix

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

                                    prepareFontSelector: function ( target ) {
                                        var language, fonts, $fontSelector, savedFont,
                                            $systemFont, $fontLabel, $fontsSection;
                            
                                        // Get the language code from the right property -
                            Severity: Minor
                            Found in resources/js/ext.uls.displaysettings.js - About 1 hr to fix

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

                                      keypress: function ( e ) {
                                          var suggestion, query;
                              
                                          switch ( e.keyCode ) {
                                              case 9: // Tab -> Autocomplete
                              Severity: Minor
                              Found in lib/jquery.uls/src/jquery.uls.languagefilter.js - About 1 hr to fix

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

                                        initModule: function ( moduleName, active ) {
                                            var $settingsTitle, $settingsText, $settingsLink,
                                                languageSettings = this,
                                                module = new $.fn.languagesettings.modules[ moduleName ]( languageSettings ),
                                                $settingsMenuItems = languageSettings.$window.find( '.settings-menu-items' );
                                Severity: Minor
                                Found in resources/js/ext.uls.languagesettings.js - About 1 hr to fix

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

                                          prepareLanguageList: function () {
                                              var languageCodeIndex,
                                                  $languageListWrapper,
                                                  $languageList,
                                                  languageList,
                                  Severity: Minor
                                  Found in lib/jquery.ime/jquery.ime.js - About 1 hr to fix

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

                                        ContentEditableEntry.prototype.replaceTextAtSelection = function (
                                            precedingCharCount,
                                            newText
                                        ) {
                                            var textNode, textOffset, newOffset, newRange,
                                    Severity: Minor
                                    Found in lib/jquery.ime/jquery.ime.js - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language