bbyars/mountebank

View on GitHub

Showing 386 of 386 total issues

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

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

                            function validate (behaviors, validationSpec) {
                                const errors = [];
                        
                                (behaviors || []).forEach(config => {
                                    const validBehaviors = [],
                        Severity: Minor
                        Found in src/models/behaviorsValidator.js - About 1 hr to fix

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

                          function create (releases) {
                              function createNotice (release) {
                                  return {
                                      version: release.version,
                                      when: date.howLongAgo(release.date)
                          Severity: Minor
                          Found in src/controllers/homeController.js - About 1 hr to fix

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

                                async function proxyAndRecord (responseConfig, request, logger, requestDetails, imposterState) {
                                    const startTime = new Date(),
                                        observeProxyDuration = metrics.proxyDuration.startTimer();
                            
                                    metrics.proxyCount.inc({ imposter: logger.scopePrefix });
                            Severity: Minor
                            Found in src/models/responseResolver.js - About 1 hr to fix

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

                                  async function respond (payload, request, clientName, socket) {
                                      let formattedRequestData = payload.toString(encoding);
                                      if (formattedRequestData.length > 20) {
                                          formattedRequestData = formattedRequestData.substring(0, 20) + '...';
                                      }
                              Severity: Minor
                              Found in src/models/tcp/tcpServer.js - About 1 hr to fix

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

                                    function inject (request, fn, logger, imposterState) {
                                        if (request.isDryRun) {
                                            return Promise.resolve({});
                                        }
                                
                                
                                Severity: Minor
                                Found in src/models/responseResolver.js - About 1 hr to fix

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

                                  function create (config) {
                                      let callbackURL,
                                          proxy;
                                  
                                      function setPort (port) {
                                  Severity: Minor
                                  Found in src/models/mbConnection.js - About 1 hr to fix

                                    Function selectTransform has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                    function selectTransform (config, options, logger) {
                                        const cloned = helpers.clone(config);
                                    
                                        if (config.jsonpath) {
                                            const stringTransform = options.shouldForceStrings ? forceStrings : combinators.identity;
                                    Severity: Minor
                                    Found in src/models/predicates.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 resolveWithMetadata has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                                function resolveWithMetadata (possibleJSON) {
                                                    let metadata = {};
                                    
                                                    try {
                                                        metadata = JSON.parse(possibleJSON);
                                    Severity: Minor
                                    Found in src/models/protocols.js - About 1 hr to fix

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

                                                      client.on('error', err => {
                                                          logger.warn('CLIENT TO PROXY ERROR: [%s] %s', err.code, err.message);
                                                          logger.debug('%s', err.stack);
                                                      });
                                      Severity: Major
                                      Found in src/models/http/baseHttpServer.js and 1 other location - About 1 hr to fix
                                      src/models/http/baseHttpServer.js on lines 85..88

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

                                      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