propero-oss/easy-api

View on GitHub
src/util/http-response.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%

Function applyHeaders has a Cognitive Complexity of 21 (exceeds 10 allowed). Consider refactoring.
Invalid

export function applyHeaders(res: Response, ...headers: (Record<string, undefined | number | string | string[]> | undefined)[]) {
  const normalised: Record<string, string | string[]> = {};
  for (const header of headers)
    if (header)
      for (const [key, value] of Object.entries(header)) {
Severity: Minor
Found in src/util/http-response.ts - About 2 hrs 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 applyHttpResponse has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
Invalid

export function applyHttpResponse(it: HttpResponse, res: Response) {
  const { status, data, headers, redirect, contentType, contentLength, raw } = it;
  if (status != null) res.status(status);
  if (headers != null || contentType != null || contentLength != null)
    applyHeaders(res, { "content-type": contentType, "content-length": contentLength }, headers);
Severity: Minor
Found in src/util/http-response.ts - About 45 mins 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

Avoid too many return statements within this function.
Invalid

      else return res.json(result);
Severity: Major
Found in src/util/http-response.ts - About 30 mins to fix

    Avoid too many return statements within this function.
    Invalid

        return res.send(data);
    Severity: Major
    Found in src/util/http-response.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Wontfix

        else return res.json(err);
      Severity: Major
      Found in src/util/http-response.ts - About 30 mins to fix

        There are no issues that match your filters.

        Category
        Status