bbyars/mountebank

View on GitHub

Showing 386 of 386 total issues

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

function create (logger, encoding, isEndOfRequest) {

    if (typeof isEndOfRequest === 'undefined') {
        isEndOfRequest = () => true; // defaults to a packet boundary
    }
Severity: Major
Found in src/models/tcp/tcpProxy.js - About 2 hrs to fix

    Function create has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function create () {
        const imposters = {},
            stubRepos = {};
    
        /**
    Severity: Major
    Found in src/models/inMemoryImpostersRepository.js - About 2 hrs to fix

      Function wrap has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              function wrap (stub) {
                  const cloned = helpers.clone(stub || {}),
                      stubDir = stub ? stub.meta.dir : '';
      
                  if (typeof stub === 'undefined') {
      Severity: Major
      Found in src/models/filesystemBackedImpostersRepository.js - About 2 hrs to fix

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

        function create (releases) {
            const feedReleases = helpers.clone(releases);
        
            // Init once since we hope many consumers poll the heroku feed and we don't have monitoring
            feedReleases.reverse();
        Severity: Major
        Found in src/controllers/feedController.js - About 2 hrs to fix

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

              function predicatesFor (request, matchers, logger) {
                  const predicates = [];
          
                  matchers.forEach(matcher => {
                      if (matcher.inject) {
          Severity: Major
          Found in src/models/responseResolver.js - About 2 hrs to fix

            Function useAbsoluteUrls has 53 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function useAbsoluteUrls (port) {
                return function (request, response, next) {
                    const setHeaderOriginal = response.setHeader,
                        sendOriginal = response.send,
                        host = request.headers.host || `localhost:${port}`,
            Severity: Major
            Found in src/util/middleware.js - About 2 hrs to fix

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

                  function to (proxyDestination, originalRequest, options = {}) {
                      return new Promise((resolve, reject) => {
                          try {
                              const proxyName = socketName(connectionInfoFor(proxyDestination)),
                                  log = (direction, what) => {
              Severity: Minor
              Found in src/models/tcp/tcpProxy.js - About 1 hr to fix

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

                    argv = yargs
                        .usage('Usage: mb [command=start] [options...]')
                        .command('start', 'Starts the server (default command)', startYargs => {
                            startYargs
                                .usage('Usage: mb [start] [options...]')
                Severity: Major
                Found in src/cli/cli.js and 1 other location - About 1 hr to fix
                src/cli/cli.js on lines 194..228

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

                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 listen has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                async function listen (app, options) {
                    const hostname = options.host || 'localhost',
                        baseURL = `http://${hostname}:${options.port}`,
                        logger = utilLogger.createLogger(options),
                        isAllowedConnection = utilIp.createIPVerification(options);
                Severity: Minor
                Found in src/mountebank.js - About 1 hr to fix

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

                          const imposter = await imposters.get(request.params.id),
                              stubs = imposters.stubsFor(request.params.id),
                              validation = await validateStubIndex(stubs, request.params.stubIndex);
                  Severity: Major
                  Found in src/controllers/imposterController.js and 1 other location - About 1 hr to fix
                  src/controllers/imposterController.js on lines 300..302

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

                  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

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

                          const imposter = await imposters.get(request.params.id),
                              stubs = imposters.stubsFor(request.params.id),
                              validation = await validateStubIndex(stubs, request.params.stubIndex);
                  Severity: Major
                  Found in src/controllers/imposterController.js and 1 other location - About 1 hr to fix
                  src/controllers/imposterController.js on lines 224..226

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

                  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 send has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          response.send = function () {
                              const args = Array.prototype.slice.call(arguments),
                                  body = args[0],
                                  changeLinks = function (obj) {
                                      if (obj._links) {
                  Severity: Minor
                  Found in src/util/middleware.js - About 1 hr to fix

                    Function createStubsRepository has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function createStubsRepository () {
                        const stubs = [];
                        let requests = [];
                    
                        function reindex () {
                    Severity: Minor
                    Found in src/models/inMemoryImpostersRepository.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 postProcess has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            function postProcess (stubResponse, request) {
                                /* eslint complexity: 0 */
                                const defaultHeaders = defaultResponse.headers || {},
                                    response = {
                                        statusCode: stubResponse.statusCode || defaultResponse.statusCode || 200,
                    Severity: Minor
                    Found in src/models/http/baseHttpServer.js - About 1 hr to fix

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

                      function curl (options, method, path, body) {
                          return new Promise((resolve, reject) => {
                              const requestOptions = {
                                  method: method,
                                  path: path,
                      Severity: Minor
                      Found in src/cli/api.js - About 1 hr to fix

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

                        function selectRowFromCSV (csvConfig, keyValue, logger) {
                            const delimiter = csvConfig.delimiter || ',',
                                inputStream = fsExtra.createReadStream(csvConfig.path),
                                parser = csvParse.parse({ delimiter: delimiter }),
                                pipe = inputStream.pipe(parser);
                        Severity: Minor
                        Found in src/models/behaviors.js - About 1 hr to fix

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

                          function parseLogConfiguration (args) {
                              // Not defaulted in yargs so we can test yargs value without defaulting interfering.
                              // This is needed for backwards compatibility with older CLI options.
                              const defaultConfig = {
                                  level: 'info',
                          Severity: Minor
                          Found in src/cli/cli.js - About 1 hr to fix

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

                                            close: callback => {
                                                server.close(callback);
                                                Object.keys(connections).forEach(socket => {
                                                    connections[socket].destroy();
                                                });
                            Severity: Major
                            Found in src/models/smtp/smtpServer.js and 1 other location - About 1 hr to fix
                            src/models/http/baseHttpServer.js on lines 176..181

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

                            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

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

                                                close: callback => {
                                                    server.close(callback);
                                                    Object.keys(connections).forEach(socket => {
                                                        connections[socket].destroy();
                                                    });
                            Severity: Major
                            Found in src/models/http/baseHttpServer.js and 1 other location - About 1 hr to fix
                            src/models/smtp/smtpServer.js on lines 85..90

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

                            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 predicateSatisfied has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function predicateSatisfied (expected, actual, predicateConfig, predicateFn) {
                                if (!actual) {
                                    return false;
                                }
                            
                            
                            Severity: Minor
                            Found in src/models/predicates.js - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language