imqueue/pg-pubsub

View on GitHub

Showing 17 of 20 total issues

File PgIpLock.ts has 297 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * Copyright (c) 2018, imqueue.com <support@imqueue.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
Severity: Minor
Found in src/PgIpLock.ts - About 3 hrs to fix

    File PgPubSub.ts has 282 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /*!
     * Copyright (c) 2018, imqueue.com <support@imqueue.com>
     *
     * Permission to use, copy, modify, and/or distribute this software for any
     * purpose with or without fee is hereby granted, provided that the above
    Severity: Minor
    Found in src/PgPubSub.ts - About 2 hrs to fix

      Function createChannelLock has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private async createChannelLock(): Promise<void> {
              await this.options.pgClient.query(`
                  DO $$
                      BEGIN
                          IF EXISTS (
      Severity: Minor
      Found in src/PgIpLock.ts - About 1 hr to fix

        Function createUniqueLock has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private async createUniqueLock(): Promise<void> {
                await this.options.pgClient.query(`
                    DO $$
                        BEGIN
                            IF NOT EXISTS (
        Severity: Minor
        Found in src/PgIpLock.ts - About 1 hr to fix

          Function init has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public async init(): Promise<void> {
                  if (!await this.schemaExists()) {
                      try {
                          await this.createSchema();
                          await Promise.all([this.createLock(), this.createDeadlockCheck()]);
          Severity: Minor
          Found in src/PgIpLock.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

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

                      await this.options.pgClient.query(`
                          DELETE FROM ${this.schemaName}.lock
                          WHERE channel=${literal(this.channel)}
                      `);
          Severity: Minor
          Found in src/PgIpLock.ts and 1 other location - About 40 mins to fix
          src/PgIpLock.ts on lines 260..263

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

          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

                      await this.options.pgClient.query(`
                          DELETE FROM ${this.schemaName}.lock
                          WHERE id=${literal(this.uniqueKey)}
                      `);
          Severity: Minor
          Found in src/PgIpLock.ts and 1 other location - About 40 mins to fix
          src/PgIpLock.ts on lines 270..273

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

          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

                  const skip = RX_LOCK_CHANNEL.test(notification.channel) || (
                      this.options.filtered && this.processId === notification.processId
                  );
          Severity: Minor
          Found in src/PgPubSub.ts and 1 other location - About 35 mins to fix
          src/PgPubSub.ts on lines 561..563

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

          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

                  const skip = RX_LOCK_CHANNEL.test(notification.channel) || (
                      this.options.filtered && this.processId === notification.processId
                  );
          Severity: Minor
          Found in src/PgPubSub.ts and 1 other location - About 35 mins to fix
          src/PgPubSub.ts on lines 593..595

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

          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

          Forbidden bitwise operation
          Open

                  if (!~PgIpLock.instances.indexOf(this)) {
          Severity: Minor
          Found in src/PgIpLock.ts by tslint

          Rule: no-bitwise

          Disallows bitwise operators.

          Specifically, the following bitwise operators are banned: &, &=, |, |=, ^, ^=, <<, <<=, >>, >>=, >>>, >>>=, and ~. This rule does not ban the use of & and | for intersection and union types.

          Rationale

          Bitwise operators are often typos - for example bool1 & bool2 instead of bool1 && bool2. They also can be an indicator of overly clever code which decreases maintainability.

          Config

          Not configurable.

          Examples
          "no-bitwise": true

          For more information see this page.

          unused expression, expected an assignment or function call
          Open

                      !uniqueKey && lock.onRelease(chan => this.listen(chan));
          Severity: Minor
          Found in src/PgPubSub.ts by tslint

          Rule: no-unused-expression

          Disallows unused expression statements.

          Unused expressions are expression statements which are not assignments or function calls (and thus usually no-ops).

          Rationale

          Detects potential errors where an assignment or function call was intended.

          Config

          Three arguments may be optionally provided:

          • allow-fast-null-checks allows to use logical operators to perform fast null checks and perform method or function calls for side effects (e.g. e && e.preventDefault()).
          • allow-new allows 'new' expressions for side effects (e.g. new ModifyGlobalState();.
          • allow-tagged-template allows tagged templates for side effects (e.g. this.add\foo`;`.
          Examples
          "no-unused-expression": true
          "no-unused-expression": true,allow-fast-null-checks
          Schema
          {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "allow-fast-null-checks",
                "allow-new",
                "allow-tagged-template"
              ]
            },
            "minLength": 0,
            "maxLength": 3
          }

          For more information see this page.

          Unnecessary semicolon
          Open

          export interface JsonMap { [key: string]: AnyJson };
          Severity: Minor
          Found in src/types/AnyJson.ts by tslint

          Rule: semicolon

          Enforces consistent semicolon usage at the end of every statement.

          Notes
          • Has Fix

          Config

          One of the following arguments must be provided:

          • "always" enforces semicolons at the end of every statement.
          • "never" disallows semicolons at the end of every statement except for when they are necessary.

          The following arguments may be optionally provided:

          • "ignore-interfaces" skips checking semicolons at the end of interface members.
          • "ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
          • "strict-bound-class-methods" disables any special handling of bound class methods and treats them as any other assignment. This option overrides "ignore-bound-class-methods".
          Examples
          "semicolon": true,always
          "semicolon": true,never
          "semicolon": true,always,ignore-interfaces
          "semicolon": true,always,ignore-bound-class-methods
          Schema
          {
            "type": "array",
            "items": [
              {
                "type": "string",
                "enum": [
                  "always",
                  "never"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "ignore-interfaces"
                ]
              }
            ],
            "additionalItems": false
          }

          For more information see this page.

          unused expression, expected an assignment or function call
          Open

              timer && clearTimeout(timer);
          Severity: Minor
          Found in src/PgIpLock.ts by tslint

          Rule: no-unused-expression

          Disallows unused expression statements.

          Unused expressions are expression statements which are not assignments or function calls (and thus usually no-ops).

          Rationale

          Detects potential errors where an assignment or function call was intended.

          Config

          Three arguments may be optionally provided:

          • allow-fast-null-checks allows to use logical operators to perform fast null checks and perform method or function calls for side effects (e.g. e && e.preventDefault()).
          • allow-new allows 'new' expressions for side effects (e.g. new ModifyGlobalState();.
          • allow-tagged-template allows tagged templates for side effects (e.g. this.add\foo`;`.
          Examples
          "no-unused-expression": true
          "no-unused-expression": true,allow-fast-null-checks
          Schema
          {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "allow-fast-null-checks",
                "allow-new",
                "allow-tagged-template"
              ]
            },
            "minLength": 0,
            "maxLength": 3
          }

          For more information see this page.

          Missing semicolon
          Open

          export interface JsonMap { [key: string]: AnyJson };
          Severity: Minor
          Found in src/types/AnyJson.ts by tslint

          Rule: semicolon

          Enforces consistent semicolon usage at the end of every statement.

          Notes
          • Has Fix

          Config

          One of the following arguments must be provided:

          • "always" enforces semicolons at the end of every statement.
          • "never" disallows semicolons at the end of every statement except for when they are necessary.

          The following arguments may be optionally provided:

          • "ignore-interfaces" skips checking semicolons at the end of interface members.
          • "ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
          • "strict-bound-class-methods" disables any special handling of bound class methods and treats them as any other assignment. This option overrides "ignore-bound-class-methods".
          Examples
          "semicolon": true,always
          "semicolon": true,never
          "semicolon": true,always,ignore-interfaces
          "semicolon": true,always,ignore-bound-class-methods
          Schema
          {
            "type": "array",
            "items": [
              {
                "type": "string",
                "enum": [
                  "always",
                  "never"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "ignore-interfaces"
                ]
              }
            ],
            "additionalItems": false
          }

          For more information see this page.

          Forbidden bitwise operation
          Open

                  return !!~this.activeChannels().indexOf(channel);
          Severity: Minor
          Found in src/PgPubSub.ts by tslint

          Rule: no-bitwise

          Disallows bitwise operators.

          Specifically, the following bitwise operators are banned: &, &=, |, |=, ^, ^=, <<, <<=, >>, >>=, >>>, >>>=, and ~. This rule does not ban the use of & and | for intersection and union types.

          Rationale

          Bitwise operators are often typos - for example bool1 & bool2 instead of bool1 && bool2. They also can be an indicator of overly clever code which decreases maintainability.

          Config

          Not configurable.

          Examples
          "no-bitwise": true

          For more information see this page.

          unused expression, expected an assignment or function call
          Open

                      !this.acquireTimer && (this.acquireTimer = setInterval(
                          () => !this.acquired && this.acquire(),
                          this.options.acquireInterval,
                      ));
          Severity: Minor
          Found in src/PgIpLock.ts by tslint

          Rule: no-unused-expression

          Disallows unused expression statements.

          Unused expressions are expression statements which are not assignments or function calls (and thus usually no-ops).

          Rationale

          Detects potential errors where an assignment or function call was intended.

          Config

          Three arguments may be optionally provided:

          • allow-fast-null-checks allows to use logical operators to perform fast null checks and perform method or function calls for side effects (e.g. e && e.preventDefault()).
          • allow-new allows 'new' expressions for side effects (e.g. new ModifyGlobalState();.
          • allow-tagged-template allows tagged templates for side effects (e.g. this.add\foo`;`.
          Examples
          "no-unused-expression": true
          "no-unused-expression": true,allow-fast-null-checks
          Schema
          {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "allow-fast-null-checks",
                "allow-new",
                "allow-tagged-template"
              ]
            },
            "minLength": 0,
            "maxLength": 3
          }

          For more information see this page.

          unused expression, expected an assignment or function call
          Open

                      this.options.logger && this.options.logger.error &&
                      this.options.logger.error(err);
          Severity: Minor
          Found in src/PgIpLock.ts by tslint

          Rule: no-unused-expression

          Disallows unused expression statements.

          Unused expressions are expression statements which are not assignments or function calls (and thus usually no-ops).

          Rationale

          Detects potential errors where an assignment or function call was intended.

          Config

          Three arguments may be optionally provided:

          • allow-fast-null-checks allows to use logical operators to perform fast null checks and perform method or function calls for side effects (e.g. e && e.preventDefault()).
          • allow-new allows 'new' expressions for side effects (e.g. new ModifyGlobalState();.
          • allow-tagged-template allows tagged templates for side effects (e.g. this.add\foo`;`.
          Examples
          "no-unused-expression": true
          "no-unused-expression": true,allow-fast-null-checks
          Schema
          {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "allow-fast-null-checks",
                "allow-new",
                "allow-tagged-template"
              ]
            },
            "minLength": 0,
            "maxLength": 3
          }

          For more information see this page.

          Severity
          Category
          Status
          Source
          Language