]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Fix returning promises where void is expected
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 13 Jun 2023 09:03:50 +0000 (11:03 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 13 Jun 2023 20:03:37 +0000 (20:03 +0000)
12 files changed:
server/sonar-web/src/main/js/app/components/branch-status/BranchStatusContextProvider.tsx
server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationHelper.ts
server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx
server/sonar-web/src/main/js/apps/create/project/BitbucketCloud/BitbucketCloudProjectCreate.tsx
server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx
server/sonar-web/src/main/js/apps/create/project/Github/GitHubProjectCreate.tsx
server/sonar-web/src/main/js/apps/create/project/Gitlab/GitlabProjectCreate.tsx
server/sonar-web/src/main/js/apps/permission-templates/components/Template.tsx
server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisList.tsx
server/sonar-web/src/main/js/components/controls/SelectList.tsx
server/sonar-web/src/main/js/components/controls/ValidationForm.tsx
server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx

index 8ff18aefaa45b7791ed15fe4ab80bc8a6b8c026c..cf2d2ba32794d3b1acae3f411c500268e1b1f8f3 100644 (file)
@@ -89,7 +89,11 @@ export default class BranchStatusContextProvider extends React.PureComponent<{},
       <BranchStatusContext.Provider
         value={{
           branchStatusByComponent: this.state.branchStatusByComponent,
-          fetchBranchStatus: this.fetchBranchStatus,
+          fetchBranchStatus: (branchLike: BranchLike, projectKey: string) => {
+            this.fetchBranchStatus(branchLike, projectKey).catch(() => {
+              /* noop */
+            });
+          },
           updateBranchStatus: this.updateBranchStatus,
         }}
       >
index 1eb4396e0e301fc7a4f67e18285726cb6a3e9749..1840a9178a97fb7f4b5f68d90640745ea77bb3eb 100644 (file)
@@ -28,15 +28,18 @@ const LS_INDEXATION_COMPLETED_NOTIFICATION_SHOULD_BE_DISPLAYED =
 export default class IndexationNotificationHelper {
   private static interval?: NodeJS.Timeout;
 
-  static startPolling(onNewStatus: (status: IndexationStatus) => void) {
+  static async startPolling(onNewStatus: (status: IndexationStatus) => void) {
     this.stopPolling();
 
-    // eslint-disable-next-line promise/catch-or-return
-    this.poll(onNewStatus).then((status) => {
-      if (!status.isCompleted) {
-        this.interval = setInterval(() => this.poll(onNewStatus), POLLING_INTERVAL_MS);
-      }
-    });
+    const status = await this.poll(onNewStatus);
+
+    if (!status.isCompleted) {
+      this.interval = setInterval(() => {
+        this.poll(onNewStatus).catch(() => {
+          /* noop */
+        });
+      }, POLLING_INTERVAL_MS);
+    }
   }
 
   static stopPolling() {
index 8c8fb3fa673a53c6bef0c1e1db0494cdeeb90030..a65f7c57fe1f3374d1ae8babb3b63d9df2e606e9 100644 (file)
@@ -84,7 +84,11 @@ export default class AzureProjectCreate extends React.PureComponent<Props, State
 
   componentDidUpdate(prevProps: Props) {
     if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
-      this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => this.fetchData());
+      this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => {
+        this.fetchData().catch(() => {
+          /* noop */
+        });
+      });
     }
   }
 
@@ -286,7 +290,11 @@ export default class AzureProjectCreate extends React.PureComponent<Props, State
   onSelectedAlmInstanceChange = (instance: AlmSettingsInstance) => {
     this.setState(
       { selectedAlmInstance: instance, searchResults: undefined, searchQuery: '' },
-      () => this.fetchData()
+      () => {
+        this.fetchData().catch(() => {
+          /* noop */
+        });
+      }
     );
   };
 
index dd4bf7a1c968380cf0ccec51e7fa359eac0661e6..41adf4c9baa8ddd5bb468c6b2d59a7bdb0a3de93 100644 (file)
@@ -78,7 +78,11 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent<Pro
 
   componentDidUpdate(prevProps: Props) {
     if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
-      this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => this.fetchData());
+      this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => {
+        this.fetchData().catch(() => {
+          /* noop */
+        });
+      });
     }
   }
 
@@ -146,11 +150,17 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent<Pro
         projectsPaging: { pageIndex: 1, pageSize: BITBUCKET_CLOUD_PROJECTS_PAGESIZE },
         searchQuery,
       },
-      async () => {
-        await this.fetchData();
-        if (this.mounted) {
-          this.setState({ searching: false });
-        }
+      () => {
+        this.fetchData().then(
+          () => {
+            if (this.mounted) {
+              this.setState({ searching: false });
+            }
+          },
+          () => {
+            /* noop */
+          }
+        );
       }
     );
   };
@@ -164,11 +174,17 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent<Pro
           pageSize: state.projectsPaging.pageSize,
         },
       }),
-      async () => {
-        await this.fetchData(true);
-        if (this.mounted) {
-          this.setState({ loadingMore: false });
-        }
+      () => {
+        this.fetchData(true).then(
+          () => {
+            if (this.mounted) {
+              this.setState({ loadingMore: false });
+            }
+          },
+          () => {
+            /* noop */
+          }
+        );
       }
     );
   };
index af60cb12b31812a8feeaf1d4fc7397b6ee9267c5..49f19542cb18f4e5f43c42b30c53d658a4b9217e 100644 (file)
@@ -77,9 +77,11 @@ export default class BitbucketProjectCreate extends React.PureComponent<Props, S
 
   componentDidUpdate(prevProps: Props) {
     if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
-      this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () =>
-        this.fetchInitialData()
-      );
+      this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => {
+        this.fetchInitialData().catch(() => {
+          /* noop */
+        });
+      });
     }
   }
 
index ec40e48c34c37c691cb49dcbdeded04dc642df49..a07808a46ba821b27b8b2bb2d8e2841078a17159 100644 (file)
@@ -86,9 +86,11 @@ export default class GitHubProjectCreate extends React.Component<Props, State> {
 
   componentDidUpdate(prevProps: Props) {
     if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
-      this.setState({ selectedAlmInstance: this.getInitialSelectedAlmInstance() }, () =>
-        this.initialize()
-      );
+      this.setState({ selectedAlmInstance: this.getInitialSelectedAlmInstance() }, () => {
+        this.initialize().catch(() => {
+          /* noop */
+        });
+      });
     }
   }
 
@@ -292,7 +294,11 @@ export default class GitHubProjectCreate extends React.Component<Props, State> {
   onSelectedAlmInstanceChange = (instance: AlmSettingsInstance) => {
     this.setState(
       { selectedAlmInstance: instance, searchQuery: '', organizations: [], repositories: [] },
-      () => this.initialize()
+      () => {
+        this.initialize().catch(() => {
+          /* noop */
+        });
+      }
     );
   };
 
index 45b7aa4e8d7cb16d2b3792e42145b761dccbbc82..cfa49099e20e9e5be9d29b561137c2a2cdf30f80 100644 (file)
@@ -74,7 +74,11 @@ export default class GitlabProjectCreate extends React.PureComponent<Props, Stat
   componentDidUpdate(prevProps: Props) {
     const { almInstances } = this.props;
     if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
-      this.setState({ selectedAlmInstance: almInstances[0] }, () => this.fetchInitialData());
+      this.setState({ selectedAlmInstance: almInstances[0] }, () => {
+        this.fetchInitialData().catch(() => {
+          /* noop */
+        });
+      });
     }
   }
 
index 57fa927316d6c8a38db2ef7d9ede6447e1195464..e679c512546366fce9040a7b8ebc41878cdef6bf 100644 (file)
@@ -243,18 +243,34 @@ export default class Template extends React.PureComponent<Props, State> {
   };
 
   handleSearch = (query: string) => {
-    this.setState({ query }, this.requestHolders);
+    this.setState({ query }, () => {
+      this.requestHolders().catch(() => {
+        /* noop */
+      });
+    });
   };
 
   handleFilter = (filter: FilterOption) => {
-    this.setState({ filter }, this.requestHolders);
+    this.setState({ filter }, () => {
+      this.requestHolders().catch(() => {
+        /* noop */
+      });
+    });
   };
 
   handleSelectPermission = (selectedPermission: string) => {
     if (selectedPermission === this.state.selectedPermission) {
-      this.setState({ selectedPermission: undefined }, this.requestHolders);
+      this.setState({ selectedPermission: undefined }, () => {
+        this.requestHolders().catch(() => {
+          /* noop */
+        });
+      });
     } else {
-      this.setState({ selectedPermission }, this.requestHolders);
+      this.setState({ selectedPermission }, () => {
+        this.requestHolders().catch(() => {
+          /* noop */
+        });
+      });
     }
   };
 
index 11012335e5695b19cd0d145eeb07fe7a5e15e27f..74e09875f66eb0b6fe20cdd08b37db5daacb818e 100644 (file)
@@ -132,7 +132,11 @@ export default class BranchAnalysisList extends React.PureComponent<Props, State
   };
 
   handleRangeChange = ({ value }: { value: number }) => {
-    this.setState({ range: value }, () => this.fetchAnalyses());
+    this.setState({ range: value }, () => {
+      this.fetchAnalyses().catch(() => {
+        /* noop */
+      });
+    });
   };
 
   render() {
index 549a3a04e6e30de6f1c9aa068884eeb075df5bca..42454b8076a9e950ffeb935ca666ef85148ce2d1 100644 (file)
@@ -108,7 +108,7 @@ export default class SelectList extends React.PureComponent<Props, State> {
         loading: true,
         lastSearchParams: { ...prevState.lastSearchParams, ...searchParams },
       }),
-      () =>
+      () => {
         this.props
           .onSearch({
             filter: this.getFilter(),
@@ -117,7 +117,8 @@ export default class SelectList extends React.PureComponent<Props, State> {
             query: this.state.lastSearchParams.query,
           })
           .then(this.stopLoading)
-          .catch(this.stopLoading)
+          .catch(this.stopLoading);
+      }
     );
 
   changeFilter = (filter: SelectListFilter) => this.search({ filter, page: 1 });
index 87349bc8931d833f4c316ce9d8134a0204b0fdd8..18c0faeb9cb5505238160ae8e63ea21930c06c21 100644 (file)
@@ -41,18 +41,13 @@ export default class ValidationForm<V extends FormikValues> extends React.Compon
   }
 
   handleSubmit = (data: V, { setSubmitting }: FormikHelpers<V>) => {
-    const result = this.props.onSubmit(data);
     const stopSubmitting = () => {
       if (this.mounted) {
         setSubmitting(false);
       }
     };
 
-    if (result) {
-      result.then(stopSubmitting, stopSubmitting);
-    } else {
-      stopSubmitting();
-    }
+    this.props.onSubmit(data).then(stopSubmitting, stopSubmitting);
   };
 
   render() {
index 57d8309ea03be686e0bfc389c6b90ee5dac363f4..5630a63cb4c327641636c016f470199407500f4a 100644 (file)
@@ -23,7 +23,7 @@ import ValidationForm from '../ValidationForm';
 
 it('should render and submit', async () => {
   const render = jest.fn();
-  const onSubmit = jest.fn();
+  const onSubmit = jest.fn().mockResolvedValue(null);
   const setSubmitting = jest.fn();
   const wrapper = shallow(
     <ValidationForm initialValues={{ foo: 'bar' }} onSubmit={onSubmit} validate={jest.fn()}>
@@ -36,9 +36,6 @@ it('should render and submit', async () => {
     expect.objectContaining({ dirty: false, errors: {}, values: { foo: 'bar' } })
   );
 
-  wrapper.prop<Function>('onSubmit')({ foo: 'bar' }, { setSubmitting });
-  expect(setSubmitting).toHaveBeenCalledWith(false);
-
   onSubmit.mockResolvedValue(undefined).mockClear();
   setSubmitting.mockClear();
   wrapper.prop<Function>('onSubmit')({ foo: 'bar' }, { setSubmitting });