ForestAdmin/toolbelt

View on GitHub

Showing 166 of 172 total issues

Function addObjectSchema has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function addObjectSchema(type, parentSchema, currentKey) {
  const isTypeAnArray = Array.isArray(type);

  if (parentSchema[currentKey] !== undefined) {
    if (areSchemaTypesMixed(parentSchema[currentKey], type)) {
Severity: Minor
Found in src/services/schema/update/analyzer/mongo-embedded-analyzer.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 ApimapSorter has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function ApimapSorter(apimap) {
  const { assertPresent, logger, lodash } = inject();
  assertPresent({ logger, lodash });

  function sortArrayOfObjects(array) {
Severity: Minor
Found in src/services/apimap-sorter.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

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

  constructor(argv, config, plan) {
    super(argv, config, plan);
    const { assertPresent, authenticator } = this.context;
    assertPresent({ authenticator });
    this.authenticator = authenticator;
Severity: Major
Found in src/commands/login.js and 2 other locations - About 1 hr to fix
src/commands/environments/update.js on lines 6..11
src/commands/logout.js on lines 4..9

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

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

  constructor(argv, config, plan) {
    super(argv, config, plan);
    const { assertPresent, authenticator } = this.context;
    assertPresent({ authenticator });
    this.authenticator = authenticator;
Severity: Major
Found in src/commands/logout.js and 2 other locations - About 1 hr to fix
src/commands/environments/update.js on lines 6..11
src/commands/login.js on lines 5..10

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

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

  constructor(argv, config, plan) {
    super(argv, config, plan);
    const { assertPresent, env } = this.context;
    assertPresent({ env });
    this.env = env;
Severity: Major
Found in src/commands/environments/update.js and 2 other locations - About 1 hr to fix
src/commands/login.js on lines 5..10
src/commands/logout.js on lines 4..9

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

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

function createReference(
  tableName,
  existingsReferences,
  association,
  foreignKey,
Severity: Minor
Found in src/services/schema/update/analyzer/sequelize-tables-analyzer.js - About 1 hr to fix

    Function SchemaSender has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function SchemaSender(serializedSchema, secret, authenticationToken, oclifExit) {
      /**
       * @function
       * @returns {Promise<number | undefined>}
       */
    Severity: Minor
    Found in src/services/schema-sender.js - About 1 hr to fix

      Function runAuthenticated has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async runAuthenticated() {
          const parsed = await this.parse(PushCommand);
          const envSecret = this.env.FOREST_ENV_SECRET;
          const commandOptions = { ...parsed.flags, ...parsed.args, envSecret };
          let config;
      Severity: Minor
      Found in src/commands/push.js - About 1 hr to fix

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

            return agent
              .get(`${env.FOREST_SERVER_URL}/api/projects?envSecret${includeLegacyParameter}`)
              .set('Authorization', `Bearer ${authToken}`)
              .set('forest-secret-key', envSecret)
              .send()
        Severity: Major
        Found in src/services/project-manager.js and 1 other location - About 1 hr to fix
        src/services/environment-manager.js on lines 26..31

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

        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

            return agent
              .get(`${env.FOREST_SERVER_URL}/api/environments/${environmentId}`)
              .set('Authorization', `Bearer ${authToken}`)
              .set('forest-environment-id', environmentId)
              .send()
        Severity: Major
        Found in src/services/environment-manager.js and 1 other location - About 1 hr to fix
        src/services/project-manager.js on lines 44..49

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

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

          constructor(context) {
            super(context);
        
            const {
              assertPresent,
        Severity: Minor
        Found in src/services/dumpers/forest-express.js - About 1 hr to fix

          Function handleBranchError has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          async function handleBranchError(rawError) {
            const { message, meta } = handleErrorWithMeta(rawError);
            switch (message) {
              // NOTICE: When no env/project can be found through envSecret
              case 'Not Found':
          Severity: Minor
          Found in src/services/branch-manager.js - About 1 hr to fix

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

              async _connectToDatabases(databasesConfig) {
                this.spinner.start({ text: 'Connecting to your database(s)' });
                const databasesConnectionPromise = this.database.connectFromDatabasesConfig(databasesConfig);
                return this.spinner.attachToPromise(databasesConnectionPromise);
              }
            Severity: Major
            Found in src/services/schema/schema-service.js and 1 other location - About 1 hr to fix
            src/services/schema/schema-service.js on lines 69..73

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

            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 _disconnectFromDatabases(databaseConnections) {
                this.spinner.start({ text: 'Disconnecting from your database(s)' });
                const databasesConnectionPromise = this.database.disconnectFromDatabases(databaseConnections);
                return this.spinner.attachToPromise(databasesConnectionPromise);
              }
            Severity: Major
            Found in src/services/schema/schema-service.js and 1 other location - About 1 hr to fix
            src/services/schema/schema-service.js on lines 63..67

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

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

              this.perform = () => {
                const { env, logger } = Context.inject();
            
                return agent
                  .post(`${env.FOREST_SERVER_URL}/forest/apimaps`)
            Severity: Minor
            Found in src/services/schema-sender.js - About 1 hr to fix

              Function notifyError has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async notifyError(code = 'unknown_error', message = null, context = undefined) {
                  if (!this.applicationName || !this.command) {
                    return;
                  }
              
              
              Severity: Minor
              Found in src/utils/event-sender.js - About 1 hr to fix

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

                function deserialize(error) {
                  if (!error || !error.status) {
                    throw new Error('Wrong API Error format');
                  }
                
                
                Severity: Minor
                Found in src/deserializers/api-error.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 analyzeMongoCollections has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  async analyzeMongoCollections(databaseConnection) {
                    const collections = await databaseConnection.collections();
                    if (collections.length === 0) {
                      this.restoreDefaultState();
                      throw new EmptyDatabaseError('no collections found', {
                Severity: Minor
                Found in src/services/schema/update/analyzer/mongo-collections-analyzer.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

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

                  return agent
                    .put(`${env.FOREST_SERVER_URL}/api/environments`)
                    .set('Authorization', `Bearer ${authToken}`)
                    .set('forest-secret-key', `${environmentSecret}`)
                    .send(EnvironmentSerializer.serialize({ currentBranchId: id }));
                Severity: Major
                Found in src/services/branch-manager.js and 4 other locations - About 1 hr to fix
                src/services/branch-manager.js on lines 60..67
                src/services/branch-manager.js on lines 75..79
                src/services/branch-manager.js on lines 99..103
                src/services/environment-manager.js on lines 101..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 63.

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

                  writePackageJson(dbDialect, appName) {
                    const orm = dbDialect === 'mongodb' ? 'mongoose' : 'sequelize';
                    const dependencies = {
                      'body-parser': '1.19.0',
                      chalk: '~1.1.3',
                Severity: Minor
                Found in src/services/dumpers/forest-express.js - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language