subgraph/core/src/datapoint.ts
Function getNewValue
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
function getNewValue(currentVar: string, targetVar: string, delta: BigInt, counter: Entity | null): Value {
if (currentVar === targetVar) {
return !counter ? Value.fromBigInt(delta) : Value.fromBigInt(counter.get(currentVar)!.toBigInt().plus(delta));
} else {
return !counter ? Value.fromBigInt(ZERO) : counter.get(currentVar)!;
- Read upRead up
- Create a ticketCreate a ticket
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
Expected a 'for-of' loop instead of a 'for' loop with this simple iteration Open
Open
for (let i = 0; i < VARIABLES.length; i++) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Rule: prefer-for-of
Recommends a 'for-of' loop over a standard 'for' loop if the index is only used to access the array being iterated.
Rationale
A for(... of ...) loop is easier to implement and read when the index is not needed.
Config
Not configurable.
Examples
"prefer-for-of": true
For more information see this page.