WikiEducationFoundation/WikiEduDashboard

View on GitHub
app/assets/javascripts/reducers/revisions.js

Summary

Maintainability
F
1 wk
Test Coverage
F
38%

Function revisions has 168 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function revisions(state = initialState, action) {
  switch (action.type) {
    case INCREASE_LIMIT: {
      let revisionsDisplayed = state.revisionsDisplayed.concat(
        state.revisions.slice(
Severity: Major
Found in app/assets/javascripts/reducers/revisions.js - About 6 hrs to fix

    Function revisions has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function revisions(state = initialState, action) {
      switch (action.type) {
        case INCREASE_LIMIT: {
          let revisionsDisplayed = state.revisionsDisplayed.concat(
            state.revisions.slice(
    Severity: Minor
    Found in app/assets/javascripts/reducers/revisions.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

    Avoid too many return statements within this function.
    Open

          return {
            ...state,
            revisions: state.revisions.concat(action.data.course.revisions),
            limitReached: isLimitReached(action.data.course.start, state.last_date),
            revisionsLoaded: true,
    Severity: Major
    Found in app/assets/javascripts/reducers/revisions.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

            return newState;
      Severity: Major
      Found in app/assets/javascripts/reducers/revisions.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

              return { ...state,
                revisionsDisplayed: sortedRevisions.newModels,
                revisionsDisplayedCourseSpecific: sortedCourseScopedRevisions.newModels,
                sort: {
                  sortKey: desc ? null : action.key,
        Severity: Major
        Found in app/assets/javascripts/reducers/revisions.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return {
                  ...state,
                  courseScopedRevisions: state.courseScopedRevisions.concat(action.data.course.revisions),
                  courseScopedLimitReached: isLimitReached(action.data.course.start, state.last_date_course_specific),
                  courseScopedRevisionsLoaded: true,
          Severity: Major
          Found in app/assets/javascripts/reducers/revisions.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return newState;
            Severity: Major
            Found in app/assets/javascripts/reducers/revisions.js - About 30 mins to fix

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

                  case RECEIVE_ASSESSMENTS: {
                    const newState = { ...state, assessmentsLoaded: true };
                    const revisionsArray = newState.revisions;
                    const pageAssessments = action.data.assessments;
                    newState.revisions = revisionsArray.map((revision) => {
              Severity: Major
              Found in app/assets/javascripts/reducers/revisions.js and 1 other location - About 1 day to fix
              app/assets/javascripts/reducers/revisions.js on lines 140..161

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

              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

                  case 'RECEIVE_ASSESSMENTS_COURSE_SPECIFIC': {
                    const newState = { ...state, courseSpecificAssessmentsLoaded: true };
                    const revisionsArray = newState.courseScopedRevisions;
                    const pageAssessments = action.data.assessments;
                    newState.courseScopedRevisions = revisionsArray.map((revision) => {
              Severity: Major
              Found in app/assets/javascripts/reducers/revisions.js and 1 other location - About 1 day to fix
              app/assets/javascripts/reducers/revisions.js on lines 118..139

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

              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

                  case INCREASE_LIMIT: {
                    let revisionsDisplayed = state.revisionsDisplayed.concat(
                      state.revisions.slice(
                          state.revisionsDisplayed.length, state.revisionsDisplayed.length + REVISIONS_INCREMENT
                        )
              Severity: Major
              Found in app/assets/javascripts/reducers/revisions.js and 1 other location - About 1 day to fix
              app/assets/javascripts/reducers/revisions.js on lines 72..93

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

              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

                  case INCREASE_LIMIT_COURSE_SPECIFIC: {
                    let revisionsDisplayedCourseSpecific = state.revisionsDisplayedCourseSpecific.concat(
                      state.courseScopedRevisions.slice(
                          state.revisionsDisplayedCourseSpecific.length, state.revisionsDisplayedCourseSpecific.length + REVISIONS_INCREMENT
                        )
              Severity: Major
              Found in app/assets/javascripts/reducers/revisions.js and 1 other location - About 1 day to fix
              app/assets/javascripts/reducers/revisions.js on lines 50..71

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

              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

                  case RECEIVE_REFERENCES_COURSE_SPECIFIC: {
                    const newState = { ...state, courseSpecificReferencesLoaded: true };
                    const revisionsArray = newState.courseScopedRevisions;
                    const referencesAdded = action.data.referencesAdded;
                    newState.courseScopedRevisions = revisionsArray.map((revision) => {
              Severity: Major
              Found in app/assets/javascripts/reducers/revisions.js and 1 other location - About 5 hrs to fix
              app/assets/javascripts/reducers/revisions.js on lines 94..105

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

              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

                  case RECEIVE_REFERENCES: {
                    const newState = { ...state, referencesLoaded: true };
                    const revisionsArray = newState.revisions;
                    const referencesAdded = action.data.referencesAdded;
                    newState.revisions = revisionsArray.map((revision) => {
              Severity: Major
              Found in app/assets/javascripts/reducers/revisions.js and 1 other location - About 5 hrs to fix
              app/assets/javascripts/reducers/revisions.js on lines 106..117

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

              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

                    if ((state.sort.key !== 'date' && state.sort.key !== null) || (state.sort.key === 'date' && state.sort.sortKey !== null)) {
                      const desc = state.sort.sortKey === null;
                      const absolute = state.sort.key === 'characters';
                      revisionsDisplayed = sortByKey(revisionsDisplayed, state.sort.key, null, desc, absolute).newModels;
                    }
              Severity: Major
              Found in app/assets/javascripts/reducers/revisions.js and 1 other location - About 4 hrs to fix
              app/assets/javascripts/reducers/revisions.js on lines 187..191

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

              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

                    if ((state.sort.key !== 'date' && state.sort.key !== null) || (state.sort.key === 'date' && state.sort.sortKey !== null)) {
                      const desc = state.sort.sortKey === null;
                      const absolute = state.sort.key === 'characters';
                      revisionsDisplayedCourseSpecific = sortByKey(revisionsDisplayedCourseSpecific, state.sort.key, null, desc, absolute).newModels;
                    }
              Severity: Major
              Found in app/assets/javascripts/reducers/revisions.js and 1 other location - About 4 hrs to fix
              app/assets/javascripts/reducers/revisions.js on lines 166..170

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

              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

              Parsing error: Cannot find module 'babel-plugin-root-import' Require stack: - /usr/local/node_modules/@babel/core/lib/config/files/plugins.js - /usr/local/node_modules/@babel/core/lib/config/files/index.js - /usr/local/node_modules/@babel/core/lib/index.js - /usr/local/node_modules/@babel/eslint-parser/lib/worker/babel-core.cjs - /usr/local/node_modules/@babel/eslint-parser/lib/worker/handle-message.cjs - /usr/local/node_modules/@babel/eslint-parser/lib/client.cjs - /usr/local/node_modules/@babel/eslint-parser/lib/index.cjs - /usr/local/node_modules/eslint/lib/cli-engine/config-array-factory.js - /usr/src/app/lib/eslint6-patch.js - /usr/src/app/lib/eslint.js - /usr/src/app/bin/eslint.js
              Open

              import {

              For more information visit Source: http://eslint.org/docs/rules/

              There are no issues that match your filters.

              Category
              Status