Function parse
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
public static parse(seps: Separators, instructions: string, grouped: boolean, topScope: boolean): { instructions: RoutingInstruction[]; remaining: string } {
if (!instructions) {
return { instructions: [], remaining: '' };
}
if (instructions.startsWith(seps.sibling) && !InstructionParser.isAdd(seps, instructions)) {
- Read upRead up
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 parseOne
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
private static parseOne(seps: Separators, instruction: string): {
instruction: RoutingInstruction;
remaining: string;
} {
const tokens = [seps.parameters, seps.viewport, seps.noScope, seps.groupEnd, seps.scope, seps.sibling];
- Read upRead up
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 parse
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static parse(seps: Separators, instructions: string, grouped: boolean, topScope: boolean): { instructions: RoutingInstruction[]; remaining: string } {
if (!instructions) {
return { instructions: [], remaining: '' };
}
if (instructions.startsWith(seps.sibling) && !InstructionParser.isAdd(seps, instructions)) {
Function parseOne
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static parseOne(seps: Separators, instruction: string): {
instruction: RoutingInstruction;
remaining: string;
} {
const tokens = [seps.parameters, seps.viewport, seps.noScope, seps.groupEnd, seps.scope, seps.sibling];
Avoid deeply nested control flow statements. Open
if (instructions.slice(i, i + seps.groupEnd.length) !== seps.groupEnd) {
if (routingInstructions.length > 1) {
throw new Error(`Instruction parser error: Children below scope ${seps.groupStart}${seps.groupEnd} in instruction part "(${instructions}" is not allowed.`);
} else {
instructions = instructions.slice(i);
Avoid deeply nested control flow statements. Open
if (!grouped) {
return { instructions: routingInstructions, remaining: instructions };
}
Avoid deeply nested control flow statements. Open
if (instructions.slice(i, i + seps.sibling.length) === seps.sibling) {
return { instructions: routingInstructions, remaining: instructions };
}
Avoid too many return
statements within this function. Open
return { instructions: routingInstructions, remaining: instructions };
Function findNextToken
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static findNextToken(instruction: string, tokens: string[]): { token: string; pos: number } {
const matches: Record<string, number> = {};
// Tokens can have length > 1
for (const token of tokens) {
const tokenPos = instruction.indexOf(token);
- Read upRead up
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"