mozilla/publish.webmaker.org

View on GitHub

Showing 102 of 102 total issues

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

  getOne(id) {
    return new this.UsersModel()
    .query()
    .where(this.context.column(`id`), id)
    .then(function(users) { return users[0]; });
Severity: Major
Found in api/modules/users/model.js and 1 other location - About 1 hr to fix
api/modules/publishedFiles/model.js on lines 14..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 73.

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

  getOne(id) {
    return new this.PublishedFilesModel()
    .query()
    .where(this.context.column(`id`), id)
    .then(function(publishedFiles) { return publishedFiles[0]; });
Severity: Major
Found in api/modules/publishedFiles/model.js and 1 other location - About 1 hr to fix
api/modules/users/model.js on lines 11..16

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

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 new this.PublishedFilesModel()
    .query()
    .where(this.context.column(`published_id`), publishedId)
    .whereNull(this.context.column(`file_id`))
    .select(
Severity: Major
Found in api/modules/publishedFiles/model.js and 1 other location - About 1 hr to fix
api/modules/publishedFiles/model.js on lines 80..90

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

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

exports.up = function (knex, Promise) {
  return Promise.resolve()
  .then(function() {
    return knex.schema.createTable('publishedProjects', function(t) {
      t.increments('id');
Severity: Minor
Found in migrations/20150608170220_create_users_projects_files.js - About 1 hr to fix

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

        return new this.PublishedFilesModel()
        .query()
        .where(this.context.column(`published_id`), publishedId)
        .select(this.context.column(`path`))
        .then(function(publishedFiles) {
    Severity: Major
    Found in api/modules/publishedFiles/model.js and 1 other location - About 1 hr to fix
    api/modules/publishedFiles/model.js on lines 69..76

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

    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

      return FilesModel
      .forge(fileData)
      .save()
      .then(function(record) {
        if (!record) {
    Severity: Major
    Found in api/modules/files/controller.js and 1 other location - About 1 hr to fix
    api/classes/base_controller.js on lines 40..53

    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

        return this.Model
        .forge(requestData)
        .save()
        .then(function(record) {
          if (!record) {
    Severity: Major
    Found in api/classes/base_controller.js and 1 other location - About 1 hr to fix
    api/modules/files/controller.js on lines 26..40

    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

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

    exports.up = function (knex, Promise) {
      return Promise.join(
        knex.schema.table('projects', function (t) {
          t.boolean('_readonly');
          t.text('_client');
    Severity: Major
    Found in migrations/20150929010135_add_readonly_client_columns.js and 1 other location - About 1 hr to fix
    migrations/20151103101048_add_date_tracking_published_projects.js on lines 3..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 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

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

    exports.up = function (knex, Promise) {
      return Promise.join(
        knex.schema.table('publishedProjects', function (t) {
          t.text('_date_created');
          t.text('_date_updated');
    migrations/20150929010135_add_readonly_client_columns.js on lines 3..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 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 seed has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.seed = function(knex, Promise) {
      return Promise.join(
        knex('files').insert({
          project_id: 1,
          path: '/spacecats-API/index.js',
    Severity: Minor
    Found in seeds/3_files.js - About 1 hr to fix

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

        run(resourceIdentifier, next) {
          /*
           * Validating an existing token for a resource
           */
          if (!resourceIdentifier) {
      Severity: Minor
      Found in api/classes/base_export_cache.js - About 1 hr to fix

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

        .then(() => loginDb.beginTransaction()
          .then(() => loginDb.query(
              `DELETE FROM \`LoginTokens\` WHERE \`UserId\` = ?`,
              [ id ]
            )
        Severity: Major
        Found in scripts/delete-thimble-account.js and 1 other location - About 1 hr to fix
        scripts/delete-thimble-account.js on lines 120..123

        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

        Function validateCreationPermission has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          static validateCreationPermission(getUserForModelFn) {
            return {
              method(request, reply) {
                const result = Promise.fromCallback(next => {
                  return request.server.methods.user(request.auth.credentials.username, next);
        Severity: Minor
        Found in api/classes/prerequisites.js - About 1 hr to fix

          Function seed has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          exports.seed = function(knex, Promise) {
            return Promise.join(
              knex('projects').insert({
                user_id: 1,
                title: 'spacecats-API',
          Severity: Minor
          Found in seeds/2_projects.js - About 1 hr to fix

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

            .then(() => idDb.connectAsync()
              .then(() => idDb.queryAsync(`DELETE FROM access_tokens WHERE user_id=$1`, [ id ]))
              .then(() => idDb.queryAsync(`DELETE FROM auth_codes WHERE user_id=$1`, [ id ]))
              .then(() => console.log(steps.shift()))
            Severity: Major
            Found in scripts/delete-thimble-account.js and 1 other location - About 1 hr to fix
            scripts/delete-thimble-account.js on lines 125..140

            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

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

              static confirmRecordExists(model, config) {
                config = config || {};
                const dbKey = config.databaseKey || config.requestKey;
                const requestKey = config.requestKey;
            
            
            Severity: Minor
            Found in api/classes/prerequisites.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 validateOwnership has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              static validateOwnership(recordsAreNotModels, fetchUser, userIsNotModel) {
                if (recordsAreNotModels && typeof fetchUser !== `function`) {
                  throw new Error(`fetchUser needs to be a function provided if recordsAreNotModels is set to true`);
                }
            
            
            Severity: Minor
            Found in api/classes/prerequisites.js - About 1 hr to fix

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

                    method(request, reply) {
                      const result = Promise.fromCallback(next => {
                        return request.server.methods.user(request.auth.credentials.username, next);
                      })
                      .then(function(user) {
              Severity: Minor
              Found in api/classes/prerequisites.js - About 1 hr to fix

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

                  static validateOwnership(recordsAreNotModels, fetchUser, userIsNotModel) {
                    if (recordsAreNotModels && typeof fetchUser !== `function`) {
                      throw new Error(`fetchUser needs to be a function provided if recordsAreNotModels is set to true`);
                    }
                
                
                Severity: Minor
                Found in api/classes/prerequisites.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 2 locations. Consider refactoring.
                Open

                const classProps = {
                  typeName: `comics`,
                  filters: {
                    name(queryBuilder, value) {
                      return queryBuilder.whereIn(`name`, value);
                Severity: Major
                Found in api/modules/users/model.js and 1 other location - About 1 hr to fix
                api/modules/publishedFiles/model.js on lines 146..156

                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

                Severity
                Category
                Status
                Source
                Language