kleros/kleros-v2

View on GitHub
web/src/pages/Home/CourtOverview/Chart.tsx

Summary

Maintainability
A
2 hrs
Test Coverage

Function Chart has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const Chart: React.FC = () => {
  const [chartOption, setChartOption] = useState("stakedPNK");
  const { data } = useHomePageContext();
  const chartData = data?.counters;
  const courtsChartData = data?.courts;
Severity: Minor
Found in web/src/pages/Home/CourtOverview/Chart.tsx - About 1 hr to fix

Function Chart has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

const Chart: React.FC = () => {
  const [chartOption, setChartOption] = useState("stakedPNK");
  const { data } = useHomePageContext();
  const chartData = data?.counters;
  const courtsChartData = data?.courts;
Severity: Minor
Found in web/src/pages/Home/CourtOverview/Chart.tsx - 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

Assigning this reference to local variable not allowed: tooltip.
Open

  const tooltip = this;

Rule: no-this-assignment

Disallows unnecessary references to this.

Rationale

Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well.

Instead of storing a reference to this and using it inside a function () {:

const self = this;

setTimeout(function () {
    self.doWork();
});

Use () => arrow lambdas, as they preserve this scope for you:

setTimeout(() => {
    this.doWork();
});

Config

Two options may be provided on an object:

  • allow-destructuring allows using destructuring to access members of this (e.g. { foo, bar } = this;).
  • allowed-names may be specified as a list of regular expressions to match allowed variable names.
Examples
"no-this-assignment": true
"no-this-assignment": true,[object Object]
Schema
{
  "additionalProperties": false,
  "properties": {
    "allow-destructuring": {
      "type": "boolean"
    },
    "allowed-names": {
      "listType": "string",
      "type": "list"
    }
  },
  "type": "object"
}

For more information see this page.

There are no issues that match your filters.

Category
Status