mozilla/publish.webmaker.org

View on GitHub

Showing 102 of 102 total issues

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

const classProps = {
  typeName: `publishedFiles`,
  filters: {
    project_id(queryBuilder, value) {
      return queryBuilder.whereIn(`project_id`, value);
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 29..39

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

  createOrUpdatePublishedProject() {
    const project = this.project;
    const projectData = {
      title: project.title,
      tags: project.tags,
Severity: Minor
Found in api/classes/publisher.js - About 1 hr to fix

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

          method(request, reply) {
            const records = request.pre.records;
            const resource = recordsAreNotModels ? records[0] : records.models[0];
            const authenticatedUser = request.pre.user;
    
    
    Severity: Minor
    Found in api/classes/prerequisites.js - About 1 hr to fix

      Function _getAllDataFromDB has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _getAllDataFromDB(metaKey, bufferKeyPrefix, publishedProjectId) {
          const publishedFiles = [];
          const publishedFilesMeta = [];
      
          // Get all the metadata and buffers from the db with one query
      Severity: Minor
      Found in api/modules/publishedFiles/cache.js - About 1 hr to fix

        Function up has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        exports.up = function (knex, Promise) {
          return knex('publishedProjects')
          .whereNull('date_created')
          .orWhereNull('date_updated')
          .select('id', 'date_created', 'date_updated')

          Function login has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            login(request, reply) {
              if (request.payload.name !== request.auth.credentials.username) {
                return reply(
                  Errors.generateErrorResponse(
                    Boom.unauthorized(null, {
          Severity: Minor
          Found in api/modules/users/controller.js - About 1 hr to fix

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

              deleteOne(id) {
                return new this.PublishedFilesModel()
                .query()
                .where(this.context.column(`id`), id)
                .del();
            Severity: Major
            Found in api/modules/publishedFiles/model.js and 2 other locations - About 1 hr to fix
            api/modules/publishedFiles/model.js on lines 128..133
            api/modules/publishedProjects/model.js on lines 37..42

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

            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

              deleteOne(id) {
                return new this.PublishedProjectsModel()
                .query()
                .where(this.context.column(`id`), id)
                .del();
            Severity: Major
            Found in api/modules/publishedProjects/model.js and 2 other locations - About 1 hr to fix
            api/modules/publishedFiles/model.js on lines 121..126
            api/modules/publishedFiles/model.js on lines 128..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 59.

            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

              deleteAll(publishedId) {
                return new this.PublishedFilesModel()
                .query()
                .where(this.context.column(`published_id`), publishedId)
                .del();
            Severity: Major
            Found in api/modules/publishedFiles/model.js and 2 other locations - About 1 hr to fix
            api/modules/publishedFiles/model.js on lines 121..126
            api/modules/publishedProjects/model.js on lines 37..42

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

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

              updatePaths(request, reply) {
                const projectId = request.pre.records.models[0].get(`id`);
                const renamedPaths = request.payload;
            
                function renameOperation(transaction) {
            Severity: Minor
            Found in api/modules/projects/controller.js - About 1 hr to fix

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

                server.auth.strategy(
                  `publishedProjectToken`,
                  `bearer-access-token`,
                  {
                    accessTokenName: `export_token`,
              Severity: Major
              Found in server.js and 1 other location - About 1 hr to fix
              server.js on lines 89..97

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

              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

                server.auth.strategy(
                  `projectToken`,
                  `bearer-access-token`,
                  {
                    accessTokenName: `export_token`,
              Severity: Major
              Found in server.js and 1 other location - About 1 hr to fix
              server.js on lines 99..107

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

              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 a Cognitive Complexity of 10 (exceeds 5 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

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

                _getFileTarStream(Model, files, concurrency=2) {
                  const tarStream = Tar.pack();
              
                  function processFile(file) {
                    return Model.query({
              Severity: Minor
              Found in api/classes/base_controller.js - About 1 hr to fix

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

                  run(publishedProjectId, next) {
                    if (!this.cache) {
                      return PublishedFiles.query({
                        where: {
                          published_id: publishedProjectId
                Severity: Minor
                Found in api/modules/publishedFiles/cache.js - About 1 hr to fix

                  Function getAllModifiedFiles has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    getAllModifiedFiles(publishedId) {
                      const self = this;
                  
                      return new this.PublishedFilesModel()
                      .query()
                  Severity: Minor
                  Found in api/modules/publishedFiles/model.js - About 1 hr to fix

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

                        return new FilesModel()
                        .query()
                        .leftOuterJoin(
                          this.context.tableName,
                          this.filesTable.column(`id`),
                    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 94..103

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

                    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)
                        .where(this.context.column(`path`), `like`, pattern)
                        .whereNotIn(this.context.column(`path`), ignorePaths)
                    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 22..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 55.

                    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

                          Prerequisites.confirmRecordExists(FilesModel, {
                            mode: `param`,
                            requestKey: `id`,
                            columns: [`id`, `path`, `project_id`]
                          }),
                    Severity: Major
                    Found in api/modules/files/routes/update.js and 1 other location - About 1 hr to fix
                    api/modules/files/routes/read.js on lines 78..82

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

                    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

                          Prerequisites.confirmRecordExists(FilesModel, {
                            mode: `param`,
                            requestKey: `project_id`,
                            columns: [`id`, `project_id`, `path`]
                          }),
                    Severity: Major
                    Found in api/modules/files/routes/read.js and 1 other location - About 1 hr to fix
                    api/modules/files/routes/update.js on lines 24..28

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

                    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