bcgov/common-forms-toolkit

View on GitHub

Showing 559 of 559 total issues

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

    this._routes.put('/current/statusCodes', middleware.hasRole(this._resourceAccess, 'admin'), async (req, res, next) => {
      await this._controller.updateCurrentStatusCodes(req, res, next);
    });
Severity: Major
Found in app/src/forms/common/router.js and 8 other locations - About 1 hr to fix
app/src/forms/teammanagement/router.js on lines 23..25
app/src/forms/teammanagement/router.js on lines 27..29
app/src/forms/teammanagement/router.js on lines 31..33
app/src/forms/teammanagement/router.js on lines 35..37
app/src/forms/teammanagement/router.js on lines 39..41
app/src/forms/teammanagement/router.js on lines 43..45
app/src/forms/teammanagement/router.js on lines 47..49
app/src/forms/teammanagement/router.js on lines 51..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 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 9 locations. Consider refactoring.
Open

    this._routes.put('/roles/:roleId/users', middleware.hasRole(this._clientName, 'admin'), async (req, res, next) => {
      await this._controller.updateRoleUsers(req, res, next);
    });
Severity: Major
Found in app/src/forms/teammanagement/router.js and 8 other locations - About 1 hr to fix
app/src/forms/common/router.js on lines 23..25
app/src/forms/teammanagement/router.js on lines 23..25
app/src/forms/teammanagement/router.js on lines 27..29
app/src/forms/teammanagement/router.js on lines 31..33
app/src/forms/teammanagement/router.js on lines 35..37
app/src/forms/teammanagement/router.js on lines 39..41
app/src/forms/teammanagement/router.js on lines 43..45
app/src/forms/teammanagement/router.js on lines 47..49

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

  static get modifiers() {
    return {
      orderDescending(builder) {
        builder.orderBy('createdAt', 'desc');
      },
Severity: Minor
Found in app/src/forms/attestations/models/submission.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 modifiers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  static get modifiers () {
    return {
      filterActive(query, value) {
        if (value !== undefined) {
          query.where('active', value);
Severity: Minor
Found in app/src/forms/common/models/base.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 modifiers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  static get modifiers() {
    return {
      orderDescending(builder) {
        builder.orderBy('createdAt', 'desc');
      },
Severity: Minor
Found in app/src/forms/attestations/models/submission.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 searchSubmissions has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  async searchSubmissions(params) {
    const tiny = data => {
      if (!data || !Array.isArray(data) || !data.length) {
        return [];
      }
Severity: Minor
Found in docs/sample/forms/myform/dataService.js - About 1 hr to fix

    Function modifiers has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static get modifiers () {
        return {
          filterActive(query, value) {
            if (value !== undefined) {
              query.where('active', value);
    Severity: Minor
    Found in app/src/forms/common/models/base.js - About 1 hr to fix

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

        async current(tiny) {
          let form;
          let version;
      
          if (tiny) {
      Severity: Minor
      Found in app/src/forms/attestations/dataService.js - About 1 hr to fix

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

          async current(tiny){
            let form;
            let version;
        
            if (tiny) {
        Severity: Minor
        Found in app/src/forms/common/dataService.js - About 1 hr to fix

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

            async createSubmission(obj, user) {
              if (!obj) {
                throw Error(`${this._constants.TITLE} Submission cannot be created without data`);
              }
          
          
          Severity: Minor
          Found in docs/sample/forms/myform/dataService.js - About 1 hr to fix

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

              async searchSubmissions(params) {
                if (params && params.tiny) {
                  const submissions = await this._models.SubmissionSearchView.query()
                    .modify('filterVersion', params.version)
                    .modify('filterConfirmationId', params.confirmationId)
            Severity: Minor
            Found in app/src/forms/attestations/dataService.js - About 1 hr to fix

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

                static get relationMappings() {
                  return {
                    survey: {
                      relation: Model.HasOneRelation,
                      modelClass: this.Survey,
              Severity: Minor
              Found in docs/sample/forms/myform/models/form.js - About 1 hr to fix

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

                  async current(tiny) {
                    let form;
                    let version;
                
                    if (tiny) {
                Severity: Minor
                Found in docs/sample/forms/myform/dataService.js - About 1 hr to fix

                  Function updateSubmission has a Cognitive Complexity of 9 (exceeds 5 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 55 mins 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

                        if (doTheUpdate) {
                          // only want to update the who and when...
                          await this._models.Submission.query(trx).patchAndFetchById(obj.submissionId, {updatedBy: user.username});
                        }
                  Severity: Minor
                  Found in docs/sample/forms/myform/dataService.js and 1 other location - About 55 mins to fix
                  app/src/forms/attestations/dataService.js on lines 322..325

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

                  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

                      this._routes.post('/submissions', middleware.publicRateLimiter, middleware.currentUser, async (req, res, next) => {
                        await this._controller.createSubmission(req, res, next);
                      });
                  Severity: Minor
                  Found in app/src/forms/attestations/router.js and 1 other location - About 55 mins to fix
                  docs/sample/forms/myform/router.js on lines 26..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 53.

                  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

                        if (doTheUpdate) {
                          // only want to update the who and when...
                          await this._models.Submission.query(trx).patchAndFetchById(obj.submissionId, {updatedBy: user.username});
                        }
                  Severity: Minor
                  Found in app/src/forms/attestations/dataService.js and 1 other location - About 55 mins to fix
                  docs/sample/forms/myform/dataService.js on lines 295..298

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

                  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

                      this._routes.post('/submissions', middleware.publicRateLimiter, middleware.currentUser, async (req, res, next) => {
                        await this._controller.createSubmission(req, res, next);
                      });
                  Severity: Minor
                  Found in docs/sample/forms/myform/router.js and 1 other location - About 55 mins to fix
                  app/src/forms/attestations/router.js on lines 26..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 53.

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

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

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

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

                  Refactorings

                  Further Reading

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

                  const operationTypes = [
                    {type:'AGRICULTURE', display: 'Agriculture', enabled: true, createdBy: CREATED_BY},
                    {type:'SEAFOOD', display: 'Seafood', enabled: true, createdBy: CREATED_BY}
                  ];
                  app/src/db/migrations/20210506111303_020-farmopscreening-data.js on lines 10..13

                  Duplicated Code

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

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

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

                  Tuning

                  This issue has a mass of 52.

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

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

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

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

                  Refactorings

                  Further Reading

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

                  const operationTypes = [
                    {type:'AGRICULTURE', display: 'Agriculture', enabled: true, createdBy: CREATED_BY},
                    {type:'SEAFOOD', display: 'Seafood', enabled: true, createdBy: CREATED_BY}
                  ];
                  app/src/db/migrations/20200603145742_011-agriseafoodopscreening-data.js on lines 10..13

                  Duplicated Code

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

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

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

                  Tuning

                  This issue has a mass of 52.

                  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