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

@@ -3,6 +3,7 @@ import type {
} from '@/application/collections/';
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
import { createScriptDataWithCode } from './ScriptDataStub';
export class CollectionDataStub implements CollectionData {
public os = 'windows';
@@ -13,17 +14,17 @@ export class CollectionDataStub implements CollectionData {
public functions?: ReadonlyArray<FunctionData>;
public withActions(actions: readonly CategoryData[]): CollectionDataStub {
public withActions(actions: readonly CategoryData[]): this {
this.actions = actions;
return this;
}
public withOs(os: string): CollectionDataStub {
public withOs(os: string): this {
this.os = os;
return this;
}
public withScripting(scripting: ScriptingDefinitionData): CollectionDataStub {
public withScripting(scripting: ScriptingDefinitionData): this {
this.scripting = scripting;
return this;
}
@@ -57,11 +58,7 @@ function getScriptStub(
scriptName: string,
level: RecommendationLevel = RecommendationLevel.Standard,
): ScriptData {
return {
name: scriptName,
code: 'script code',
revertCode: 'revert code',
recommend: RecommendationLevel[level].toLowerCase(),
call: undefined,
};
return createScriptDataWithCode()
.withName(scriptName)
.withRecommend(RecommendationLevel[level].toLowerCase());
}