Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

=== undefined/nullを消す #1747

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/background/configMigration014.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function ({
if (fs.existsSync(configPath)) {
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));

if (config?.__internal__?.migrations?.version === undefined) {
if (config?.__internal__?.migrations?.version == undefined) {
throw new Error("configMigration014: config.json is invalid");
}

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/SelectionHelperForQInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class SelectionHelperForQInput {

// this.start が number | null なので null も受け付ける
setCursorPosition(index: number | null) {
if (index === null) return;
if (index == undefined) return;

this.nativeEl.selectionStart = this.nativeEl.selectionEnd = index;
}
Expand Down Expand Up @@ -50,7 +50,7 @@ export class SelectionHelperForQInput {
get isEmpty() {
const start = this.nativeEl.selectionStart;
const end = this.nativeEl.selectionEnd;
return start === null || end === null || start === end;
return start == undefined || end == undefined || start === end;
}

private get nativeEl() {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export function mapUndefinedPipe<T, U1, U2, U3>(
fn3: (_: NonNullable<U2>) => U3 | undefined
): U3 | undefined;
/**
* 一連の関数を実行する。途中でundefinedを返すとその後undefinedを返す
* 一連の関数を実行する。途中でundefinedかnullを返すとその後undefinedを返す
*/
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any
export function mapUndefinedPipe(source: any, ...fn: Function[]) {
return fn.reduce((prev, curr) => {
if (prev === undefined) {
if (prev == undefined) {
return undefined;
}
return curr(prev);
Expand All @@ -30,7 +30,7 @@ export const undefinedToDefault = <T>(
defaultValue: T,
maybeValue: T | undefined
): T => {
if (maybeValue === undefined) {
if (maybeValue == undefined) {
return defaultValue;
}
return maybeValue;
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/previewSliderHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const previewSliderHelper = (props: Props): PreviewSliderHelper => {
previewValue.value = value;
};
const changePreviewValue = async () => {
if (previewValue.value === null)
if (previewValue.value == null)
throw new Error("previewValue.value === null");
if (modelValue.value !== previewValue.value && props.onChange) {
await props.onChange(previewValue.value);
Expand All @@ -128,7 +128,7 @@ export const previewSliderHelper = (props: Props): PreviewSliderHelper => {
};
// start awaiting
const fireChange = () => {
if (awaitingChange !== null) awaitingChange.cancel();
if (awaitingChange != null) awaitingChange.cancel();
isAwaiting.value = true;
awaitingChange = new CancelableFinary(changePreviewValue(), endAwaiting);
};
Expand Down Expand Up @@ -165,7 +165,7 @@ export const previewSliderHelper = (props: Props): PreviewSliderHelper => {
);
// This function is called when the q-slider fire onWheel.
const onWheel = (event: Events["onWheel"]) => {
if (disableScroll.value || disable.value || currentValue.value === null)
if (disableScroll.value || disable.value || currentValue.value == null)
return;
event.preventDefault();
const deltaY = event.deltaY;
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructures/EngineConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const OpenAPIEngineConnectorFactoryImpl = (): IEngineConnectorFactory => {
return {
instance: (host: string) => {
const cached = instanceMapper[host];
if (cached !== undefined) {
if (cached != undefined) {
return cached;
}
const api = new DefaultApi(new Configuration({ basePath: host }));
Expand Down
4 changes: 2 additions & 2 deletions src/store/audioPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const audioPlayerStoreState: AudioPlayerStoreState = {
export const audioPlayerStore = createPartialStore<AudioPlayerStoreTypes>({
ACTIVE_AUDIO_ELEM_CURRENT_TIME: {
getter: (state) => {
return state._activeAudioKey !== undefined
return state._activeAudioKey != undefined
? getAudioElement().currentTime
: undefined;
},
Expand Down Expand Up @@ -61,7 +61,7 @@ export const audioPlayerStore = createPartialStore<AudioPlayerStoreTypes>({
) {
const audioElement = getAudioElement();

if (offset !== undefined) {
if (offset != undefined) {
audioElement.currentTime = offset;
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const dictionaryStore = createPartialStore<DictionaryStoreTypes>({
// 同じ単語IDで登録するために、1つのエンジンで登録したあと全エンジンに同期する。
const engineId: EngineId | undefined = state.engineIds[0];

if (engineId === undefined)
if (engineId == undefined)
throw new Error(`No such engine registered: index == 0`);
await dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
engineId,
Expand Down
8 changes: 4 additions & 4 deletions src/store/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const engineStore = createPartialStore<EngineStoreTypes>({
IS_ENGINE_READY: {
getter: (state) => (engineId) => {
const engineState: EngineState | undefined = state.engineStates[engineId];
if (engineState === undefined)
if (engineState == undefined)
throw new Error(`No such engineState set: engineId == ${engineId}`);

return engineState === "READY";
Expand All @@ -159,12 +159,12 @@ export const engineStore = createPartialStore<EngineStoreTypes>({
action: createUILockAction(
async ({ state, commit, dispatch }, { engineId }) => {
let engineState: EngineState | undefined = state.engineStates[engineId];
if (engineState === undefined)
if (engineState == undefined)
throw new Error(`No such engineState set: engineId == ${engineId}`);

for (let i = 0; i < 100; i++) {
engineState = state.engineStates[engineId]; // FIXME: explicit undefined
if (engineState === undefined)
if (engineState == undefined)
throw new Error(`No such engineState set: engineId == ${engineId}`);

if (engineState === "FAILED_STARTING") {
Expand Down Expand Up @@ -268,7 +268,7 @@ export const engineStore = createPartialStore<EngineStoreTypes>({
DETECTED_ENGINE_ERROR: {
action({ state, commit }, { engineId }) {
const engineState: EngineState | undefined = state.engineStates[engineId];
if (engineState === undefined)
if (engineState == undefined)
throw new Error(`No such engineState set: engineId == ${engineId}`);

switch (engineState) {
Expand Down
4 changes: 2 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
const defaultStyleId = defaultStyleIds.find(
(styleId) => styleId.speakerUuid == speakerUuid
);
if (defaultStyleId === undefined) {
if (defaultStyleId == undefined) {
return true;
}

Expand Down Expand Up @@ -244,7 +244,7 @@ export const indexStore = createPartialStore<IndexStoreTypes>({
audioItem.voice.styleId
);

if (characterInfo === undefined)
if (characterInfo == undefined)
throw new Error("assert characterInfo !== undefined");

const speakerUuid = characterInfo.metas.speakerUuid;
Expand Down
6 changes: 3 additions & 3 deletions src/store/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ export const presetStore = createPartialStore<PresetStoreTypes>({

const presetConfig = await window.electron.getSetting("presets");
if (
presetConfig === undefined ||
presetConfig.items === undefined ||
presetConfig.keys === undefined
presetConfig == undefined ||
presetConfig.items == undefined ||
presetConfig.keys == undefined
)
return;
commit("SET_PRESET_ITEMS", {
Expand Down
6 changes: 3 additions & 3 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({

// set phoneme length
// 0.7 未満のプロジェクトファイルは styleId ではなく characterIndex なので、ここだけ characterIndex とした
if (audioItem.characterIndex === undefined)
if (audioItem.characterIndex == undefined)
throw new Error("audioItem.characterIndex === undefined");
await context
.dispatch("FETCH_MORA_DATA", {
Expand Down Expand Up @@ -227,7 +227,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
) {
for (const audioItemsKey in projectData.audioItems) {
const audioItem = projectData.audioItems[audioItemsKey];
if (audioItem.speaker !== null) {
if (audioItem.speaker != null) {
audioItem.styleId = audioItem.speaker;
delete audioItem.speaker;
}
Expand All @@ -239,7 +239,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
) {
for (const audioItemsKey in projectData.audioItems) {
const audioItem = projectData.audioItems[audioItemsKey];
if (audioItem.engineId === undefined) {
if (audioItem.engineId == undefined) {
audioItem.engineId = engineId;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const proxyStoreCreator = (_engineFactory: IEngineConnectorFactory) => {
action({ state }, payload) {
const engineId = payload.engineId;
const engineInfo: EngineInfo | undefined = state.engineInfos[engineId];
if (engineInfo === undefined)
if (engineInfo == undefined)
return Promise.reject(
new Error(`No such engineInfo registered: engineId == ${engineId}`)
);
Expand Down
2 changes: 1 addition & 1 deletion src/store/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function replaceTag(
): string {
const result = template.replace(/\$(.+?)\$/g, (match, p1) => {
const replaceTagId = replaceTagStringToTagId[p1];
if (replaceTagId === undefined) {
if (replaceTagId == undefined) {
return match;
}
return replacer[replaceTagId] ?? "";
Expand Down
2 changes: 1 addition & 1 deletion src/type/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const failure: Failure = <C extends string>(
error: codeOrError,
};
} else if (codeOrError == undefined || typeof codeOrError === "string") {
if (error === undefined) {
if (error == undefined) {
throw new Error("Error must be specified");
}
return { ok: false as const, code: codeOrError, error };
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/lib/map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,4 @@ describe("undefinedToDefault", () => {
const defaultValue = "test";
expect(undefinedToDefault(defaultValue, undefined)).toEqual(defaultValue);
});

it("undefinedのみを値がない状態とみなす", () => {
const defaultValue = "test";
expect(undefinedToDefault(defaultValue, null)).toBeNull();
});
sevenc-nanashi marked this conversation as resolved.
Show resolved Hide resolved
});
Loading