airbnb/caravel

View on GitHub
superset-frontend/src/SqlLab/reducers/sqlLab.js

Summary

Maintainability
F
1 wk
Test Coverage

Function sqlLabReducer has 665 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function sqlLabReducer(state = {}, action) {
  const actionHandlers = {
    [actions.ADD_QUERY_EDITOR]() {
      const mergeUnsavedState = alterInArr(
        state,
Severity: Major
Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 3 days to fix

    File sqlLab.js has 699 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements.  See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership.  The ASF licenses this file
    Severity: Major
    Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 1 day to fix

      Function sqlLabReducer has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function sqlLabReducer(state = {}, action) {
        const actionHandlers = {
          [actions.ADD_QUERY_EDITOR]() {
            const mergeUnsavedState = alterInArr(
              state,
      Severity: Minor
      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 1 day 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

      actionHandlers has 49 functions (exceeds 20 allowed). Consider refactoring.
      Open

        const actionHandlers = {
          [actions.ADD_QUERY_EDITOR]() {
            const mergeUnsavedState = alterInArr(
              state,
              'queryEditors',
      Severity: Minor
      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 6 hrs to fix

        Function actions.REFRESH_QUERIES has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            [actions.REFRESH_QUERIES]() {
              let newQueries = { ...state.queries };
              // Fetch the updates to the queries present in the store.
              let change = false;
              let { queriesLastUpdate } = state;
        Severity: Minor
        Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 1 hr to fix

          Function actions.REMOVE_QUERY_EDITOR has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              [actions.REMOVE_QUERY_EDITOR]() {
                const queryEditor = {
                  ...action.queryEditor,
                  ...(action.queryEditor.id === state.unsavedQueryEditor.id &&
                    state.unsavedQueryEditor),
          Severity: Minor
          Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 1 hr to fix

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

                [actions.START_QUERY]() {
                  let newState = { ...state };
                  if (action.query.sqlEditorId) {
                    const qe = {
                      ...getFromArr(state.queryEditors, action.query.sqlEditorId),
            Severity: Minor
            Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 1 hr to fix

              Function actions.MERGE_TABLE has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  [actions.MERGE_TABLE]() {
                    const at = { ...action.table };
                    let existingTable;
                    state.tables.forEach(xt => {
                      if (
              Severity: Minor
              Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 1 hr to fix

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

                    [actions.SET_ACTIVE_QUERY_EDITOR]() {
                      const qeIds = state.queryEditors.map(qe => qe.id);
                      if (
                        qeIds.indexOf(action.queryEditor?.id) > -1 &&
                        state.tabHistory[state.tabHistory.length - 1] !== action.queryEditor.id
                Severity: Minor
                Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 1 hr to fix

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

                      [actions.CLONE_QUERY_TO_NEW_TAB]() {
                        const queryEditor = state.queryEditors.find(
                          qe => qe.id === state.tabHistory[state.tabHistory.length - 1],
                        );
                        const progenitor = {
                  Severity: Minor
                  Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 1 hr to fix

                    Consider simplifying this complex logical expression.
                    Open

                            if (
                              !state.queries.hasOwnProperty(id) ||
                              (state.queries[id].state !== QueryState.Stopped &&
                                state.queries[id].state !== QueryState.Failed)
                            ) {
                    Severity: Major
                    Found in superset-frontend/src/SqlLab/reducers/sqlLab.js - About 40 mins to fix

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

                          [actions.MIGRATE_TABLE]() {
                            try {
                              // remove migrated table from localStorage
                              const { sqlLab } = JSON.parse(localStorage.getItem('redux'));
                              sqlLab.tables = sqlLab.tables.filter(
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 1 other location - About 5 hrs to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 431..448

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

                      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

                          [actions.MIGRATE_QUERY_EDITOR]() {
                            try {
                              // remove migrated query editor from localStorage
                              const { sqlLab } = JSON.parse(localStorage.getItem('redux'));
                              sqlLab.queryEditors = sqlLab.queryEditors.filter(
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 1 other location - About 5 hrs to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 449..467

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

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

                          [actions.QUERY_EDITOR_SETDB]() {
                            return {
                              ...state,
                              ...alterUnsavedQueryEditorState(
                                state,
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 7 other locations - About 35 mins to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 506..517
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 518..529
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 550..561
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 562..573
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 574..585
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 599..610
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 624..635

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

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

                          [actions.QUERY_EDITOR_SET_TITLE]() {
                            return {
                              ...state,
                              ...alterUnsavedQueryEditorState(
                                state,
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 7 other locations - About 35 mins to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 494..505
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 506..517
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 550..561
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 562..573
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 574..585
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 599..610
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 624..635

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

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

                          [actions.QUERY_EDITOR_SET_SCHEMA]() {
                            return {
                              ...state,
                              ...alterUnsavedQueryEditorState(
                                state,
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 7 other locations - About 35 mins to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 494..505
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 518..529
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 550..561
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 562..573
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 574..585
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 599..610
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 624..635

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

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

                          [actions.QUERY_EDITOR_SET_TEMPLATE_PARAMS]() {
                            return {
                              ...state,
                              ...alterUnsavedQueryEditorState(
                                state,
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 7 other locations - About 35 mins to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 494..505
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 506..517
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 518..529
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 550..561
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 562..573
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 599..610
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 624..635

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

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

                          [actions.QUERY_EDITOR_TOGGLE_LEFT_BAR]() {
                            return {
                              ...state,
                              ...alterUnsavedQueryEditorState(
                                state,
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 7 other locations - About 35 mins to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 494..505
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 506..517
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 518..529
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 550..561
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 562..573
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 574..585
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 599..610

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

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

                          [actions.QUERY_EDITOR_SET_CURSOR_POSITION]() {
                            return {
                              ...state,
                              ...alterUnsavedQueryEditorState(
                                state,
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 7 other locations - About 35 mins to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 494..505
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 506..517
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 518..529
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 562..573
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 574..585
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 599..610
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 624..635

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

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

                          [actions.QUERY_EDITOR_SET_QUERY_LIMIT]() {
                            return {
                              ...state,
                              ...alterUnsavedQueryEditorState(
                                state,
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 7 other locations - About 35 mins to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 494..505
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 506..517
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 518..529
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 550..561
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 574..585
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 599..610
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 624..635

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

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

                          [actions.QUERY_EDITOR_SET_AUTORUN]() {
                            return {
                              ...state,
                              ...alterUnsavedQueryEditorState(
                                state,
                      Severity: Major
                      Found in superset-frontend/src/SqlLab/reducers/sqlLab.js and 7 other locations - About 35 mins to fix
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 494..505
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 506..517
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 518..529
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 550..561
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 562..573
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 574..585
                      superset-frontend/src/SqlLab/reducers/sqlLab.js on lines 624..635

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

                      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

                      There are no issues that match your filters.

                      Category
                      Status