mambax7/alumni-26x

View on GitHub
media/jquery/tablesorter-master/js/jquery.tablesorter.js

Summary

Maintainability
F
7 mos
Test Coverage

File jquery.tablesorter.js has 2314 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*! TableSorter (FORK) v2.29.2 *//*
* Client-side table sorting with ease!
* @requires jQuery v1.2.6+
*
* Copyright (c) 2007 Christian Bach
Severity: Major
Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 6 days to fix

    Function buildCache has 128 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            buildCache : function( c, callback, $tbodies ) {
                var cache, val, txt, rowIndex, colIndex, tbodyIndex, $tbody, $row,
                    cols, $cells, cell, cacheTime, totalRows, rowData, prevRowData,
                    colMax, span, cacheIndex, hasParser, max, len, index,
                    table = c.table,
    Severity: Major
    Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 5 hrs to fix

      Function initSort has 113 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              initSort : function( c, cell, event ) {
                  if ( c.table.isUpdating ) {
                      // let any updates complete before initializing a sort
                      return setTimeout( function(){
                          ts.initSort( c, cell, event );
      Severity: Major
      Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 4 hrs to fix

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

                setup : function( table, c ) {
                    // if no thead or tbody, or tablesorter is already present, quit
                    if ( !table || !table.tHead || table.tBodies.length === 0 || table.hasInitialized === true ) {
                        if ( c.debug ) {
                            if ( table.hasInitialized ) {
        Severity: Major
        Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 4 hrs to fix

          Function bindMethods has 87 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  bindMethods : function( c ) {
                      var $table = c.$table,
                          namespace = c.namespace,
                          events = ( 'sortReset update updateRows updateAll updateHeaders addRows updateCell updateComplete ' +
                              'sorton appendCache updateCache applyWidgetId applyWidgets refreshWidgets destroy mouseup ' +
          Severity: Major
          Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 3 hrs to fix

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

                    setupParsers : function( c, $tbodies ) {
                        var rows, list, span, max, colIndex, indx, header, configHeaders,
                            noParser, parser, extractor, time, tbody, len,
                            table = c.table,
                            tbodyIndex = 0,
            Severity: Major
            Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 3 hrs to fix

              Function buildHeaders has 82 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      buildHeaders : function( c ) {
                          var $temp, icon, timer, indx;
                          c.headerList = [];
                          c.headerContent = [];
                          c.sortVars = [];
              Severity: Major
              Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 3 hrs to fix

                Function setHeadersCss has 70 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        setHeadersCss : function( c ) {
                            var indx, column,
                                list = c.sortList,
                                len = list.length,
                                none = ts.css.sortNone + ' ' + c.cssNone,
                Severity: Major
                Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 2 hrs to fix

                  Function bindEvents has 64 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          bindEvents : function( table, $headers, core ) {
                              table = $( table )[ 0 ];
                              var tmp,
                                  c = table.config,
                                  namespace = c.namespace,
                  Severity: Major
                  Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 2 hrs to fix

                    Function multisort has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            multisort : function( c ) { /*jshint loopfunc:true */
                                var tbodyIndex, sortTime, colMax, rows, tmp,
                                    table = c.table,
                                    sorter = [],
                                    dir = 0,
                    Severity: Major
                    Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 2 hrs to fix

                      Function addRows has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              addRows : function( c, $row, resort, callback ) {
                                  var txt, val, tbodyIndex, rowIndex, rows, cellIndex, len, order,
                                      cacheIndex, rowData, cells, cell, span,
                                      // allow passing a row string if only one non-info tbody exists in the table
                                      valid = typeof $row === 'string' && c.$tbodies.length === 1 && /<tr/.test( $row || '' ),
                      Severity: Major
                      Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 2 hrs to fix

                        Function applyWidget has 55 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                applyWidget : function( table, init, callback ) {
                                    table = $( table )[ 0 ]; // in case this is called externally
                                    var indx, len, names, widget, time,
                                        c = table.config,
                                        widgets = [];
                        Severity: Major
                        Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 2 hrs to fix

                          Function updateCell has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                                  updateCell : function( c, cell, resort, callback ) {
                                      // updateCell for child rows is a mess - we'll ignore them for now
                                      // eventually I'll break out the "update" row cache code to make everything consistent
                                      if ( $( cell ).closest( 'tr' ).hasClass( c.cssChildRow ) ) {
                                          console.warn('Tablesorter Warning! "updateCell" for child row content has been disabled, use "update" instead');
                          Severity: Major
                          Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 2 hrs to fix

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

                                        c.$headers = $( $.map( c.$table.find( c.selectorHeaders ), function( elem, index ) {
                                            var configHeaders, header, column, template, tmp,
                                                $elem = $( elem );
                                            // ignore cell (don't add it to c.$headers) if row has ignoreRow class
                                            if ( ts.getClosest( $elem, 'tr' ).hasClass( c.cssIgnoreRow ) ) { return; }
                            Severity: Minor
                            Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

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

                                      updateHeaderSortCount : function( c, list ) {
                                          var col, dir, group, indx, primary, temp, val, order,
                                              sortList = list || c.sortList,
                                              len = sortList.length;
                                          c.sortList = [];
                              Severity: Minor
                              Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

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

                                        getColumnText : function( table, column, callback, rowFilter ) {
                                            table = $( table )[0];
                                            var tbodyIndex, rowIndex, cache, row, tbodyLen, rowLen, raw, parsed, $cell, result,
                                                hasCallback = typeof callback === 'function',
                                                allColumns = column === 'all',
                                Severity: Minor
                                Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

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

                                          destroy : function( table, removeClasses, callback ) {
                                              table = $( table )[ 0 ];
                                              if ( !table.hasInitialized ) { return; }
                                              // remove all widgets
                                              ts.removeWidget( table, true, false );
                                  Severity: Minor
                                  Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

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

                                            appendCache : function( c, init ) {
                                                var parsed, totalRows, $tbody, $curTbody, rowIndex, tbodyIndex, appendTime,
                                                    table = c.table,
                                                    wo = c.widgetOptions,
                                                    $tbodies = c.$tbodies,
                                    Severity: Minor
                                    Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

                                      Function applyWidgetId has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                              applyWidgetId : function( table, id, init ) {
                                                  table = $(table)[0];
                                                  var applied, time, name,
                                                      c = table.config,
                                                      wo = c.widgetOptions,
                                      Severity: Minor
                                      Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

                                        Function computeColumnIndex has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                                computeColumnIndex : function( $rows, c ) {
                                                    var i, j, k, l, cell, cells, rowIndex, rowSpan, colSpan, firstAvailCol,
                                                        // total columns has been calculated, use it to set the matrixrow
                                                        columns = c && c.columns || 0,
                                                        matrix = [],
                                        Severity: Minor
                                        Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

                                          Function removeWidget has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                          Open

                                                  removeWidget : function( table, name, refreshing ) {
                                                      table = $( table )[ 0 ];
                                                      var index, widget, indx, len,
                                                          c = table.config;
                                                      // if name === true, add all widgets from $.tablesorter.widgets
                                          Severity: Minor
                                          Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

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

                                                    detectParserForColumn : function( c, rows, rowIndex, cellIndex ) {
                                                        var cur, $node, row,
                                                            indx = ts.parsers.length,
                                                            node = false,
                                                            nodeValue = '',
                                            Severity: Minor
                                            Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

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

                                                      sortNatural : function( a, b ) {
                                                          if ( a === b ) { return 0; }
                                                          a = a.toString();
                                                          b = b.toString();
                                                          var aNum, bNum, aFloat, bFloat, indx, max,
                                              Severity: Minor
                                              Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

                                                Consider simplifying this complex logical expression.
                                                Open

                                                                if ( ( ( e.which || e.button ) !== 1 && !type.match( ' ' + c.pointerClick + ' | sort | keyup ' ) ) ||
                                                                    // allow pressing enter
                                                                    ( type === ' keyup ' && e.which !== ts.keyCodes.enter ) ||
                                                                    // allow triggering a click event (e.which is undefined) & ignore physical clicks
                                                                    ( type.match( ' ' + c.pointerClick + ' ' ) && typeof e.which !== 'undefined' ) ) {
                                                Severity: Major
                                                Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 1 hr to fix

                                                  Avoid deeply nested control flow statements.
                                                  Open

                                                                              if ( cell ) {
                                                                                  prevRowData.child[ len ][ colIndex ] = ts.getParsedText( c, cell, colIndex );
                                                                                  span = $cells[ colIndex ].colSpan - 1;
                                                                                  if ( span > 0 ) {
                                                                                      cacheIndex += span;
                                                  Severity: Major
                                                  Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                    Function sortNumericDesc has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                                    Open

                                                            sortNumericDesc : function( a, b, num, max, col, c ) {
                                                    Severity: Minor
                                                    Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                      Avoid deeply nested control flow statements.
                                                      Open

                                                                                  if ( c.debug ) {
                                                                                      debug[ '(' + colIndex + ') ' + header.text() ] = {
                                                                                          parser : parser.id,
                                                                                          extractor : extractor ? extractor.id : 'none',
                                                                                          string : c.strings[ colIndex ],
                                                      Severity: Major
                                                      Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                        Avoid deeply nested control flow statements.
                                                        Open

                                                                                    for ( indx = 1; indx < th.colSpan; indx++ ) {
                                                                                        c.sortList[ c.sortList.length ] = [ col + indx, dir ];
                                                                                        // update count on columns in colSpan
                                                                                        c.sortVars[ col + indx ].count = $.inArray( dir, order );
                                                                                    }
                                                        Severity: Major
                                                        Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                          Avoid deeply nested control flow statements.
                                                          Open

                                                                                      if ( span > 0 ) {
                                                                                          colIndex += span;
                                                                                          max += span;
                                                                                          while ( span + 1 > 0 ) {
                                                                                              // set colspan columns to use the same parsers & extractors
                                                          Severity: Major
                                                          Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                            Avoid deeply nested control flow statements.
                                                            Open

                                                                                        if ( !hasParser && c.debug ) {
                                                                                            console.warn( 'No parser found for row: ' + rowIndex + ', column: ' + colIndex +
                                                                                                '; cell containing: "' + $(cell).text() + '"; does it have a header?' );
                                                                                        }
                                                            Severity: Major
                                                            Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                              Avoid deeply nested control flow statements.
                                                              Open

                                                                                          if ( !parser ) {
                                                                                              parser = ts.detectParserForColumn( c, rows, -1, colIndex );
                                                                                          }
                                                              Severity: Major
                                                              Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                Avoid deeply nested control flow statements.
                                                                Open

                                                                                            if ( $.inArray( setting, ignore ) < 0 && typ === 'undefined' ) {
                                                                                                console.warn( 'Tablesorter Warning! "table.config.' + setting + '.' + setting2 + '" option not recognized' );
                                                                                            }
                                                                Severity: Major
                                                                Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                  Avoid deeply nested control flow statements.
                                                                  Open

                                                                                              if ( !$sorted[ column ].sortDisabled ) {
                                                                                                  updateColumnSort( $sorted.eq( column ) , list[ indx ][ 1 ] );
                                                                                              }
                                                                  Severity: Major
                                                                  Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                    Function sortNumericAsc has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                                                    Open

                                                                            sortNumericAsc : function( a, b, num, max, col, c ) {
                                                                    Severity: Minor
                                                                    Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                      Avoid deeply nested control flow statements.
                                                                      Open

                                                                                                  if ( noParser ) {
                                                                                                      parser = ts.getParserById( 'no-parser' );
                                                                                                  }
                                                                      Severity: Major
                                                                      Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                        Avoid deeply nested control flow statements.
                                                                        Open

                                                                                                    if ( temp ) {
                                                                                                        tmp = c.sortList[ 0 ][ 1 ];
                                                                                                        switch ( temp[ 0 ] ) {
                                                                                                            case 'd' :
                                                                                                                dir = 1;
                                                                        Severity: Major
                                                                        Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                          Avoid deeply nested control flow statements.
                                                                          Open

                                                                                                      if ( span > 0 ) {
                                                                                                          index = 0;
                                                                                                          while ( index <= span ) {
                                                                                                              // duplicate text (or not) to spanned columns
                                                                                                              // instead of setting duplicate span to empty string, use textExtraction to try to get a value
                                                                          Severity: Major
                                                                          Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                            Avoid deeply nested control flow statements.
                                                                            Open

                                                                                                        if ( hasParser && ( parsers[ cacheIndex ].type || '' ).toLowerCase() === 'numeric' ) {
                                                                                                            // determine column max value (ignore sign)
                                                                                                            colMax[ cacheIndex ] = Math.max( Math.abs( txt ) || 0, colMax[ cacheIndex ] || 0 );
                                                                                                        }
                                                                            Severity: Major
                                                                            Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                              Avoid deeply nested control flow statements.
                                                                              Open

                                                                                                          if ( !extractor ) {
                                                                                                              // For now, maybe detect someday
                                                                                                              extractor = false;
                                                                                                          }
                                                                              Severity: Major
                                                                              Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                                Avoid deeply nested control flow statements.
                                                                                Open

                                                                                                            if ( tmp[1] === 2 ) {
                                                                                                                c.sortList.splice( indx, 1 );
                                                                                                                c.sortVars[ col ].count = -1;
                                                                                                            }
                                                                                Severity: Major
                                                                                Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 45 mins to fix

                                                                                  Consider simplifying this complex logical expression.
                                                                                  Open

                                                                                                          if ( header && header.length ) {
                                                                                                              // get column indexed table cell; adding true parameter fixes #1362 but
                                                                                                              // it would break backwards compatibility...
                                                                                                              configHeaders = ts.getColumnData( table, c.headers, colIndex ); // , true );
                                                                                                              // get column parser/extractor
                                                                                  Severity: Major
                                                                                  Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 40 mins to fix

                                                                                    Function getColumnData has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                                    Open

                                                                                            getColumnData : function( table, obj, indx, getCell, $headers ) {
                                                                                    Severity: Minor
                                                                                    Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 35 mins to fix

                                                                                      Avoid too many return statements within this function.
                                                                                      Open

                                                                                                          return $.trim( tmp( $node[ 0 ], c.table, cellIndex ) );
                                                                                      Severity: Major
                                                                                      Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 30 mins to fix

                                                                                        Avoid too many return statements within this function.
                                                                                        Open

                                                                                                    return $.trim( $node[ 0 ].textContent || $node.text() );
                                                                                        Severity: Major
                                                                                        Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 30 mins to fix

                                                                                          Avoid too many return statements within this function.
                                                                                          Open

                                                                                                          if ( aFloat > bFloat ) { return 1; }
                                                                                          Severity: Major
                                                                                          Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 30 mins to fix

                                                                                            Avoid too many return statements within this function.
                                                                                            Open

                                                                                                        return 0;
                                                                                            Severity: Major
                                                                                            Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 30 mins to fix

                                                                                              Avoid too many return statements within this function.
                                                                                              Open

                                                                                                              if ( aFloat < bFloat ) { return -1; }
                                                                                              Severity: Major
                                                                                              Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js - About 30 mins to fix

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

                                                                                                ;( function( $ ) {
                                                                                                    'use strict';
                                                                                                    var ts = $.tablesorter = {
                                                                                                
                                                                                                        version : '2.29.2',
                                                                                                Severity: Major
                                                                                                Found in media/jquery/tablesorter-master/js/jquery.tablesorter.js and 1 other location - About 6 mos to fix
                                                                                                media/jquery/tablesorter-master/dist/js/jquery.tablesorter.js on lines 31..2889

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

                                                                                                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