airbnb/superset

View on GitHub
superset-frontend/plugins/plugin-chart-table/src/transformProps.ts

Summary

Maintainability
F
1 wk
Test Coverage

File transformProps.ts has 627 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/plugins/plugin-chart-table/src/transformProps.ts - About 1 day to fix

    Function transformProps has 243 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const transformProps = (
      chartProps: TableChartProps,
    ): TableChartTransformedProps => {
      const {
        height,
    Severity: Major
    Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 1 day to fix

      Function transformProps has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
      Open

      const transformProps = (
        chartProps: TableChartProps,
      ): TableChartTransformedProps => {
        const {
          height,
      Severity: Minor
      Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 7 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

      Function processColumns has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

      const processColumns = memoizeOne(function processColumns(
        props: TableChartProps,
      ) {
        const {
          datasource: { columnFormats, currencyFormats, verboseMap },
      Severity: Minor
      Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 4 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

      Function processColumns has 83 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const processColumns = memoizeOne(function processColumns(
        props: TableChartProps,
      ) {
        const {
          datasource: { columnFormats, currencyFormats, verboseMap },
      Severity: Major
      Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 3 hrs to fix

        Function processComparisonColumns has 74 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            .map(col => {
              const {
                datasource: { columnFormats, currencyFormats },
                rawFormData: { column_config: columnConfig = {} },
              } = props;
        Severity: Major
        Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 2 hrs to fix

          Function getBasicColorFormatter has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            const getBasicColorFormatter = memoizeOne(function getBasicColorFormatter(
              originalData: DataRecord[] | undefined,
              originalColumns: DataColumnMeta[],
              selectedColumns?: ConditionalFormattingConfig[],
            ) {
          Severity: Major
          Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 2 hrs to fix

            Function columns has 53 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                .map((key: string, i) => {
                  const dataType = coltypes[i];
                  const config = columnConfig[key] || {};
                  // for the purpose of presentation, only numeric values are treated as metrics
                  // because users can also add things like `MAX(str_col)` as a metric.
            Severity: Major
            Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 2 hrs to fix

              Function processComparisonDataRecords has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                function processComparisonDataRecords(
                  originalData: DataRecord[] | undefined,
                  originalColumns: DataColumnMeta[],
                  comparisonSuffix: string,
                ) {
              Severity: Minor
              Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 1 hr to fix

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

                const processComparisonTotals = (
                  comparisonSuffix: string,
                  totals?: DataRecord[],
                ): DataRecord | undefined => {
                  if (!totals) {
                Severity: Minor
                Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                          if (
                            (origCol.isMetric || origCol.isPercentMetric) &&
                            !origCol.key.includes(comparisonSuffix) &&
                            origCol.isNumeric
                          ) {
                  Severity: Major
                  Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 1 hr to fix

                    Consider simplifying this complex logical expression.
                    Open

                            if (
                              (origCol.isMetric || origCol.isPercentMetric) &&
                              !origCol.key.includes(ensureIsArray(timeOffsets)[0]) &&
                              origCol.isNumeric
                            ) {
                    Severity: Major
                    Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 1 hr to fix

                      Consider simplifying this complex logical expression.
                      Open

                            if (totalRecord[key] !== undefined && !key.includes(comparisonSuffix)) {
                              transformedTotals[`Main ${key}`] =
                                parseInt(transformedTotals[`Main ${key}`]?.toString() || '0', 10) +
                                parseInt(totalRecord[key]?.toString() || '0', 10);
                              transformedTotals[`# ${key}`] =
                      Severity: Major
                      Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 40 mins to fix

                        Function calculateDifferences has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                        const calculateDifferences = (
                          originalValue: number,
                          comparisonValue: number,
                        ) => {
                          const valueDifference = originalValue - comparisonValue;
                        Severity: Minor
                        Found in superset-frontend/plugins/plugin-chart-table/src/transformProps.ts - About 35 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

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

                          if (!originalValue && !comparisonValue) {
                            percentDifferenceNum = 0;
                          } else if (!originalValue || !comparisonValue) {
                            percentDifferenceNum = originalValue ? 1 : -1;
                          } else {
                        superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts on lines 157..163

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

                        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

                        function isNumeric(key: string, data: DataRecord[] = []) {
                          return data.every(
                            x => x[key] === null || x[key] === undefined || typeof x[key] === 'number',
                          );
                        }
                        superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts on lines 35..42

                        Duplicated Code

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

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

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

                        Tuning

                        This issue has a mass of 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

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

                          if (isUsingTimeComparison && !isEmpty(customOrInheritShifts)) {
                            if (customOrInheritShifts.includes('custom')) {
                              timeOffsets = timeOffsets.concat([formData.start_date_offset]);
                            }
                            if (customOrInheritShifts.includes('inherit')) {
                        superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/buildQuery.ts on lines 53..60
                        superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts on lines 105..115

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

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

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

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

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

                        Refactorings

                        Further Reading

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

                                  {
                                    ...col,
                                    label: `△`,
                                    key: `△ ${col.key}`,
                                    config: getComparisonColConfig(`△`, col.key, columnConfig),
                        superset-frontend/plugins/plugin-chart-table/src/transformProps.ts on lines 369..381
                        superset-frontend/plugins/plugin-chart-table/src/transformProps.ts on lines 395..407

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

                                  {
                                    ...col,
                                    label: `#`,
                                    key: `# ${col.key}`,
                                    config: getComparisonColConfig(`#`, col.key, columnConfig),
                        superset-frontend/plugins/plugin-chart-table/src/transformProps.ts on lines 382..394
                        superset-frontend/plugins/plugin-chart-table/src/transformProps.ts on lines 395..407

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

                                  {
                                    ...col,
                                    label: `%`,
                                    key: `% ${col.key}`,
                                    config: getComparisonColConfig(`%`, col.key, columnConfig),
                        superset-frontend/plugins/plugin-chart-table/src/transformProps.ts on lines 369..381
                        superset-frontend/plugins/plugin-chart-table/src/transformProps.ts on lines 382..394

                        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

                        There are no issues that match your filters.

                        Category
                        Status