dougmoscrop/serverless-http

View on GitHub

Showing 26 of 26 total issues

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

function isBinaryContent(headers, options) {
  const contentTypes = [].concat(options.binary
    ? options.binary
    : BINARY_CONTENT_TYPES
  ).map(candidate =>
Severity: Major
Found in lib/provider/azure/is-binary.js and 1 other location - About 4 hrs to fix
lib/provider/aws/is-binary.js on lines 16..26

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

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

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

function isBinaryContent(headers, options) {
  const contentTypes = [].concat(options.binary
    ? options.binary
    : BINARY_CONTENT_TYPES
  ).map(candidate =>
Severity: Major
Found in lib/provider/aws/is-binary.js and 1 other location - About 4 hrs to fix
lib/provider/azure/is-binary.js on lines 16..26

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

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

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

module.exports = function isBinary(headers, options) {
  if (options.binary === false) {
    return false;
  }

Severity: Major
Found in lib/provider/azure/is-binary.js and 1 other location - About 3 hrs to fix
lib/provider/aws/is-binary.js on lines 28..42

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

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

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

module.exports = function isBinary(headers, options) {
  if (options.binary === false) {
    return false;
  }

Severity: Major
Found in lib/provider/aws/is-binary.js and 1 other location - About 3 hrs to fix
lib/provider/azure/is-binary.js on lines 28..42

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

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

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

function isBinaryEncoding(headers) {
  const contentEncoding = headers['content-encoding'];

  if (typeof contentEncoding === 'string') {
    return contentEncoding.split(',').some(value =>
Severity: Major
Found in lib/provider/azure/is-binary.js and 1 other location - About 2 hrs to fix
lib/provider/aws/is-binary.js on lines 6..14

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

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

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

function isBinaryEncoding(headers) {
  const contentEncoding = headers['content-encoding'];

  if (typeof contentEncoding === 'string') {
    return contentEncoding.split(',').some(value =>
Severity: Major
Found in lib/provider/aws/is-binary.js and 1 other location - About 2 hrs to fix
lib/provider/azure/is-binary.js on lines 6..14

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

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

Function getFramework has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function getFramework(app) {
  if (app instanceof http.Server) {
    return request => {
      const response = new Response(request);
      app.emit('request', request, response)
Severity: Minor
Found in lib/framework/get-framework.js - About 2 hrs to fix

    Function constructor has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      constructor({ method }) {
        super({ method });
    
        this[BODY] = [];
        this[HEADERS] = {};
    Severity: Minor
    Found in lib/response.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 exports has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = (event, response, options) => {
      const eventType = getEventType(event);
      const { statusCode } = response;
      const { headers, multiValueHeaders } = sanitizeHeaders(Response.headers(response));
    
    
    Severity: Minor
    Found in lib/provider/aws/format-response.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 finish has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = async function finish(item, transform, ...details) {
      await new Promise((resolve, reject) => {
        if (item.finished || item.complete) {
          resolve();
          return;
    Severity: Minor
    Found in lib/finish.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 constructor has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      constructor({ method }) {
        super({ method });
    
        this[BODY] = [];
        this[HEADERS] = {};
    Severity: Minor
    Found in lib/response.js - About 1 hr to fix

      Function getFramework has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = function getFramework(app) {
        if (app instanceof http.Server) {
          return request => {
            const response = new Response(request);
            app.emit('request', request, response)
      Severity: Minor
      Found in lib/framework/get-framework.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 exports has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      module.exports = (event, response, options) => {
        const eventType = getEventType(event);
        const { statusCode } = response;
        const { headers, multiValueHeaders } = sanitizeHeaders(Response.headers(response));
      
      
      Severity: Minor
      Found in lib/provider/aws/format-response.js - About 1 hr to fix

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

        module.exports = async function finish(item, transform, ...details) {
          await new Promise((resolve, reject) => {
            if (item.finished || item.complete) {
              resolve();
              return;
        Severity: Minor
        Found in lib/finish.js - About 1 hr to fix

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

          module.exports = function sanitizeHeaders(headers) {
            return Object.keys(headers).reduce((memo, key) => {
                const value = headers[key];
          
                if (Array.isArray(value)) {
          Severity: Minor
          Found in lib/provider/azure/sanitize-headers.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 constructor has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            constructor({ method, url, headers, body, remoteAddress }) {
              super({
                encrypted: true,
                readable: false,
                remoteAddress,
          Severity: Minor
          Found in lib/request.js - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

              if (event.version === '2.0') {
                event.requestContext.authorizer = event.requestContext.authorizer || {};
                event.requestContext.http.method = event.requestContext.http.method || 'GET';
                event.rawPath = removeBasePath(event.requestPath || event.rawPath, options.basePath);
              } else {
            Severity: Major
            Found in lib/provider/aws/clean-up-event.js - About 1 hr to fix

              Function recursiveURLDecode has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              function recursiveURLDecode(value) {
              
                if (isString(value)) {
                  return specialDecodeURIComponent(value);
                } else if (Array.isArray(value)) {
              Severity: Minor
              Found in lib/provider/aws/clean-up-event.js - About 55 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

              Function sanitizeHeaders has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              module.exports = function sanitizeHeaders(headers) {
                return Object.keys(headers).reduce((memo, key) => {
                    const value = headers[key];
              
                  if (Array.isArray(value)) {
              Severity: Minor
              Found in lib/provider/aws/sanitize-headers.js - About 55 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

              Function cleanupEvent has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              module.exports = function cleanupEvent(evt, options) {
                const event = evt || {};
              
                event.requestContext = event.requestContext || {};
                event.body = event.body || '';
              Severity: Minor
              Found in lib/provider/aws/clean-up-event.js - About 35 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

              Severity
              Category
              Status
              Source
              Language