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:
@@ -4,7 +4,6 @@ import { Script } from '@/domain/Script';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { ScriptCodeStub } from '@tests/unit/shared/Stubs/ScriptCodeStub';
|
||||
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
|
||||
describe('Script', () => {
|
||||
describe('ctor', () => {
|
||||
@@ -20,19 +19,6 @@ describe('Script', () => {
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
describe('throws when missing', () => {
|
||||
itEachAbsentObjectValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing code';
|
||||
const code: IScriptCode = absentValue;
|
||||
// act
|
||||
const construct = () => new ScriptBuilder()
|
||||
.withCode(code)
|
||||
.build();
|
||||
// assert
|
||||
expect(construct).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('canRevert', () => {
|
||||
it('returns false without revert code', () => {
|
||||
@@ -112,34 +98,34 @@ class ScriptBuilder {
|
||||
|
||||
private code: IScriptCode = new ScriptCodeStub();
|
||||
|
||||
private level = RecommendationLevel.Standard;
|
||||
private level? = RecommendationLevel.Standard;
|
||||
|
||||
private docs: readonly string[] = undefined;
|
||||
private docs: readonly string[] = [];
|
||||
|
||||
public withCodes(code: string, revertCode = ''): ScriptBuilder {
|
||||
public withCodes(code: string, revertCode = ''): this {
|
||||
this.code = new ScriptCodeStub()
|
||||
.withExecute(code)
|
||||
.withRevert(revertCode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public withCode(code: IScriptCode): ScriptBuilder {
|
||||
public withCode(code: IScriptCode): this {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withName(name: string): ScriptBuilder {
|
||||
public withName(name: string): this {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withRecommendationLevel(level: RecommendationLevel): ScriptBuilder {
|
||||
public withRecommendationLevel(level: RecommendationLevel | undefined): this {
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withDocs(urls: readonly string[]): ScriptBuilder {
|
||||
this.docs = urls;
|
||||
public withDocs(docs: readonly string[]): this {
|
||||
this.docs = docs;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user