ForestAdmin/toolbelt

View on GitHub

Showing 166 of 172 total issues

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

  constructor({ assertPresent, mongoAnalyzer, sequelizeAnalyzer, terminator }) {
    assertPresent({
      mongoAnalyzer,
      sequelizeAnalyzer,
      terminator,
Severity: Major
Found in src/services/schema/update/analyzer/database-analyzer.js and 5 other locations - About 2 hrs to fix
src/renderers/branches.js on lines 4..13
src/renderers/environments.js on lines 4..13
src/renderers/project.js on lines 4..13
src/renderers/projects.js on lines 4..13
src/services/schema/update/database.js on lines 2..11

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

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

  constructor({ assertPresent, mongodb, Sequelize, terminator }) {
    assertPresent({
      mongodb,
      Sequelize,
      terminator,
Severity: Major
Found in src/services/schema/update/database.js and 5 other locations - About 2 hrs to fix
src/renderers/branches.js on lines 4..13
src/renderers/environments.js on lines 4..13
src/renderers/project.js on lines 4..13
src/renderers/projects.js on lines 4..13
src/services/schema/update/analyzer/database-analyzer.js on lines 4..13

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

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

  constructor({ assertPresent, chalk, logger, Table }) {
    assertPresent({
      chalk,
      logger,
      Table,
Severity: Major
Found in src/renderers/environments.js and 5 other locations - About 2 hrs to fix
src/renderers/branches.js on lines 4..13
src/renderers/project.js on lines 4..13
src/renderers/projects.js on lines 4..13
src/services/schema/update/analyzer/database-analyzer.js on lines 4..13
src/services/schema/update/database.js on lines 2..11

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

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

ForestExpress has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

class ForestExpress extends AbstractDumper {
  templateFolder = 'forest-express';

  constructor(context) {
    super(context);
Severity: Minor
Found in src/services/dumpers/forest-express.js - About 2 hrs to fix

    Function readSchema has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      readSchema() {
        this.logger.log('Reading ".forestadmin-schema.json" from current directory...');
        const filename = '.forestadmin-schema.json';
    
        if (!this.fs.existsSync(filename)) {
    Severity: Major
    Found in src/commands/schema/apply.js - About 2 hrs to fix

      Function ProjectManager has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function ProjectManager(config) {
        const { assertPresent, authenticator, env, jwtDecode, lodash } = Context.inject();
        assertPresent({ authenticator, env, jwtDecode, lodash });
      
        function deserialize(response) {
      Severity: Major
      Found in src/services/project-manager.js - About 2 hrs to fix

        Function createAllReferences has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function createAllReferences(databaseSchema, schemaGenerated) {
          const references = {};
          Object.keys(databaseSchema).forEach(tableName => {
            references[tableName] = [];
          });
        Severity: Major
        Found in src/services/schema/update/analyzer/sequelize-tables-analyzer.js - About 2 hrs to fix

          Function MysqlTableConstraintsGetter has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function MysqlTableConstraintsGetter(databaseConnection) {
            const queryInterface = databaseConnection.getQueryInterface();
          
            // NOTICE: provide an array of array. Each inner array representing a (possibly composite) unique
            //         index
          Severity: Minor
          Found in src/services/schema/update/analyzer/mysql-table-constraints-getter.js - About 2 hrs to fix

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

              async runAuthenticated() {
                const parsed = await this.parse(DeleteCommand);
                const config = { ...this.env, ...parsed.flags, ...parsed.args };
                const manager = new EnvironmentManager(config);
            
            
            Severity: Minor
            Found in src/commands/environments/delete.js - About 1 hr to fix

              Function connectToMongodb has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                connectToMongodb(options, isSSL) {
                  let connectionOptionsMongoClient = options.connectionOptions;
                  if (!connectionOptionsMongoClient) {
                    connectionOptionsMongoClient = {
                      useNewUrlParser: true,
              Severity: Minor
              Found in src/services/schema/update/database.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 constructor has 47 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                constructor({
                  assertPresent,
                  logger,
                  detectReferences,
                  applyReferences,
              Severity: Minor
              Found in src/services/schema/update/analyzer/mongo-collections-analyzer.js - About 1 hr to fix

                Function writeModel has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  writeModel(config, table, fields, references, options = {}) {
                    const { underscored } = options;
                    let modelPath = `models/${this.tableToFilename(table)}.js`;
                    if (config.appConfig.useMultiDatabase) {
                      modelPath = `models/${config.appConfig.modelsExportPath}/${this.tableToFilename(table)}.js`;
                Severity: Minor
                Found in src/services/dumpers/forest-express.js - About 1 hr to fix

                  Function createFiles has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    async createFiles(config, schema) {
                      const { isUpdate, useMultiDatabase, modelsExportPath } = config.appConfig;
                  
                      await this.mkdirp(`${this.projectPath}/routes`);
                      await this.mkdirp(`${this.projectPath}/forest`);
                  Severity: Minor
                  Found in src/services/dumpers/forest-express.js - About 1 hr to fix

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

                    const detectReference = (databaseConnection, field, collectionName) =>
                      pickSampleValues(databaseConnection, collectionName, field)
                        .then(samples => findCollectionMatchingSamples(databaseConnection, samples))
                        .then(matches => filterReferenceCollection(matches))
                        .then(referencedCollection => buildReference(collectionName, referencedCollection, field));
                    src/services/schema/update/analyzer/mongo-references-analyzer.js on lines 31..35

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 70.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

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

                    const detectReference = (databaseConnection, field, collectionName) =>
                      pickSampleValues(databaseConnection, collectionName, field)
                        .then(samples => findCollectionMatchingSamples(databaseConnection, samples))
                        .then(matches => filterReferenceCollection(matches))
                        .then(referencedCollection => buildReference(collectionName, referencedCollection, field));
                    src/services/schema/update/analyzer/mongo-hasmany-analyzer.js on lines 34..38

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 70.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

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

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

                      Function analyzeMongoCollections has 43 lines of code (exceeds 25 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

                        Function mapCollection has 42 lines of code (exceeds 25 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 1 hr to fix

                          Function createProject has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            this.createProject = async (config, sessionToken, project) => {
                              let newProject;
                          
                              try {
                                newProject = await agent
                          Severity: Minor
                          Found in src/services/api.js - About 1 hr to fix

                            Function createReference has a Cognitive Complexity of 13 (exceeds 5 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

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Severity
                            Category
                            Status
                            Source
                            Language