bcgov/common-forms-toolkit

View on GitHub

Showing 559 of 559 total issues

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

exports.down = function(knex) {
  return Promise.resolve()
    .then(() => knex.schema.alterTable(`${PREFIX}_submission_location`, table => {
      table.dropColumn('motelAdditional');
    }));
app/src/db/migrations/20200605115436_013-agriseafoodopscreening-remove-licencee.js on lines 4..9

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

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

File farmOpScreeningForm.js has 254 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import moment from 'moment';

import commonFormService from '@/services/commonFormService';
import { FormNames } from '@/utils/constants';
import { SampleData, RandomCities } from './sampleData.js';
Severity: Minor
Found in app/frontend/src/store/modules/farmopscreening/farmOpScreeningForm.js - About 2 hrs to fix

    File forestrySectorOpScreeningForm.js has 254 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import moment from 'moment';
    
    import commonFormService from '@/services/commonFormService';
    import { FormNames } from '@/utils/constants';
    import { SampleData, RandomCities } from './sampleData.js';

      Function getClient has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        async getClient(id, includeRoles = false, includeUsers = false, includeUserRoles = false) {
          try {
            // TEMP: refresh loop was DOSing SSO
            await this._auth();
      
      
      Severity: Minor
      Found in app/src/components/keycloakAdminService.js - About 2 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

        async searchSubmissions(req, res, next) {
          try {
            const response = await this._dataService.searchSubmissions(req.params);
            res.status(200).json(response);
          } catch (error) {
      Severity: Major
      Found in docs/sample/forms/myform/controller.js and 1 other location - About 2 hrs to fix
      app/src/forms/attestations/controller.js on lines 51..58

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

      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 searchSubmissions(req, res, next) {
          try {
            const response = await this._dataService.searchSubmissions(req.searchParameters);
            res.status(200).json(response);
          } catch (error) {
      Severity: Major
      Found in app/src/forms/attestations/controller.js and 1 other location - About 2 hrs to fix
      docs/sample/forms/myform/controller.js on lines 49..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 76.

      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

      File dataService.js has 252 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const log = require('npmlog');
      const Problem = require('api-problem');
      const { transaction } = require('objection');
      
      class DataService {
      Severity: Minor
      Found in app/src/forms/common/dataService.js - About 2 hrs to fix

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

          return knex(`${PREFIX}_version_status_code`).del()
            .then(() => {
              return knex(`${PREFIX}_status_code`).del();
            })
            .then(()=> {
        app/src/db/migrations/20200602090643_010-forestrysectoroperatorscreening-data.js on lines 33..86
        app/src/db/migrations/20200603145742_011-agriseafoodopscreening-data.js on lines 22..75
        app/src/db/migrations/20210506111303_020-farmopscreening-data.js on lines 22..75
        docs/sample/db/migrations/20200626145742_myform-data.js on lines 16..66

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

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

          return Promise.resolve()
            .then(() => {
              return knex(`${PREFIX}_version_status_code`).del();
            })
            .then(() => {
        Severity: Major
        Found in docs/sample/db/migrations/20200626145742_myform-data.js and 4 other locations - About 2 hrs to fix
        app/src/db/migrations/20200515134601_004-minesoperatorscreening-seed-data.js on lines 14..61
        app/src/db/migrations/20200602090643_010-forestrysectoroperatorscreening-data.js on lines 33..86
        app/src/db/migrations/20200603145742_011-agriseafoodopscreening-data.js on lines 22..75
        app/src/db/migrations/20210506111303_020-farmopscreening-data.js on lines 22..75

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

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

          static get relationMappings() {
            return {
              attestation: {
                relation: Model.HasOneRelation,
                modelClass: this.Attestation,
        Severity: Minor
        Found in app/src/forms/attestations/models/submission.js - About 2 hrs to fix

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

          exports.up = function(knex) {
            return Promise.resolve()
              .then(() => knex.schema.createTable(`${PREFIX}_form`, table => {
                table.uuid('formId').references('formId').inTable('form').notNullable().primary();
                table.string('description');
          Severity: Minor
          Found in app/src/db/migrations/20200514140356_002-minesoperatorscreening.js - About 1 hr to fix

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

            exports.up = function(knex) {
              return knex(`${PREFIX}_version_status_code`).del()
                .then(() => {
                  return knex(`${PREFIX}_status_code`).del();
                })

              Function updateSubmission has 48 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async updateSubmission(submissionId, obj, user) {
                  // update: location, contacts, business
                  if (!obj) {
                    throw Error(`${this._constants.TITLE} Submission cannot be updated without data`);
                  }
              Severity: Minor
              Found in app/src/forms/attestations/dataService.js - About 1 hr to fix

                Function constructor has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  constructor(slug, dataService) {
                    super();
                
                    this._controller = new Controller(dataService);
                    this._resourceAccess = `comfort-${slug}`;
                Severity: Minor
                Found in app/src/forms/common/router.js - About 1 hr to fix

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

                          context: {
                            confirmationNumber: submission.confirmationId,
                            title: settings.config.title,
                            messageLinkText: settings.config.messageLinkText,
                            messageLinkUrl: `${settings.config.messageLinkUrl}/${submission.submissionId}`
                  Severity: Major
                  Found in app/src/forms/attestations/emailService.js and 1 other location - About 1 hr to fix
                  app/src/forms/attestations/emailService.js on lines 20..25

                  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

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

                    async current (req, res, next){
                      try {
                        const response = await this._dataService.current();
                        res.status(200).json(response);
                      } catch (error) {
                  Severity: Major
                  Found in app/src/forms/attestations/controller.js and 4 other locations - About 1 hr to fix
                  app/src/forms/attestations/controller.js on lines 33..40
                  app/src/forms/common/controller.js on lines 11..18
                  docs/sample/forms/myform/controller.js on lines 31..38
                  docs/sample/forms/myform/controller.js on lines 40..47

                  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

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

                    async current(req, res, next) {
                      try {
                        const response = await this._dataService.current();
                        res.status(200).json(response);
                      } catch (error) {
                  Severity: Major
                  Found in app/src/forms/common/controller.js and 4 other locations - About 1 hr to fix
                  app/src/forms/attestations/controller.js on lines 33..40
                  app/src/forms/attestations/controller.js on lines 42..49
                  docs/sample/forms/myform/controller.js on lines 31..38
                  docs/sample/forms/myform/controller.js on lines 40..47

                  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

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

                    async read(req, res, next){
                      try {
                        const response = await this._dataService.read();
                        res.status(200).json(response);
                      } catch (error) {
                  Severity: Major
                  Found in app/src/forms/attestations/controller.js and 4 other locations - About 1 hr to fix
                  app/src/forms/attestations/controller.js on lines 42..49
                  app/src/forms/common/controller.js on lines 11..18
                  docs/sample/forms/myform/controller.js on lines 31..38
                  docs/sample/forms/myform/controller.js on lines 40..47

                  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

                          context: {
                            confirmationNumber: submission.confirmationId,
                            title: settings.config.title,
                            messageLinkText: settings.config.messageLinkText,
                            messageLinkUrl: `${settings.config.messageLinkUrl}/${submission.submissionId}`
                  Severity: Major
                  Found in app/src/forms/attestations/emailService.js and 1 other location - About 1 hr to fix
                  app/src/forms/attestations/emailService.js on lines 62..67

                  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

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

                    async current (req, res, next){
                      try {
                        const response = await this._dataService.current();
                        res.status(200).json(response);
                      } catch (error) {
                  Severity: Major
                  Found in docs/sample/forms/myform/controller.js and 4 other locations - About 1 hr to fix
                  app/src/forms/attestations/controller.js on lines 33..40
                  app/src/forms/attestations/controller.js on lines 42..49
                  app/src/forms/common/controller.js on lines 11..18
                  docs/sample/forms/myform/controller.js on lines 31..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 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

                  Severity
                  Category
                  Status
                  Source
                  Language