Refactor to enforce strictNullChecks

This commit applies `strictNullChecks` to the entire codebase to improve
maintainability and type safety. Key changes include:

- Remove some explicit null-checks where unnecessary.
- Add necessary null-checks.
- Refactor static factory functions for a more functional approach.
- Improve some test names and contexts for better debugging.
- Add unit tests for any additional logic introduced.
- Refactor `createPositionFromRegexFullMatch` to its own function as the
  logic is reused.
- Prefer `find` prefix on functions that may return `undefined` and
  `get` prefix for those that always return a value.
This commit is contained in:
undergroundwires
2023-11-12 22:54:00 +01:00
parent 7ab16ecccb
commit 949fac1a7c
294 changed files with 2477 additions and 2738 deletions

View File

@@ -2,11 +2,12 @@ import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
import { IScript } from '@/domain/IScript';
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
import { IScriptCode } from '@/domain/IScriptCode';
export class ScriptStub extends BaseEntity<string> implements IScript {
public name = `name${this.id}`;
public code = {
public code: IScriptCode = {
execute: `REM execute-code (${this.id})`,
revert: `REM revert-code (${this.id})`,
};
@@ -23,23 +24,29 @@ export class ScriptStub extends BaseEntity<string> implements IScript {
return Boolean(this.code.revert);
}
public withLevel(value?: RecommendationLevel): ScriptStub {
public withLevel(value: RecommendationLevel | undefined): this {
this.level = value;
return this;
}
public withCode(value: string): ScriptStub {
this.code.execute = value;
public withCode(value: string): this {
this.code = {
execute: value,
revert: this.code.revert,
};
return this;
}
public withName(name: string): ScriptStub {
public withName(name: string): this {
this.name = name;
return this;
}
public withRevertCode(revertCode: string): ScriptStub {
this.code.revert = revertCode;
public withRevertCode(revertCode?: string): this {
this.code = {
execute: this.code.execute,
revert: revertCode,
};
return this;
}