Skip to content

Commit

Permalink
chore: ts check indexed access
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Jan 25, 2025
1 parent ef1bb6d commit c89f851
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/steps/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ export class StepsBuilder {
const stepsToClose = this.openSteps.filter(
(step) => step.indent === line.indent,
);
if (stepsToClose.length === 0) {
this.throwError(line, `Step end without step start`);
}
if (stepsToClose.length > 1) {
this.throwError(line, `Several open steps with same indent.`);
}
stepsToClose[0].end = line.index;
stepsToClose[0].endByComment = true;
const stepToClose = stepsToClose[0];
if (!stepToClose) {
this.throwError(line, `Step end without step start`);
}
stepToClose.end = line.index;
stepToClose.endByComment = true;
}

private closeStepByStartComment(line: ParsedLine) {
Expand All @@ -82,8 +83,9 @@ export class StepsBuilder {
if (stepsToClose.length > 1) {
this.throwError(line, `Several open steps with same indent.`);
}
if (stepsToClose.length === 1) {
stepsToClose[0].end = line.index - 1;
const stepToClose = stepsToClose[0];
if (stepsToClose.length === 1 && stepToClose) {
stepToClose.end = line.index - 1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/steps/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class StepsRenderer {
if (endByComment) {
this.lines[end] = `${' '.repeat(indent)}});`;
} else {
const line = this.lines[end];
const line = this.lines[end]!;
this.lines[end] = isCommented(line)
? `${' '.repeat(indent)}}); ${line.trim()}`
: `${line} });`;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "es2021",
"module": "nodenext",
"strict": true,
"noUncheckedIndexedAccess": true,
"useUnknownInCatchVariables": false,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
Expand Down

0 comments on commit c89f851

Please sign in to comment.