auth0-extensions/auth0-source-control-extension-tools

View on GitHub
src/auth0/handlers/actions.js

Summary

Maintainability
F
5 days
Test Coverage

File actions.js has 430 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable consistent-return */
import _ from 'lodash';
import DefaultHandler, { order } from './default';
import log from '../../logger';
import { areArraysEquals } from '../../utils';
Severity: Minor
Found in src/auth0/handlers/actions.js - About 6 hrs to fix

    Function calcChanges has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async calcChanges(actionsAssets, existing) {
        // Calculate the changes required between two sets of assets.
        const update = [];
        let del = [ ...existing ];
        const create = [];
    Severity: Minor
    Found in src/auth0/handlers/actions.js - About 1 hr to fix

      Function processChanges has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        @order('60')
        async processChanges(assets) {
          // eslint-disable-next-line prefer-destructuring
          const actions = assets.actions;
      
      
      Severity: Minor
      Found in src/auth0/handlers/actions.js - About 1 hr to fix

        Function getType has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          async getType() {
            if (this.existing) {
              return this.existing;
            }
        
        
        Severity: Minor
        Found in src/auth0/handlers/actions.js - About 1 hr to fix

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

            async getVersionById(actionId, deployedVersion) {
              // in case client version does not support actionVersions
              if (typeof this.client.actions.getVersions !== 'function') {
                return null;
              }
          Severity: Minor
          Found in src/auth0/handlers/actions.js - 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

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

            async calcDeployedVersionChanges(actionId, actionAsset, existingVersion) {
              const create = [];
          
              if (actionAsset.deployed) {
                const versionToCreate = {
          Severity: Minor
          Found in src/auth0/handlers/actions.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

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

            async calcChanges(actionsAssets, existing) {
              // Calculate the changes required between two sets of assets.
              const update = [];
              let del = [ ...existing ];
              const create = [];
          Severity: Minor
          Found in src/auth0/handlers/actions.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

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

            async getType() {
              if (this.existing) {
                return this.existing;
              }
          
          
          Severity: Minor
          Found in src/auth0/handlers/actions.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

          Avoid too many return statements within this function.
          Open

                  return [];
          Severity: Major
          Found in src/auth0/handlers/actions.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return [];
            Severity: Major
            Found in src/auth0/handlers/actions.js - About 30 mins to fix

              Function actionChanges has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                async actionChanges(action, found) {
                  const actionChanges = {};
              
                  // if action is deployed, should compare against curren_version - calcDeployedVersionChanges method
                  if (!action.deployed) {
              Severity: Minor
              Found in src/auth0/handlers/actions.js - 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

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

                async createVersions(creates) {
                  await this.client.pool
                    .addEachTask({
                      data: creates || [],
                      generator: (item) => this.createVersion(item)
              Severity: Major
              Found in src/auth0/handlers/actions.js and 1 other location - About 6 hrs to fix
              src/auth0/handlers/actions.js on lines 331..347

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

              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 3 locations. Consider refactoring.
              Open

                  await Promise.all(
                    myChanges.map(async (change) => {
                      switch (true) {
                        case change.del && change.del.length > 0:
                          await this.deleteActions(change.del);
              Severity: Major
              Found in src/auth0/handlers/actions.js and 2 other locations - About 6 hrs to fix
              src/auth0/handlers/organizations.js on lines 190..204
              src/auth0/handlers/roles.js on lines 159..173

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

              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

                async createActions(creates) {
                  await this.client.pool
                    .addEachTask({
                      data: creates || [],
                      generator: (item) => this.createAction(item)
              Severity: Major
              Found in src/auth0/handlers/actions.js and 1 other location - About 6 hrs to fix
              src/auth0/handlers/actions.js on lines 247..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 161.

              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 Promise.all(
                    myChanges.map(async (change) => {
                      switch (true) {
                        case change.create && change.create.length > 0:
                          await this.createVersions(changes.create);
              Severity: Major
              Found in src/auth0/handlers/actions.js and 1 other location - About 2 hrs to fix
              src/auth0/handlers/triggers.js on lines 161..171

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

              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 4 locations. Consider refactoring.
              Open

                  try {
                    const actions = await this.client.actions.getAll();
                    // need to get complete current version for each action
                    // the deployed_version inside the action doesn't have all the necessary information
                    this.existing = await Promise.all(
              Severity: Major
              Found in src/auth0/handlers/actions.js and 3 other locations - About 1 hr to fix
              src/auth0/handlers/actions.js on lines 138..152
              src/auth0/handlers/triggers.js on lines 55..83
              src/auth0/handlers/triggers.js on lines 94..105

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

              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 4 locations. Consider refactoring.
              Open

                  try {
                    return await this.client.actions.getVersions({
                      action_id: actionId,
                      version_id: deployedVersion.id
                    });
              Severity: Major
              Found in src/auth0/handlers/actions.js and 3 other locations - About 1 hr to fix
              src/auth0/handlers/actions.js on lines 168..189
              src/auth0/handlers/triggers.js on lines 55..83
              src/auth0/handlers/triggers.js on lines 94..105

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

              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

              function isActionsDisabled(err) {
                const errorBody = _.get(err, 'originalError.response.body') || {};
              
                return (
                  err.statusCode === 403 && errorBody.errorCode === 'feature_not_enabled'
              Severity: Minor
              Found in src/auth0/handlers/actions.js and 1 other location - About 55 mins to fix
              src/auth0/handlers/triggers.js on lines 24..30

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

              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 3 locations. Consider refactoring.
              Open

                  log.info(
                    `Start processChanges for actions [delete:${changes.del.length}] [update:${changes.update.length}], [create:${changes.create.length}]`
                  );
              Severity: Major
              Found in src/auth0/handlers/actions.js and 2 other locations - About 50 mins to fix
              src/auth0/handlers/organizations.js on lines 186..186
              src/auth0/handlers/roles.js on lines 157..157

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

              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 4 locations. Consider refactoring.
              Open

                  if (
                    !this.client.actions
                    || typeof this.client.actions.getAll !== 'function'
                  ) {
                    return [];
              Severity: Major
              Found in src/auth0/handlers/actions.js and 3 other locations - About 30 mins to fix
              src/auth0/handlers/hooks.js on lines 143..145
              src/auth0/handlers/roles.js on lines 124..126
              src/auth0/handlers/triggers.js on lines 46..51

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

              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

              There are no issues that match your filters.

              Category
              Status