bbyars/mountebank

View on GitHub

Showing 119 of 386 total issues

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

    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

      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

                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

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

                      function createImposterMetrics () {
                          const impostersMetrics = {
                              predicateMatchDuration: new prometheus.Histogram({
                                  name: 'mb_predicate_match_duration_seconds',
                                  help: 'Time it takes to match the predicates and select a stub',
                  Severity: Minor
                  Found in src/models/imposter.js - About 1 hr to fix

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

                        async function put (request, response) {
                            const requestImposters = request.body.imposters || [],
                                validationPromises = requestImposters.map(imposter => validate(imposter));
                    
                            logger.debug(requestDetails(request));
                    Severity: Minor
                    Found in src/controllers/impostersController.js - About 1 hr to fix

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

                          function getProxyRequest (baseUrl, originalRequest, proxyOptions, requestDetails) {
                              /* eslint complexity: 0 */
                              const parts = new URL(baseUrl),
                                  protocol = parts.protocol === 'https:' ? https : http,
                                  defaultPort = parts.protocol === 'https:' ? 443 : 80,
                      Severity: Minor
                      Found in src/models/http/httpProxy.js - About 1 hr to fix

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

                        function create (version, options) {
                            const publicOptions = helpers.clone(options);
                        
                            delete publicOptions.version;
                        
                        
                        Severity: Minor
                        Found in src/controllers/configController.js - About 1 hr to fix

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

                          function createLogger (options) {
                              if (!options.log) {
                                  options.log = { level: 'info' };
                              }
                              if (!options.log.transports) {
                          Severity: Minor
                          Found in src/util/logger.js - About 1 hr to fix

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

                            function postJSON (what, where) {
                                return new Promise((resolve, reject) => {
                                    const parts = new URL(where),
                                        driver = require(parts.protocol.replace(':', '')),
                                        options = {
                            Severity: Minor
                            Found in src/models/mbConnection.js - About 1 hr to fix

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

                              function execShell (command, request, response, logger) {
                                  const exec = childProcess.exec,
                                      env = helpers.clone(process.env),
                                      maxBuffer = buffer.constants.MAX_STRING_LENGTH,
                                      maxShellCommandLength = 2048;
                              Severity: Minor
                              Found in src/models/behaviors.js - About 1 hr to fix

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

                                function json (log) {
                                    return function (request, response, next) {
                                        // Disable body parsing, if already parsed
                                        if (request.headers['content-type'] === 'application/json' && helpers.isObject(request.body)) {
                                            next();
                                Severity: Minor
                                Found in src/util/middleware.js - About 1 hr to fix

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

                                      function to (proxyDestination, originalRequest, options, requestDetails) {
                                  
                                          addInjectedHeadersTo(originalRequest, options.injectHeaders);
                                  
                                          function log (direction, what) {
                                  Severity: Minor
                                  Found in src/models/http/httpProxy.js - About 1 hr to fix

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

                                    function wrap (stub = {}) {
                                        const cloned = helpers.clone(stub),
                                            statefulResponses = repeatTransform(cloned.responses || []);
                                    
                                        /**
                                    Severity: Minor
                                    Found in src/models/inMemoryImpostersRepository.js - About 1 hr to fix

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

                                      function validateApiKey (expectedApiKey, log) {
                                          return function (request, response, next) {
                                              if (!expectedApiKey) {
                                                  next();
                                                  return;
                                      Severity: Minor
                                      Found in src/util/middleware.js - About 1 hr to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language