bbc/cloudflare-queue-consumer

View on GitHub

Showing 13 of 13 total issues

File consumer.ts has 303 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { TypedEventEmitter } from "./emitter.js";
import type {
  ConsumerOptions,
  Message,
  PullMessagesResponse,
Severity: Minor
Found in src/consumer.ts - About 3 hrs to fix

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

    export class StandardError extends Error {
      cause: Error;
      time: Date;
    
      constructor(message = "An unexpected error occurred:") {
    Severity: Major
    Found in src/errors.ts and 1 other location - About 1 hr to fix
    src/errors.ts on lines 67..76

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

    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

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

    export class TimeoutError extends Error {
      cause: Error;
      time: Date;
    
      constructor(message = "Operation timed out.") {
    Severity: Major
    Found in src/errors.ts and 1 other location - About 1 hr to fix
    src/errors.ts on lines 43..52

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

    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

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

      on<E extends keyof Events>(
        event: E,
        listener: (...args: Events[E]) => void,
      ): this {
        return super.on(event, listener);
    Severity: Major
    Found in src/emitter.ts and 1 other location - About 1 hr to fix
    src/emitter.ts on lines 23..28

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

    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

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

    export function toStandardError(err: Error, message: string): StandardError {
      const error = new StandardError(message);
      error.cause = err;
      error.time = new Date();
    
    
    Severity: Major
    Found in src/errors.ts and 1 other location - About 1 hr to fix
    src/errors.ts on lines 83..92

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

    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

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

      once<E extends keyof Events>(
        event: E,
        listener: (...args: Events[E]) => void,
      ): this {
        return super.once(event, listener);
    Severity: Major
    Found in src/emitter.ts and 1 other location - About 1 hr to fix
    src/emitter.ts on lines 12..17

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

    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

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

    export function toTimeoutError(
      err: TimeoutError,
      message: string,
    ): TimeoutError {
      const error = new TimeoutError(message);
    Severity: Major
    Found in src/errors.ts and 1 other location - About 1 hr to fix
    src/errors.ts on lines 59..65

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

    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 executeHandler has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private async executeHandler(message: Message): Promise<Message> {
        let handleMessageTimeoutId: NodeJS.Timeout | undefined = undefined;
    
        try {
          let result;
    Severity: Minor
    Found in src/consumer.ts - About 1 hr to fix

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

        private async poll(): Promise<void> {
          if (this.stopped) {
            logger.debug("cancelling_poll", {
              detail:
                "Poll was called while consumer was stopped, cancelling poll...",
      Severity: Minor
      Found in src/consumer.ts - About 1 hr to fix

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

        function validateOption(option: string, value: number, strict?: boolean): void {
          switch (option) {
            case "batchSize":
              if (value > 100 || value < 1) {
                throw new Error("batchSize must be between 1 and 100");
        Severity: Minor
        Found in src/validation.ts - 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 acknowledgeMessage has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private async acknowledgeMessage(
            acks: Message[],
            retries: Message[],
          ): Promise<AckMessageResponse> {
            try {
        Severity: Minor
        Found in src/consumer.ts - About 1 hr to fix

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

            private async executeHandler(message: Message): Promise<Message> {
              let handleMessageTimeoutId: NodeJS.Timeout | undefined = undefined;
          
              try {
                let result;
          Severity: Minor
          Found in src/consumer.ts - 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 handleQueueResponse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            private async handleQueueResponse(
              response: PullMessagesResponse,
            ): Promise<void> {
              if (!response.success) {
                this.emit("error", new Error("Failed to pull messages"));
          Severity: Minor
          Found in src/consumer.ts - About 25 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