fossasia/loklak_webclient

View on GitHub
iframely/lib/core.js

Summary

Maintainability
F
1 wk
Test Coverage

File core.js has 857 lines of code (exceeds 250 allowed). Consider refactoring.
Open

(function(core) {

    var _ = require('underscore'),
        request = require('request'),
        urlLib = require('url');
Severity: Major
Found in iframely/lib/core.js - About 2 days to fix

    Function run has 146 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        var run = core.run = function(uri, options, cb) {
    
            if (typeof options === 'function') {
                cb = options;
                options = {};
    Severity: Major
    Found in iframely/lib/core.js - About 5 hrs to fix

      Function getPluginsSet has 111 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function getPluginsSet(uri, options, usedParams) {
      
              var initialPlugins = [],
                  usedDomains,
                  isDomainPluginsMode = false,
      Severity: Major
      Found in iframely/lib/core.js - About 4 hrs to fix

        Function runMethods has 88 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function runMethods(methods, context, pluginsUrlMatches, options, asyncMethodCb) {
        
                // Sync results list.
                var results = [];
        
        
        Severity: Major
        Found in iframely/lib/core.js - About 3 hrs to fix

          Function useResult has 78 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function useResult(usedMethods, context, pluginsContexts, allResults, result, options, asyncMethodCb) {
          
                  if (!result) {
                      return false;
                  }
          Severity: Major
          Found in iframely/lib/core.js - About 3 hrs to fix

            Function prepareResultData has 68 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function prepareResultData(uri, result, options) {
            
                    if (!options.debug) {
                        // TODO: deep clean?
                        delete result.allData;
            Severity: Major
            Found in iframely/lib/core.js - About 2 hrs to fix

              Function runPostPlugins has 67 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function runPostPlugins(link, dataRecord, usedMethods, context, pluginsContexts, asyncMethodCb) {
              
                      for(var i = 0; i < postPluginsList.length; i++) {
                          (function() {
              
              
              Severity: Major
              Found in iframely/lib/core.js - About 2 hrs to fix

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

                    function findPluginMethods(pluginId, loadedParams, pluginsUrlMatches, usedMethods, usedParams, methods, scannedPluginsIds, usedDomains, mandatoryParams) {
                
                       /*
                        * Params:
                        *
                Severity: Major
                Found in iframely/lib/core.js - About 2 hrs to fix

                  Function asyncMethodCb has 59 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                              asyncMethodCb = function(error, result) {
                  
                                  if (aborted) {
                                      return;
                                  }
                  Severity: Major
                  Found in iframely/lib/core.js - About 2 hrs to fix

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

                        core.sortLinks = function(links) {
                    
                            // Sort links in order of REL according to CONFIG.REL_GROUPS.
                            function getRelIndex(rel) {
                                var rels = _.intersection(rel, CONFIG.REL_GROUPS);
                    Severity: Minor
                    Found in iframely/lib/core.js - About 1 hr to fix

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

                                      var callback = function(error, data) {
                      
                                          if (timeout) {
                                              clearTimeout(timeout);
                                              timeout = null;
                      Severity: Minor
                      Found in iframely/lib/core.js - About 1 hr to fix

                        Function findPluginMethods has 9 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            function findPluginMethods(pluginId, loadedParams, pluginsUrlMatches, usedMethods, usedParams, methods, scannedPluginsIds, usedDomains, mandatoryParams) {
                        Severity: Major
                        Found in iframely/lib/core.js - About 1 hr to fix

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

                                      finish = function() {
                          
                                          // Abort request.
                                          if (context.htmlparser && context.htmlparser.request) {
                                              context.htmlparser.request.abort();
                          Severity: Minor
                          Found in iframely/lib/core.js - About 1 hr to fix

                            Function runPluginsIteration has 8 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                function runPluginsIteration(requiredPlugins, context, pluginsUrlMatches, usedMethods, usedParams, usedDomains, options, asyncMethodCb) {
                            Severity: Major
                            Found in iframely/lib/core.js - About 1 hr to fix

                              Function useResult has 7 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  function useResult(usedMethods, context, pluginsContexts, allResults, result, options, asyncMethodCb) {
                              Severity: Major
                              Found in iframely/lib/core.js - About 50 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                        if (!(key in context) || key === 'whitelistRecord') {
                                                            context[key] = r.data[key];
                                                            hasNewData = true;
                                                        }
                                Severity: Major
                                Found in iframely/lib/core.js - About 45 mins to fix

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

                                      function runPostPlugins(link, dataRecord, usedMethods, context, pluginsContexts, asyncMethodCb) {
                                  Severity: Minor
                                  Found in iframely/lib/core.js - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                            while (!match && j < res.length) {
                                                                match = uri.match(res[j]);
                                                                j++;
                                                            }
                                    Severity: Major
                                    Found in iframely/lib/core.js - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                              if (idx === -1 || ((idx > 0) && domain.charAt(idx - 1) !== '.')) {
                                                                  // Break if not found, or not dot separation.
                                                                  continue;
                                                              }
                                      Severity: Major
                                      Found in iframely/lib/core.js - About 45 mins to fix

                                        Avoid deeply nested control flow statements.
                                        Open

                                                                if (match) {
                                                                    registerDomainPlugin(plugin, null);
                                                                }
                                        Severity: Major
                                        Found in iframely/lib/core.js - About 45 mins to fix

                                          Avoid deeply nested control flow statements.
                                          Open

                                                                  if (match) {
                                                                      // Store match for plugin.
                                                                      registerDomainPlugin(plugin, match);
                                                                      pluginsUrlMatches[plugin.id] = match;
                                                                      continue;
                                          Severity: Major
                                          Found in iframely/lib/core.js - About 45 mins to fix

                                            Avoid deeply nested control flow statements.
                                            Open

                                                                        if (!exists) {
                                                                            initialPlugins.push(plugins[foundPluginId]);
                                                                        }
                                            Severity: Major
                                            Found in iframely/lib/core.js - About 45 mins to fix

                                              Avoid deeply nested control flow statements.
                                              Open

                                                                  for(var key in r.data) {
                                                                      var v = r.data[key];
                                              
                                                                      // TODO: postprocessing meta plugins.
                                              
                                              
                                              Severity: Major
                                              Found in iframely/lib/core.js - About 45 mins to fix

                                                Consider simplifying this complex logical expression.
                                                Open

                                                            if (canonical && link.href && typeof link.href === 'string' && link.rel && link.rel.indexOf(CONFIG.R.file) === -1 && link.rel.indexOf(CONFIG.R.iframely) === -1) {
                                                
                                                                // Remove last / from url.
                                                
                                                                var link1 = link.href.replace(/\/+$/, '');
                                                Severity: Major
                                                Found in iframely/lib/core.js - About 40 mins to fix

                                                  Consider simplifying this complex logical expression.
                                                  Open

                                                                  if ((hasGetLinkMethod && getLinkMethodUsed)
                                                                      || (r.method.name === 'getData' && r.data.safe_html)
                                                                      || (!hasGetLinkMethod && r.method.name === 'getMeta')) {
                                                                      hasDomainData = true;
                                                                  }
                                                  Severity: Major
                                                  Found in iframely/lib/core.js - About 40 mins to fix

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

                                                        function runMethods(methods, context, pluginsUrlMatches, options, asyncMethodCb) {
                                                    Severity: Minor
                                                    Found in iframely/lib/core.js - About 35 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                                      return;
                                                      Severity: Major
                                                      Found in iframely/lib/core.js - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                            return -1;
                                                        Severity: Major
                                                        Found in iframely/lib/core.js - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                              return 1;
                                                          Severity: Major
                                                          Found in iframely/lib/core.js - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                            return 1;
                                                            Severity: Major
                                                            Found in iframely/lib/core.js - About 30 mins to fix

                                                              Avoid too many return statements within this function.
                                                              Open

                                                                          return 0;
                                                              Severity: Major
                                                              Found in iframely/lib/core.js - About 30 mins to fix

                                                                Avoid too many return statements within this function.
                                                                Open

                                                                                    return 1;
                                                                Severity: Major
                                                                Found in iframely/lib/core.js - About 30 mins to fix

                                                                  Avoid too many return statements within this function.
                                                                  Open

                                                                                  return -1;
                                                                  Severity: Major
                                                                  Found in iframely/lib/core.js - About 30 mins to fix

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

                                                                                    if (r.error && r.error[SYS_ERRORS.responseStatusCode]) {
                                                                                        sysUtils.log('   -- response (by "' + r.method.pluginId + '")', r.error[SYS_ERRORS.responseStatusCode]);
                                                                                        return r.error[SYS_ERRORS.responseStatusCode];
                                                                                    }
                                                                    Severity: Major
                                                                    Found in iframely/lib/core.js and 1 other location - About 2 hrs to fix
                                                                    iframely/lib/core.js on lines 1092..1095

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

                                                                    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

                                                                                    if (r.error && r.error[SYS_ERRORS.redirect]) {
                                                                                        sysUtils.log('   -- plugin redirect (by "' + r.method.pluginId + '")', r.error[SYS_ERRORS.redirect]);
                                                                                        return r.error[SYS_ERRORS.redirect];
                                                                                    }
                                                                    Severity: Major
                                                                    Found in iframely/lib/core.js and 1 other location - About 2 hrs to fix
                                                                    iframely/lib/core.js on lines 1105..1108

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

                                                                    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