Skip to content

Commit

Permalink
refactor: rearrange the code to reduce cognitive complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
alvis committed Aug 2, 2022
1 parent 5123609 commit 6c9cad7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions source/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ export function renderStack(
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i];

if (block.type === 'location' && filter(block.path)) {
if (block.type === 'description') {
renderedBlocks.push(renderDescription(block, currentError));
currentError = error['cause'];
} else if (filter(block.path)) {
renderedBlocks.push(
renderLocation(block, {
showSource:
// NOTE a location block must follow a description block
showSource && blocks[i - 1].type === 'description',
}),
);
} else if (block.type === 'description') {
renderedBlocks.push(renderDescription(block, currentError));
currentError = error['cause'];
}
}

Expand Down
3 changes: 2 additions & 1 deletion source/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export interface StackLocationBlock {

export type StackBlock = StackDescriptionBlock | StackLocationBlock;

const stackLineExpression = /(\s*at (.+) \((.+):([0-9]+):([0-9]+)\))|(^(\w+):\s*([\w\W]*?)(\s*\n\s+))/gm;
const stackLineExpression =
/(\s*at (.+) \((.+):([0-9]+):([0-9]+)\))|(^(\w+):\s*([\w\W]*?)(\s*\n\s+))/gm;

/**
* parse a stack into its components
Expand Down

0 comments on commit 6c9cad7

Please sign in to comment.