karma-runner/karma

View on GitHub

Showing 258 of 258 total issues

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

ContextKarma.getPostMessageCallParentKarmaMethod = function (parentWindow) {
  return function postMessageCallParentKarmaMethod (method, args) {
    parentWindow.postMessage({ __karmaMethod: method, __karmaArguments: args }, window.location.origin)
  }
}
Severity: Major
Found in static/context.js and 1 other location - About 1 hr to fix
context/karma.js on lines 154..158

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

Function createWebServer has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function createWebServer (injector, config) {
  const { mime = {} } = config
  mimeType.define({ ...mime }, true)

  const proxyMiddlewareInstance = injector.invoke(proxyMiddleware.create)
Severity: Minor
Found in lib/web-server.js - About 1 hr to fix

    Function DotsReporter has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function DotsReporter (formatError, reportSlow, useColors, browserConsoleLogOptions) {
      BaseReporter.call(this, formatError, reportSlow, useColors, browserConsoleLogOptions)
    
      const DOTS_WRAP = 80
      this.EXCLUSIVELY_USE_COLORS = false
    Severity: Minor
    Found in lib/reporters/dots.js - About 1 hr to fix

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

      function setup (level, colors, appenders) {
        // Turn color on/off on the console appenders with pattern layout
        const pattern = colors ? constant.COLOR_PATTERN : constant.NO_COLOR_PATTERN
        if (appenders) {
          // Convert Array to Object for backwards compatibility.
      Severity: Minor
      Found in lib/logger.js - About 1 hr to fix

        Function describeStart has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function describeStart (yargs) {
          yargs
            .usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
              'START - Start the server / do a single run.\n\n' +
              'Usage:\n' +
        Severity: Minor
        Found in lib/cli.js - About 1 hr to fix

          Function createRunnerMiddleware has 10 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          function createRunnerMiddleware (emitter, fileList, capturedBrowsers, reporter, executor,
            /* config.protocol */ protocol, /* config.hostname */ hostname, /* config.port */
            port, /* config.urlRoot */ urlRoot, config) {
          Severity: Major
          Found in lib/middleware/runner.js - About 1 hr to fix

            Function factory has 10 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              id, fullName, /* capturedBrowsers */ collection, emitter, socket, timer,
              /* config.browserDisconnectTimeout */ disconnectDelay,
              /* config.browserNoActivityTimeout */ noActivityTimeout,
              /* config.singleRun */ singleRun,
              /* config.client */ clientConfig) {
            Severity: Major
            Found in lib/browser.js - About 1 hr to fix

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

              function complete (env) {
                if (env.count === 1) {
                  return sendCompletion(env.words[0].startsWith('-') ? ['--help', '--version'] : Object.keys(options), env)
                } else if (env.count === 2 && !env.words[1].startsWith('-')) {
                  return sendCompletionFiles(env)
              Severity: Minor
              Found in lib/completion.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 DotsReporter has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

              function DotsReporter (formatError, reportSlow, useColors, browserConsoleLogOptions) {
                BaseReporter.call(this, formatError, reportSlow, useColors, browserConsoleLogOptions)
              
                const DOTS_WRAP = 80
                this.EXCLUSIVELY_USE_COLORS = false
              Severity: Minor
              Found in lib/reporters/dots.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 createSourceFilesMiddleware has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function createSourceFilesMiddleware (filesPromise, serveFile, basePath, urlRoot) {
                return function (request, response, next) {
                  const requestedFilePath = composeUrl(request.url, basePath, urlRoot)
                  // When a path contains HTML-encoded characters (e.g %2F used by Jenkins for branches with /)
                  const requestedFilePathUnescaped = composeUrl(querystring.unescape(request.url), basePath, urlRoot)
              Severity: Minor
              Found in lib/middleware/source_files.js - About 1 hr to fix

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

                exports.init = function (config) {
                  logger.setupFromConfig(config)
                
                  const colorScheme = !helper.isDefined(config.colors) || config.colors ? COLOR_SCHEME.ON : COLOR_SCHEME.OFF
                  // need to be registered before creating readlineInterface
                Severity: Minor
                Found in lib/init.js - About 1 hr to fix

                  Function files has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    get files () {
                      const served = []
                      const included = {}
                      const lookup = {}
                      this._patterns.forEach((p) => {
                  Severity: Minor
                  Found in lib/file-list.js - About 1 hr to fix

                    Function describeRun has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function describeRun (yargs) {
                      yargs
                        .usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
                          'RUN - Run the tests (requires running server).\n\n' +
                          'Usage:\n' +
                    Severity: Minor
                    Found in lib/cli.js - About 1 hr to fix

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

                        this.complete = function (result) {
                          if (resultsBuffer.length) {
                            socket.emit('result', resultsBuffer)
                            resultsBuffer = []
                          }
                      Severity: Minor
                      Found in client/karma.js - About 1 hr to fix

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

                        function encode (str, opts) {
                            if (typeof str !== 'string') {
                                throw new TypeError('Expected a String');
                            }
                            if (!opts) opts = {};
                        Severity: Minor
                        Found in static/karma.js - About 1 hr to fix

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

                            this.complete = function (result) {
                              if (resultsBuffer.length) {
                                socket.emit('result', resultsBuffer)
                                resultsBuffer = []
                              }
                          Severity: Minor
                          Found in static/karma.js - About 1 hr to fix

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

                            function encode (str, opts) {
                                if (typeof str !== 'string') {
                                    throw new TypeError('Expected a String');
                                }
                                if (!opts) opts = {};
                            Severity: Minor
                            Found in static/context.js - About 1 hr to fix

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

                                this._execCommand = function (cmd, args) {
                                  if (!cmd) {
                                    log.error(`No binary for ${self.name} browser on your platform.\n  Please, set "${self.ENV_CMD}" env variable.`)
                              
                                    // disable restarting
                              Severity: Minor
                              Found in lib/launchers/process.js - About 1 hr to fix

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

                                    if (proxy.protocol.match(/https?:/) === null) {
                                      log.warn(`"${proxy.protocol}" is not a supported upstream proxy protocol, defaulting to "http:"`)
                                      proxy.protocol = 'http:'
                                    }
                                Severity: Major
                                Found in lib/config.js and 1 other location - About 1 hr to fix
                                lib/config.js on lines 161..164

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

                                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 (config.protocol.match(/https?:/) === null) {
                                    log.warn(`"${config.protocol}" is not a supported protocol, defaulting to "http:"`)
                                    config.protocol = 'http:'
                                  }
                                Severity: Major
                                Found in lib/config.js and 1 other location - About 1 hr to fix
                                lib/config.js on lines 153..156

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

                                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

                                Severity
                                Category
                                Status
                                Source
                                Language