airbnb/superset

View on GitHub
superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.js

Summary

Maintainability
F
6 days
Test Coverage

File utilities.js has 798 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

    Function naturalSort has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    const naturalSort = (as, bs) => {
      // nulls first
      if (bs !== null && as === null) {
        return -1;
      }

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

      processRecord(record) {
        // this code is called in a tight loop
        const colKey = [];
        const rowKey = [];
        this.props.cols.forEach(col => {

      Function naturalSort has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const naturalSort = (as, bs) => {
        // nulls first
        if (bs !== null && as === null) {
          return -1;
        }

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

          processRecord(record) {
            // this code is called in a tight loop
            const colKey = [];
            const rowKey = [];
            this.props.cols.forEach(col => {

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

          extremes(mode, formatter = usFmt) {
            return function ([attr]) {
              return function (data) {
                return {
                  val: null,

          Function runningStat has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            runningStat(mode = 'mean', ddof = 1, formatter = usFmt) {
              return function ([attr]) {
                return function () {
                  return {
                    n: 0.0,

            Function quantile has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              quantile(q, formatter = usFmt) {
                return function ([attr]) {
                  return function () {
                    return {
                      vals: [],

              Function sortKeys has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                sortKeys() {
                  if (!this.sorted) {
                    this.sorted = true;
                    const v = (r, c) => this.getAggregator(r, c).value();
                    switch (this.props.rowOrder) {

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

                  constructor(inputProps = {}, subtotals = {}) {
                    this.props = { ...PivotData.defaultProps, ...inputProps };
                    this.processRecord = this.processRecord.bind(this);
                    PropTypes.checkPropTypes(
                      PivotData.propTypes,

                  Function dateFormat has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    dateFormat(
                      col,
                      formatString,
                      utcOutput = false,
                      mthNames = mthNamesEn,

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

                    const sortAs = function (order) {
                      const mapping = {};
                    
                      // sort lowercased keys similarly
                      const lMapping = {};

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

                                push(record) {
                                  const x = record[attr];
                                  if (['min', 'max'].includes(mode)) {
                                    const coercedValue = Number(x);
                                    if (Number.isNaN(coercedValue)) {

                        Function dateFormat has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            col,
                            formatString,
                            utcOutput = false,
                            mthNames = mthNamesEn,
                            dayNames = dayNamesEn,

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

                          const getSort = function (sorters, attr) {
                            if (sorters) {
                              if (typeof sorters === 'function') {
                                const sort = sorters(attr);
                                if (typeof sort === 'function') {

                          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 1;

                            Avoid too many return statements within this function.
                            Open

                                return -1;

                              Avoid too many return statements within this function.
                              Open

                                  return naturalSort(a, b);

                                Avoid too many return statements within this function.
                                Open

                                    return 1;

                                  Avoid too many return statements within this function.
                                  Open

                                      return -1;

                                    Avoid too many return statements within this function.
                                    Open

                                        return 0;

                                      Avoid too many return statements within this function.
                                      Open

                                        return a.length - b.length;

                                        Avoid too many return statements within this function.
                                        Open

                                            return a > b ? 1 : -1;

                                          Avoid too many return statements within this function.
                                          Open

                                              return -1;

                                            Avoid too many return statements within this function.
                                            Open

                                                  return 1;

                                              Avoid too many return statements within this function.
                                              Open

                                                  return 0;

                                                Avoid too many return statements within this function.
                                                Open

                                                      return a1 > b1 ? 1 : -1;

                                                  Avoid too many return statements within this function.
                                                  Open

                                                          return a1.replace(rz, '.0') - b1.replace(rz, '.0');

                                                    Avoid too many return statements within this function.
                                                    Open

                                                        return 1;

                                                      Avoid too many return statements within this function.
                                                      Open

                                                            return -1;

                                                        Function getAggregator has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                          getAggregator(rowKey, colKey) {
                                                            let agg;
                                                            const flatRowKey = flatKey(rowKey);
                                                            const flatColKey = flatKey(colKey);
                                                            if (rowKey.length === 0 && colKey.length === 0) {

                                                        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 (!this.colTotals[flatColKey]) {
                                                                this.colKeys.push(fColKey);
                                                                this.colTotals[flatColKey] = this.getFormattedAggregator(
                                                                  record,
                                                                  colKey,
                                                        superset-frontend/src/dashboard/util/getFilterScopeFromNodesTree.test.js on lines 329..341

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

                                                        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

                                                            this.props.rows.forEach(row => {
                                                              rowKey.push(row in record ? record[row] : 'null');
                                                            });
                                                        superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.js on lines 740..742

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

                                                        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

                                                            this.props.cols.forEach(col => {
                                                              colKey.push(col in record ? record[col] : 'null');
                                                            });
                                                        superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.js on lines 743..745

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

                                                        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 'key_z_to_a':
                                                                  this.colKeys.sort(
                                                                    this.arrSort(this.props.cols, this.subtotals.colPartialOnTop, true),
                                                                  );
                                                                  break;
                                                        superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.js on lines 690..694

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

                                                                case 'key_z_to_a':
                                                                  this.rowKeys.sort(
                                                                    this.arrSort(this.props.rows, this.subtotals.rowPartialOnTop, true),
                                                                  );
                                                                  break;
                                                        superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.js on lines 707..711

                                                        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