ForestAdmin/toolbelt

View on GitHub

Showing 166 of 172 total issues

Function TableConstraintsGetter has 292 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function TableConstraintsGetter(databaseConnection, schema) {
  const queryInterface = databaseConnection.getQueryInterface();

  this.perform = async table => {
    let query = null;

    Function perform has 289 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      this.perform = async table => {
        let query = null;
        const replacements = { table };
    
        switch (queryInterface.sequelize.options.dialect) {

      Function Authenticator has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
      Open

      function Authenticator({
        logger,
        api,
        chalk,
        inquirer,
      Severity: Minor
      Found in src/services/authenticator.js - About 1 day 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

      File sequelize-tables-analyzer.js has 443 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const { inject } = require('@forestadmin/context');
      const P = require('bluebird');
      const { plural, singular } = require('pluralize');
      const ColumnTypeGetter = require('./sequelize-column-type-getter');
      const DefaultValueExpression = require('./sequelize-default-value');
      Severity: Minor
      Found in src/services/schema/update/analyzer/sequelize-tables-analyzer.js - About 6 hrs to fix

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

          async getConfig() {
            const envSecret = this.env.FOREST_ENV_SECRET;
            const parsed = await this.parse(SwitchCommand);
            const commandOptions = { ...parsed.flags, ...parsed.args, envSecret };
        
        
        Severity: Major
        Found in src/commands/switch.js and 1 other location - About 5 hrs to fix
        src/commands/deploy.js on lines 22..36

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

        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

              apimap.data = apimap.data.map(collection => {
                collection = reorderKeysChild(collection);
                collection.attributes = reorderKeysCollection(collection.attributes);
                if (collection.attributes.fields) {
                  collection.attributes.fields = sortArrayOfFields(collection.attributes.fields);
        Severity: Major
        Found in src/services/apimap-sorter.js and 1 other location - About 5 hrs to fix
        src/services/apimap-sorter.js on lines 84..94

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

        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 getConfig() {
            const envSecret = this.env.FOREST_ENV_SECRET;
            const parsed = await this.parse(DeployCommand);
            const commandOptions = { ...parsed.flags, ...parsed.args, envSecret };
            const config = await withCurrentProject({ ...this.env, ...commandOptions });
        Severity: Major
        Found in src/commands/deploy.js and 1 other location - About 5 hrs to fix
        src/commands/switch.js on lines 53..68

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

        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

                apimap.included = apimap.included.map(include => {
                  include = reorderKeysChild(include);
                  include.attributes = reorderKeysCollection(include.attributes);
                  if (include.attributes.fields) {
                    include.attributes.fields = sortArrayOfFields(include.attributes.fields);
        Severity: Major
        Found in src/services/apimap-sorter.js and 1 other location - About 5 hrs to fix
        src/services/apimap-sorter.js on lines 69..79

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

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

        function ColumnTypeGetter(databaseConnection, schema, allowWarning = true) {
          const queryInterface = databaseConnection.getQueryInterface();
        
          function isDialect(dialect) {
            return queryInterface.sequelize.options.dialect === dialect;
        Severity: Major
        Found in src/services/schema/update/analyzer/sequelize-column-type-getter.js - About 5 hrs to fix

          Function mapCollection has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
          Open

          function mapCollection(keys = this, emitFunction, store) {
            // this block is to inject the emit function when this code is running locally
            var emitAction;
            if (emitFunction && store) {
              emitAction = function emit(key, value) {
          Severity: Minor
          Found in src/services/schema/update/analyzer/mongo-collections-analyzer.js - About 4 hrs 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

          File agent-nodejs.ts has 328 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import type { Config, DbConfig } from '../../interfaces/project-create-interface';
          import type { Language } from '../../utils/languages';
          import type Strings from '../../utils/strings';
          import type Lodash from 'lodash';
          
          
          Severity: Minor
          Found in src/services/dumpers/agent-nodejs.ts - About 3 hrs to fix

            File forest-express.js has 327 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            const { URL } = require('url');
            const { plural, singular } = require('pluralize');
            const IncompatibleLianaForUpdateError = require('../../errors/dumper/incompatible-liana-for-update-error');
            const InvalidForestCLIProjectStructureError = require('../../errors/dumper/invalid-forest-cli-project-structure-error');
            const AbstractDumper = require('./abstract-dumper').default;
            Severity: Minor
            Found in src/services/dumpers/forest-express.js - About 3 hrs to fix

              Function EnvironmentManager has 96 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function EnvironmentManager(config) {
                const { assertPresent, authenticator, env, keyGenerator } = Context.inject();
                assertPresent({ authenticator, env, keyGenerator });
              
                this.listEnvironments = async () => {
              Severity: Major
              Found in src/services/environment-manager.js - About 3 hrs to fix

                File mongo-collections-analyzer.js has 323 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                const P = require('bluebird');
                const { ObjectId } = require('mongodb');
                
                const EmptyDatabaseError = require('../../../../errors/database/empty-database-error');
                
                
                Severity: Minor
                Found in src/services/schema/update/analyzer/mongo-collections-analyzer.js - About 3 hrs to fix

                  Function SchemaSerializer has 93 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function SchemaSerializer() {
                    // WARNING: Attributes declaration order is important for .forestadmin-schema.json format.
                    const options = {
                      id: 'name',
                      // TODO: Remove nameOld attribute once the lianas versions older than 2.0.0 are minority.
                  Severity: Major
                  Found in src/serializers/schema.js - About 3 hrs to fix

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

                      constructor(argv, config, plan) {
                        super(argv, config, plan);
                        const { assertPresent, env, path, schemaService } = this.context;
                        assertPresent({
                          env,
                    Severity: Major
                    Found in src/commands/schema/update.js and 2 other locations - About 3 hrs to fix
                    src/commands/environments/delete.js on lines 6..17
                    src/commands/schema/apply.js on lines 8..15

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

                    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, fs, joi } = this.context;
                        assertPresent({ env, fs, joi });
                        this.env = env;
                    Severity: Major
                    Found in src/commands/schema/apply.js and 2 other locations - About 3 hrs to fix
                    src/commands/environments/delete.js on lines 6..17
                    src/commands/schema/update.js on lines 6..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 108.

                    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, chalk, env, inquirer } = this.context;
                        assertPresent({
                          chalk,
                    Severity: Major
                    Found in src/commands/environments/delete.js and 2 other locations - About 3 hrs to fix
                    src/commands/schema/apply.js on lines 8..15
                    src/commands/schema/update.js on lines 6..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 108.

                    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 Api has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function Api({
                      pkg,
                      env,
                      superagent: agent,
                      applicationTokenSerializer,
                    Severity: Minor
                    Found in src/services/api.js - About 3 hrs 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

                      this.getProjectForDevWorkflow = async () => {
                        const authToken = authenticator.getAuthToken();
                    
                        return agent
                          .get(`${env.FOREST_SERVER_URL}/api/projects/${config.projectId}/dev-workflow`)
                    Severity: Major
                    Found in src/services/project-manager.js and 1 other location - About 3 hrs to fix
                    src/services/project-manager.js on lines 52..60

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

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language