Skip to content

Commit

Permalink
#470: Add ESLint "explicit-function-return-type".
Browse files Browse the repository at this point in the history
* To better know what value is returned by a function, without looking into the function body logic.
  • Loading branch information
benitsch committed Jun 26, 2024
1 parent 5a5a68f commit 916f0f6
Show file tree
Hide file tree
Showing 51 changed files with 360 additions and 278 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-function-return-type": "error",
"vue/no-mutating-props": "off",
"vue/attribute-hyphenation": [
"error",
Expand Down
34 changes: 17 additions & 17 deletions src/components/IntegrationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Licensed under the Elastic License 2.0. */
});
}
async function getFactories() {
async function getFactories(): Promise<ComponentFactory[]> {
return componentsApi
.listComponents('observation')
.then((response: any) => response.data);
Expand Down Expand Up @@ -195,20 +195,24 @@ Licensed under the Elastic License 2.0. */
},
];
function executeAction(action: MoreTableRowActionResult) {
function executeAction(action: MoreTableRowActionResult): void {
const row = action.row as MoreIntegrationTableMap;
switch (action.id) {
case 'delete':
return deleteIntegration(row);
deleteIntegration(row);
break;
case 'clone':
return createIntegration({
createIntegration({
observationId: row.observationId,
tokenLabel: row.tokenLabel,
} as MoreIntegrationLink);
break;
}
}
async function updateIntegration(integration: MoreIntegrationTableMap) {
async function updateIntegration(
integration: MoreIntegrationTableMap,
): Promise<void> {
await observationsApi
.updateTokenLabel(
props.studyId,
Expand All @@ -230,7 +234,7 @@ Licensed under the Elastic License 2.0. */
);
}
async function openIntegrationDialog(headerText: string) {
async function openIntegrationDialog(headerText: string): Promise<void> {
dialog.open(IntegrationDialog, {
data: {
observationList: observationList,
Expand All @@ -257,7 +261,9 @@ Licensed under the Elastic License 2.0. */
});
}
async function deleteIntegration(integration: MoreIntegrationTableMap) {
async function deleteIntegration(
integration: MoreIntegrationTableMap,
): Promise<void> {
await observationsApi
.deleteToken(
props.studyId,
Expand All @@ -273,15 +279,9 @@ Licensed under the Elastic License 2.0. */
});
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getObservationTokens(studyId: number, observationId: number) {
await observationsApi.getTokens(studyId, observationId).then((request) => {
return request;
});
}
getObservationTokens(props.studyId, 1);
async function createIntegration(integrationCreate: MoreIntegrationLink) {
async function createIntegration(
integrationCreate: MoreIntegrationLink,
): Promise<void> {
await observationsApi
.createToken(props.studyId, integrationCreate.observationId, {
tokenId: 0,
Expand All @@ -301,7 +301,7 @@ Licensed under the Elastic License 2.0. */
});
}
function openInfoDialog(token: EndpointToken) {
function openInfoDialog(token: EndpointToken): void {
dialog.open(CopyTokenDialog, {
data: {
title: `${token.tokenLabel} (Id: ${token.tokenId})`,
Expand Down
55 changes: 37 additions & 18 deletions src/components/InterventionsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ Licensed under the Elastic License 2.0. */
});
}
async function listActions(interventionId?: number) {
async function listActions(
interventionId?: number,
): Promise<Action[] | undefined> {
if (interventionId) {
return interventionsApi
.listActions(props.studyId, interventionId)
Expand All @@ -192,7 +194,10 @@ Licensed under the Elastic License 2.0. */
return undefined;
}
}
async function getTrigger(interventionId?: number) {
async function getTrigger(
interventionId?: number,
): Promise<Trigger | undefined> {
if (interventionId) {
return interventionsApi
.getTrigger(props.studyId, interventionId)
Expand All @@ -202,25 +207,28 @@ Licensed under the Elastic License 2.0. */
}
}
function executeAction(action: MoreTableRowActionResult) {
function executeAction(action: MoreTableRowActionResult): void {
const row = action.row as Intervention;
switch (action.id) {
case 'delete':
return deleteIntervention(row);
deleteIntervention(row);
break;
case 'clone':
return openInterventionDialog(
openInterventionDialog(
t('intervention.dialog.header.clone'),
row,
true,
);
break;
case 'edit':
return openEditIntervention(row.interventionId);
openEditIntervention(row.interventionId);
break;
default:
console.error('no handler for action', action);
}
}
async function changeValue(intervention: Intervention) {
async function changeValue(intervention: Intervention): Promise<void> {
await interventionsApi
.updateIntervention(
props.studyId,
Expand All @@ -236,7 +244,9 @@ Licensed under the Elastic License 2.0. */
);
}
async function deleteIntervention(requestIntervention: Intervention) {
async function deleteIntervention(
requestIntervention: Intervention,
): Promise<void> {
await interventionsApi
.deleteIntervention(
props.studyId,
Expand All @@ -251,7 +261,7 @@ Licensed under the Elastic License 2.0. */
);
}
async function createIntervention(object: any) {
async function createIntervention(object: any): Promise<void> {
const interventionId: number | undefined = await addIntervention(
object.intervention,
);
Expand All @@ -266,7 +276,7 @@ Licensed under the Elastic License 2.0. */
}
}
async function addIntervention(intervention: Intervention) {
async function addIntervention(intervention: Intervention): Promise<number> {
return interventionsApi
.addIntervention(props.studyId, intervention)
.then((response: AxiosResponse) => response.data.interventionId)
Expand All @@ -275,7 +285,10 @@ Licensed under the Elastic License 2.0. */
);
}
async function createAction(interventionId: number, action: Action) {
async function createAction(
interventionId: number,
action: Action,
): Promise<void> {
await interventionsApi
.createAction(props.studyId, interventionId, action)
.then(listInterventions)
Expand All @@ -288,31 +301,37 @@ Licensed under the Elastic License 2.0. */
interventionId: number,
actionId: number,
action: Action,
) {
): Promise<void> {
await interventionsApi
.updateAction(props.studyId, interventionId, actionId, action)
.catch((e: AxiosError) =>
handleIndividualError(e, `Cannot update action: ${action.actionId}`),
);
}
async function deleteAction(interventionId: number, actionId: number) {
async function deleteAction(
interventionId: number,
actionId: number,
): Promise<void> {
await interventionsApi
.deleteAction(props.studyId, interventionId, actionId)
.catch((e: AxiosError) =>
handleIndividualError(e, `Cannot delete action: ${actionId}`),
);
}
async function updateTrigger(interventionId: number, trigger: Trigger) {
async function updateTrigger(
interventionId: number,
trigger: Trigger,
): Promise<void> {
await interventionsApi
.updateTrigger(props.studyId, interventionId, trigger)
.catch((e: AxiosError) =>
handleIndividualError(e, `Cannot create trigger on: ${interventionId}`),
);
}
async function updateInterventionData(object: any) {
async function updateInterventionData(object: any): Promise<void> {
await updateIntervention(object.intervention);
if (object.intervention.interventionId) {
Expand Down Expand Up @@ -340,7 +359,7 @@ Licensed under the Elastic License 2.0. */
}
}
async function updateIntervention(intervention: Intervention) {
async function updateIntervention(intervention: Intervention): Promise<void> {
await interventionsApi
.updateIntervention(
props.studyId,
Expand All @@ -356,7 +375,7 @@ Licensed under the Elastic License 2.0. */
);
}
function openEditIntervention(interventionId: number | undefined) {
function openEditIntervention(interventionId: number | undefined): void {
const intervention = interventionList.value.find(
(i) => i.interventionId === interventionId,
);
Expand All @@ -376,7 +395,7 @@ Licensed under the Elastic License 2.0. */
headerText: string,
intervention?: Intervention,
clone?: boolean,
) {
): void {
Promise.all([
listActions(intervention?.interventionId),
getTrigger(intervention?.interventionId),
Expand Down
38 changes: 20 additions & 18 deletions src/components/ObservationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Licensed under the Elastic License 2.0. */
value: null,
} as MoreTableChoice);
async function getFactories() {
async function getFactories(): Promise<ComponentFactory[]> {
return componentsApi
.listComponents('observation')
.then((response: any) => response.data);
Expand All @@ -85,7 +85,7 @@ Licensed under the Elastic License 2.0. */
const observationTypes: any[] = factories.map((cf: ComponentFactory) => ({
label: cf.title ? t(cf.title) : '',
value: cf.componentId,
command: () => {
command: (): void => {
openObservationDialog(t('observation.dialog.header.create'), {
type: cf.componentId,
});
Expand Down Expand Up @@ -223,7 +223,7 @@ Licensed under the Elastic License 2.0. */
},
];
function getObservationTypeString(observationType: string) {
function getObservationTypeString(observationType: string): string {
return t(
factories.find((f) => f.componentId === observationType)?.title as string,
);
Expand Down Expand Up @@ -326,25 +326,24 @@ Licensed under the Elastic License 2.0. */
return '';
}
function executeAction(action: MoreTableRowActionResult) {
function executeAction(action: MoreTableRowActionResult): void {
const row = action.row as Observation;
switch (action.id) {
case 'delete':
return deleteObservation(row);
deleteObservation(row);
break;
case 'clone':
return openObservationDialog(
t('observation.dialog.header.clone'),
row,
true,
);
openObservationDialog(t('observation.dialog.header.clone'), row, true);
break;
case 'edit':
return openEditObservation(row.observationId);
openEditObservation(row.observationId);
break;
default:
console.error('no handler for action', action);
}
}
async function updateObservation(observation: Observation) {
async function updateObservation(observation: Observation): Promise<void> {
await observationsApi
.updateObservation(
props.studyId,
Expand All @@ -360,7 +359,9 @@ Licensed under the Elastic License 2.0. */
);
}
async function deleteObservation(requestObservation: Observation) {
async function deleteObservation(
requestObservation: Observation,
): Promise<void> {
await observationsApi
.deleteObservation(
props.studyId,
Expand All @@ -375,15 +376,15 @@ Licensed under the Elastic License 2.0. */
);
}
function factoryForType(type?: string) {
function factoryForType(type?: string): ComponentFactory | undefined {
return factories.find((f) => f.componentId === type);
}
function openObservationDialog(
headerText: string,
observation?: Observation,
clone?: boolean,
) {
): void {
dialog.open(ObservationDialog, {
data: {
groupStates: groupStatuses,
Expand Down Expand Up @@ -421,7 +422,7 @@ Licensed under the Elastic License 2.0. */
});
}
function createObservation(newObservation: Observation) {
function createObservation(newObservation: Observation): void {
observationsApi
.addObservation(props.studyId, newObservation)
.then(listObservations)
Expand All @@ -430,7 +431,7 @@ Licensed under the Elastic License 2.0. */
);
}
function openEditObservation(observationId: number | undefined) {
function openEditObservation(observationId: number | undefined): void {
const observation = observationList.value.find(
(observation) => observation.observationId === observationId,
);
Expand All @@ -445,10 +446,11 @@ Licensed under the Elastic License 2.0. */
openObservationDialog(dialogTitle, observation);
}
}
listObservations();
const menu = ref();
function toggleButtonMenu(event: MouseEvent) {
function toggleButtonMenu(event: MouseEvent): void {
menu.value.toggle(event);
}
</script>
Expand Down
Loading

0 comments on commit 916f0f6

Please sign in to comment.