ForestAdmin/lumber

View on GitHub

Showing 79 of 79 total issues

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));
Severity: Major
Found in services/analyzer/mongo-references-analyzer.js and 1 other location - About 1 hr to fix
services/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 writeModel has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

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

    Function createAccount has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async createAccount() {
        this.logger.info('Create an account:');
        const authConfig = await this.inquirer.prompt([{
          type: 'input',
          name: 'firstName',
    Severity: Minor
    Found in services/authenticator.js - About 1 hr to fix

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

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

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

                validate: (port) => {
                  if (!/^\d+$/.test(port)) {
                    return 'The port must be a number.';
                  }
        
        
        Severity: Major
        Found in services/prompter/database-prompts.js and 1 other location - About 1 hr to fix
        services/prompter/application-prompts.js on lines 48..56

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

        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

                  validate: (port) => {
                    if (!/^\d+$/.test(port)) {
                      return 'The port must be a number.';
                    }
        
        
        Severity: Major
        Found in services/prompter/application-prompts.js and 1 other location - About 1 hr to fix
        services/prompter/database-prompts.js on lines 125..133

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

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

        function createReference(
          tableName,
          existingsReferences,
          association,
          foreignKey,
        Severity: Minor
        Found in services/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

        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 services/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 handlePort has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          handlePort() {
            if (this.isOptionRequested('appPort')) {
              this.envConfig.appPort = this.program.applicationPort;
              if (!this.envConfig.appPort) {
                this.prompts.push({
        Severity: Minor
        Found in services/prompter/application-prompts.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 connectToMongodb has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          connectToMongodb(options, isSSL) {
            let connectionOptionsMongoClient = options.connectionOptions;
            if (!connectionOptionsMongoClient) {
              connectionOptionsMongoClient = {
                useNewUrlParser: true,
        Severity: Minor
        Found in services/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 createProject has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          async createProject(config, sessionToken, project) {
            let newProject;
        
            try {
              newProject = await this.agent
        Severity: Minor
        Found in services/api.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 writePackageJson has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          writePackageJson(projectPath, { dbDialect, appName }) {
            const orm = dbDialect === 'mongodb' ? 'mongoose' : 'sequelize';
            const dependencies = {
              'body-parser': '1.19.0',
              chalk: '~1.1.3',
        Severity: Minor
        Found in services/dumper.js - About 1 hr to fix

          Function createReference has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

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

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

            function mapCollection() {
              function allItemsAreObjectIDs(array) {
                if (!array.length) return false;
                var itemToCheckCount = array.length > 3 ? 3 : array.length;
                var arrayOfObjectIDs = true;
            Severity: Minor
            Found in services/analyzer/mongo-collections-analyzer.js - About 1 hr to fix

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

                {
                  _id: ObjectID(),
                  name: 'James Cameron',
                  propArrayOfObjects: [
                    {
              test-fixtures/mongo/nested-array-of-objects-model.js on lines 4..19

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

              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

                {
                  _id: ObjectID(),
                  name: 'James Cameron',
                  propArrayOfObjects: [
                    {
              Severity: Major
              Found in test-fixtures/mongo/nested-array-of-objects-model.js and 1 other location - About 1 hr to fix
              test-fixtures/mongo/multiple-nested-array-of-objects-model.js on lines 4..19

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

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

                handleHostname() {
                  if (this.isOptionRequested('appHostname')) {
                    this.envConfig.appHostname = this.program.applicationHost;
                    if (!this.envConfig.appHostname) {
                      this.prompts.push({
              Severity: Minor
              Found in services/prompter/application-prompts.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 createAccount has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                async createAccount() {
                  this.logger.info('Create an account:');
                  const authConfig = await this.inquirer.prompt([{
                    type: 'input',
                    name: 'firstName',
              Severity: Minor
              Found in services/authenticator.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 writeModel has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                writeModel(projectPath, config, table, fields, references, options = {}) {
                  const { underscored } = options;
                  let modelPath = `models/${Dumper.tableToFilename(table)}.js`;
                  if (config.useMultiDatabase) {
                    modelPath = `models/${config.modelsExportPath}/${Dumper.tableToFilename(table)}.js`;
              Severity: Minor
              Found in services/dumper.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

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

              const buildReference = (collectionName, referencedCollection, field) => {
                if (referencedCollection) {
                  return {
                    from: { collectionName, fieldName: field.name },
                    to: { collectionName: referencedCollection },
              Severity: Major
              Found in services/analyzer/mongo-references-analyzer.js and 1 other location - About 1 hr to fix
              services/analyzer/mongo-hasmany-analyzer.js on lines 24..32

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

              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