grafana/k6-cloud-grafana-datasource

View on GitHub

Showing 10 of 10 total issues

File DataSource.ts has 730 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import _ from 'lodash';
import Keyv from 'keyv';

import {
  DataQueryRequest,
Severity: Major
Found in src/DataSource.ts - About 1 day to fix

    File QueryEditor.tsx has 387 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import _ from 'lodash';
    import React, { PureComponent } from 'react';
    
    import { Icon, InlineFormLabel } from '@grafana/ui';
    import { QueryEditorProps, SelectableValue } from '@grafana/data';
    Severity: Minor
    Found in src/components/QueryEditor/QueryEditor.tsx - About 5 hrs to fix

      Function query has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

        async query(options: DataQueryRequest<K6CloudQuery>): Promise<DataQueryResponse> {
          let data = { data: [] as MutableDataFrame[] };
      
          for (const target of options.targets) {
            if (target.hide) {
      Severity: Minor
      Found in src/DataSource.ts - About 3 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

      DataSource has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class DataSource extends DataSourceApi<K6CloudQuery, K6CloudDataSourceOptions> {
        url?: string;
        cache?: Keyv;
      
        constructor(instanceSettings: DataSourceInstanceSettings<K6CloudDataSourceOptions>) {
      Severity: Minor
      Found in src/DataSource.ts - About 2 hrs to fix

        QueryEditor has 21 functions (exceeds 20 allowed). Consider refactoring.
        Open

        export class QueryEditor extends PureComponent<Props, QueryEditorState> {
          url?: string;
          lastTagId: number;
          state: QueryEditorState = {
            projectList: [],
        Severity: Minor
        Found in src/components/QueryEditor/QueryEditor.tsx - About 2 hrs to fix

          Function getUnitFromMetric has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          export const getUnitFromMetric = (metric: K6Metric, aggregation?: string) => {
            switch (metric.type) {
              case K6MetricType.COUNTER:
                if (_.includes(['data_received', 'data_sent'], metric.name)) {
                  return aggregation === 'rps' ? 'bps' : 'bytes';
          Severity: Minor
          Found in src/utils.ts - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Avoid deeply nested control flow statements.
          Open

                  if (resolvedTestRunId) {
                    const thresholdsList = await this.getThresholdsForTestRun(resolvedTestRunId);
                    const fields = this.convertThresholdsToFields(thresholdsList);
                    data.data.push(
                      new MutableDataFrame({
          Severity: Major
          Found in src/DataSource.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                  } else if (qtype === K6QueryType.URLS) {
                    if (resolvedTestRunId) {
                      const urlsList = await this.getURLsForTestRun(resolvedTestRunId);
                      const fields = this.convertURLsToFields(urlsList);
                      data.data.push(
            Severity: Major
            Found in src/DataSource.ts - About 45 mins to fix

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

                convertSeriesToFields(series: K6Series, metric: K6Metric, tags?: Map<string, string>, aggregation?: string) {
                  const timeValues = _.map(series.values, (d) => {
                    return dateTimeParse(d.timestamp).unix() * 1000;
                  });
                  const values = _.map(series.values, (d) => {
              Severity: Minor
              Found in src/DataSource.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

              Avoid too many return statements within this function.
              Open

                  return [];
              Severity: Major
              Found in src/DataSource.ts - About 30 mins to fix
                Severity
                Category
                Status
                Source
                Language