Showing 119 of 386 total issues
Function to
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function to (proxyDestination, originalRequest, options = {}) {
return new Promise((resolve, reject) => {
try {
const proxyName = socketName(connectionInfoFor(proxyDestination)),
log = (direction, what) => {
Function listen
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async function listen (app, options) {
const hostname = options.host || 'localhost',
baseURL = `http://${hostname}:${options.port}`,
logger = utilLogger.createLogger(options),
isAllowedConnection = utilIp.createIPVerification(options);
Function send
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
response.send = function () {
const args = Array.prototype.slice.call(arguments),
body = args[0],
changeLinks = function (obj) {
if (obj._links) {
Function createStubsRepository
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
Open
function createStubsRepository () {
const stubs = [];
let requests = [];
function reindex () {
- Read upRead up
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
Open
function postProcess (stubResponse, request) {
/* eslint complexity: 0 */
const defaultHeaders = defaultResponse.headers || {},
response = {
statusCode: stubResponse.statusCode || defaultResponse.statusCode || 200,
Function curl
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function curl (options, method, path, body) {
return new Promise((resolve, reject) => {
const requestOptions = {
method: method,
path: path,
Function selectRowFromCSV
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function selectRowFromCSV (csvConfig, keyValue, logger) {
const delimiter = csvConfig.delimiter || ',',
inputStream = fsExtra.createReadStream(csvConfig.path),
parser = csvParse.parse({ delimiter: delimiter }),
pipe = inputStream.pipe(parser);
Function parseLogConfiguration
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
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',
Function predicateSatisfied
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function predicateSatisfied (expected, actual, predicateConfig, predicateFn) {
if (!actual) {
return false;
}
Function createImposterMetrics
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
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',
Function put
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async function put (request, response) {
const requestImposters = request.body.imposters || [],
validationPromises = requestImposters.map(imposter => validate(imposter));
logger.debug(requestDetails(request));
Function getProxyRequest
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
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,
Function create
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function create (version, options) {
const publicOptions = helpers.clone(options);
delete publicOptions.version;
Function createLogger
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function createLogger (options) {
if (!options.log) {
options.log = { level: 'info' };
}
if (!options.log.transports) {
Function postJSON
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function postJSON (what, where) {
return new Promise((resolve, reject) => {
const parts = new URL(where),
driver = require(parts.protocol.replace(':', '')),
options = {
Function execShell
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function execShell (command, request, response, logger) {
const exec = childProcess.exec,
env = helpers.clone(process.env),
maxBuffer = buffer.constants.MAX_STRING_LENGTH,
maxShellCommandLength = 2048;
Function json
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
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();
Function to
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function to (proxyDestination, originalRequest, options, requestDetails) {
addInjectedHeadersTo(originalRequest, options.injectHeaders);
function log (direction, what) {
Function wrap
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function wrap (stub = {}) {
const cloned = helpers.clone(stub),
statefulResponses = repeatTransform(cloned.responses || []);
/**
Function validateApiKey
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function validateApiKey (expectedApiKey, log) {
return function (request, response, next) {
if (!expectedApiKey) {
next();
return;