kleros/kleros-v2

View on GitHub
web/src/pages/Cases/CaseDetails/Timeline.tsx

Summary

Maintainability
A
3 hrs
Test Coverage

Function useTimeline has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

const useTimeline = (dispute: DisputeDetailsQuery["dispute"], currentItemIndex: number, currentPeriodIndex: number) => {
  const isDesktop = useIsDesktop();
  const titles = useMemo(() => {
    const titles = ["Evidence", "Voting", "Appeal", "Executed"];
    if (dispute?.court.hiddenVotes) {
Severity: Minor
Found in web/src/pages/Cases/CaseDetails/Timeline.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

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

const useTimeline = (dispute: DisputeDetailsQuery["dispute"], currentItemIndex: number, currentPeriodIndex: number) => {
  const isDesktop = useIsDesktop();
  const titles = useMemo(() => {
    const titles = ["Evidence", "Voting", "Appeal", "Executed"];
    if (dispute?.court.hiddenVotes) {
Severity: Minor
Found in web/src/pages/Cases/CaseDetails/Timeline.tsx - About 1 hr to fix

Avoid too many return statements within this function.
Wontfix

    return [<StyledSkeleton key={index} width={60} />];
Severity: Major
Found in web/src/pages/Cases/CaseDetails/Timeline.tsx - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return [secondsToDayHourMinute(dispute?.court.timesPerPeriod[index])];
Severity: Major
Found in web/src/pages/Cases/CaseDetails/Timeline.tsx - About 30 mins to fix

Shadowed name: 'titles'
Open

    const titles = ["Evidence", "Voting", "Appeal", "Executed"];

Rule: no-shadowed-variable

Disallows shadowing variable declarations.

Rationale

When a variable in a local scope and a variable in the containing scope have the same name, shadowing occurs. Shadowing makes it impossible to access the variable in the containing scope and obscures to what value an identifier actually refers. Compare the following snippets:

const a = 'no shadow';
function print() {
    console.log(a);
}
print(); // logs 'no shadow'.
const a = 'no shadow';
function print() {
    const a = 'shadow'; // TSLint will complain here.
    console.log(a);
}
print(); // logs 'shadow'.

ESLint has an equivalent rule. For more background information, refer to this MDN closure doc.

Config

You can optionally pass an object to disable checking for certain kinds of declarations. Possible keys are "class", "enum", "function", "import", "interface", "namespace", "typeAlias" and "typeParameter". You can also pass "underscore" to ignore variable names that begin with _. Just set the value to false for the check you want to disable. All checks default to true, i.e. are enabled by default. Note that you cannot disable variables and parameters.

The option "temporalDeadZone" defaults to true which shows errors when shadowing block scoped declarations in their temporal dead zone. When set to false parameters, classes, enums and variables declared with let or const are not considered shadowed if the shadowing occurs within their temporal dead zone.

The following example shows how the "temporalDeadZone" option changes the linting result:

function fn(value) {
    if (value) {
        const tmp = value; // no error on this line if "temporalDeadZone" is false
        return tmp;
    }
    let tmp = undefined;
    if (!value) {
        const tmp = value; // this line always contains an error
        return tmp;
    }
}
Examples
"no-shadowed-variable": true
"no-shadowed-variable": true,[object Object]
Schema
{
  "type": "object",
  "properties": {
    "class": {
      "type": "boolean"
    },
    "enum": {
      "type": "boolean"
    },
    "function": {
      "type": "boolean"
    },
    "import": {
      "type": "boolean"
    },
    "interface": {
      "type": "boolean"
    },
    "namespace": {
      "type": "boolean"
    },
    "typeAlias": {
      "type": "boolean"
    },
    "typeParameter": {
      "type": "boolean"
    },
    "temporalDeadZone": {
      "type": "boolean"
    },
    "underscore": {
      "type": "boolean"
    }
  }
}

For more information see this page.

Missing radix parameter
Open

    const parsedTimeCurrentPeriod = parseInt(timesPerPeriod[currentPeriodIndex]);

Rule: radix

Requires the radix parameter to be specified when calling parseInt.

Rationale

From MDN:

Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10.

Config

Not configurable.

Examples
"radix": true

For more information see this page.

There are no issues that match your filters.

Category
Status