Skip to content

Commit

Permalink
Fixing SonarQube-identified tech debt
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyars committed Sep 22, 2021
1 parent 878a92a commit 93b927d
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 22 deletions.
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ In the spirit of being as lazy as possible towards maintaining code quality, I r
You are welcome to fix any tech debt that you see in SaaS dashboards:

* [Code Climate](https://codeclimate.com/github/bbyars/mountebank)
* [Codacy](https://www.codacy.com/app/brandonbyars/mountebank/dashboard)
* [Test Coverage](https://codeclimate.com/github/bbyars/mountebank/coverage)
* [SonarQube](https://sonarqube.com/dashboard?id=mountebank)
* [Codacy](https://app.codacy.com/gh/bbyars/mountebank/dashboard)
* [SonarQube](https://sonarcloud.io/dashboard?id=mountebank&branch=master)

There are several linting tools run locally as well:

Expand Down
4 changes: 2 additions & 2 deletions mbTest/mb.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ function create (port, includeStdout) {
}

async function save (args) {
return await execCommand('save', args);
return execCommand('save', args);
}

async function replay (args) {
return await execCommand('replay', args);
return execCommand('replay', args);
}

function get (endpoint) {
Expand Down
2 changes: 1 addition & 1 deletion mbTest/web/docsTester/testTypes/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function runStep (step) {
nextTestId += 1;

try {
return await execute(`sh ./${filename}`);
return execute(`sh ./${filename}`);
}
catch (reason) {
console.log(`Error executing following command: ${step.text}`);
Expand Down
3 changes: 1 addition & 2 deletions src/models/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,11 @@ async function lookup (originalRequest, response, lookupConfig, logger) {
try {
const row = await lookupRow(lookupConfig, originalRequest, logger);
replaceObjectValuesIn(response, lookupConfig.into, row, logger);
return response;
}
catch (error) {
logger.error(error);
return response;
}
return response;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/models/filesystemBackedImpostersRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function create (config, logger) {

// with realpath = false, the file doesn't have to exist, but the directory does
await ensureDir(filepath);
return await locker.lock(filepath, options);
return locker.lock(filepath, options);
}

async function readAndWriteFile (filepath, caller, transformer, defaultContents) {
Expand Down Expand Up @@ -237,7 +237,7 @@ function create (config, logger) {
// Ignore lock already released errors
if (err.code !== 'ERELEASED') {
metrics.lockErrors.inc({ caller, code: err.code });
locker.unlock(filepath, { realpath: false }).catch(() => {});
locker.unlock(filepath, { realpath: false }).catch(() => { /* ignore */ });
throw err;
}
}
Expand Down Expand Up @@ -307,7 +307,7 @@ function create (config, logger) {
.sort(timeSorter)
.map(file => readFile(`${path}/${file}`));

return await Promise.all(reads);
return Promise.all(reads);
}

function repeatsFor (response) {
Expand Down Expand Up @@ -640,7 +640,7 @@ function create (config, logger) {
});

const nonProxyStubs = allStubs.filter(stub => stub.responses.length > 0);
return await overwriteAll(nonProxyStubs);
return overwriteAll(nonProxyStubs);
}

/**
Expand All @@ -663,7 +663,7 @@ function create (config, logger) {
* @returns {Object} - the promise resolving to the array of requests
*/
async function loadRequests () {
return await loadAllInDir(`${baseDir}/requests`);
return loadAllInDir(`${baseDir}/requests`);
}

/**
Expand Down Expand Up @@ -778,7 +778,7 @@ function create (config, logger) {
* @returns {Object} - all imposters keyed by port
*/
async function all () {
return await Promise.all(Object.keys(imposterFns).map(get));
return Promise.all(Object.keys(imposterFns).map(get));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/models/http/headersMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function of (headers) {
* @returns {*}
*/
function get (headerName) {
return headers[headerNameFor(headerName, headers)];
return headers[headerNameFor(headerName)];
}

/**
Expand All @@ -44,7 +44,7 @@ function of (headers) {
* @param {String} value - the value
*/
function set (headerName, value) {
headers[headerNameFor(headerName, headers)] = value;
headers[headerNameFor(headerName)] = value;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/models/inMemoryImpostersRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function create () {
* @returns {Object} - all imposters keyed by port
*/
async function all () {
return await Promise.all(Object.keys(imposters).map(get));
return Promise.all(Object.keys(imposters).map(get));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/models/responseResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ function create (stubs, proxy, callbackURL) {
match = await stubs.first(filter, index + 1);

if (match.success) {
return await match.stub.addResponse(newResponse);
return match.stub.addResponse(newResponse);
}
else {
return await stubs.add({ predicates: newPredicates, responses: [newResponse] });
return stubs.add({ predicates: newPredicates, responses: [newResponse] });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mountebank.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async function listen (app, options) {
*/
async function create (options) {
const app = await createApp(options);
return await listen(app, options);
return listen(app, options);
}

module.exports = { create, createApp };
4 changes: 2 additions & 2 deletions tasks/mb.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ async function execCommand (command, args) {
}

async function save (args) {
return await execCommand('save', args);
return execCommand('save', args);
}

async function replay (args) {
return await execCommand('replay', args);
return execCommand('replay', args);
}

async function execute (command, args) {
Expand Down

0 comments on commit 93b927d

Please sign in to comment.