]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Fix Code Smells
authorguillaume-peoch-sonarsource <guillaume.peoch@sonarsource.com>
Tue, 13 Jun 2023 14:44:02 +0000 (16:44 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 14 Jun 2023 12:35:53 +0000 (12:35 +0000)
server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx
server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx
server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx
server/sonar-web/src/main/js/apps/overview/components/App.tsx
server/sonar-web/src/main/js/apps/quality-gates/utils.ts
server/sonar-web/src/main/js/apps/users/components/UserListItem.tsx
server/sonar-web/src/main/js/components/controls/ManagedFilter.tsx
server/sonar-web/src/main/js/components/rules/RuleTabViewer.tsx

index 686e7c50a7c25e4740add24dafaf2580c4713a78..429b0d4a1e940bc9ca83387480f569af1dd37af9 100644 (file)
@@ -36,7 +36,8 @@ jest.mock('lodash', () => {
 });
 
 it('should display system announcement', async () => {
-  (getValues as jest.Mock)
+  jest
+    .mocked(getValues)
     .mockResolvedValueOnce([
       {
         key: 'sonar.announcement.displayMessage',
index 92d438cd1f70dfda6bffc85e612d21802060ba4e..e1a2ddc03de3ba0254305cec574bb40db6b0e750 100644 (file)
@@ -30,7 +30,7 @@ jest.mock('../../../../api/metrics', () => ({
 
 it('should call metric', async () => {
   const metrics = { coverage: mockMetric() };
-  (getAllMetrics as jest.Mock).mockResolvedValueOnce(Object.values(metrics));
+  jest.mocked(getAllMetrics).mockResolvedValueOnce(Object.values(metrics));
   const wrapper = shallowRender();
 
   expect(getAllMetrics).toHaveBeenCalled();
index afdf7ead08ee541a893f8ab179589a8f4198b44d..dbacff254173cc00c7066359488add4a3b6553c7 100644 (file)
@@ -389,7 +389,7 @@ describe('security page', () => {
   });
 
   it("should not suggest creating a Project token if the user doesn't have at least one scannable Projects", () => {
-    (getScannableProjects as jest.Mock).mockResolvedValueOnce({
+    jest.mocked(getScannableProjects).mockResolvedValueOnce({
       projects: [],
     });
     renderAccountApp(
@@ -402,7 +402,7 @@ describe('security page', () => {
   });
 
   it('should preselect the user token type if the user has no scan rights', async () => {
-    (getScannableProjects as jest.Mock).mockResolvedValueOnce({
+    jest.mocked(getScannableProjects).mockResolvedValueOnce({
       projects: [],
     });
     renderAccountApp(mockLoggedInUser(), securityPagePath);
@@ -412,7 +412,7 @@ describe('security page', () => {
   });
 
   it('should preselect the only project the user has access to if they select project token', async () => {
-    (getScannableProjects as jest.Mock).mockResolvedValueOnce({
+    jest.mocked(getScannableProjects).mockResolvedValueOnce({
       projects: [
         {
           key: 'project-key-1',
index 73be0c7cc867855814b381e1486c9eb9f32a3a65..b3af0f38b155ca45284739c03f2bc27de7f6ba99 100644 (file)
@@ -69,7 +69,7 @@ export function App(props: AppProps) {
               branchLike={branchLike}
               branchLikes={branchLikes}
               component={component}
-              hasAnalyses={isPending || isInProgress}
+              hasAnalyses={isPending ?? isInProgress}
               projectBinding={projectBinding}
             />
           )}
index 502f32cb511938a792683d343333f379a079087c..df0f6dd6c6eee809bc979bc5b95e30960d5bad15 100644 (file)
@@ -243,7 +243,7 @@ export function getPossibleOperators(metric: Metric) {
 }
 
 function metricKeyExists(key: string, metrics: Dict<Metric>) {
-  return metrics && metrics[key] !== undefined;
+  return metrics[key] !== undefined;
 }
 
 function getNoDiffMetric(metric: Metric, metrics: Dict<Metric>) {
index a3840b67f3a5244f709163513128d9cadfb4b472..cd6bdef46f0429337c69a9f1d55e2ac63bcfa69c 100644 (file)
@@ -80,7 +80,7 @@ export default function UserListItem(props: UserListItemProps) {
       </td>
       <td className="thin nowrap text-middle">
         <UserGroups
-          groups={user.groups || []}
+          groups={user.groups ?? []}
           manageProvider={manageProvider}
           onUpdateUsers={onUpdateUsers}
           user={user}
index 846d5959dcdc9e622761a9936728c408937a53d6..4f25eeb57e14b8fc49d4054df38ad3fbd36883ba 100644 (file)
@@ -38,7 +38,7 @@ export function ManagedFilter(props: ManagedFilterProps) {
   return (
     <div className="big-spacer-right">
       <ButtonToggle
-        value={managed === undefined ? 'all' : managed}
+        value={managed ?? 'all'}
         disabled={loading}
         options={[
           { label: translate('all'), value: 'all' },
index 3e2b7852626cfda7b9a5af42b6f4bc26bf766ba7..33528e4f61c24a0c13bf701fad1a347a1a9b1dad 100644 (file)
@@ -98,7 +98,7 @@ export class RuleTabViewer extends React.PureComponent<RuleTabViewerProps, State
     const query = new URLSearchParams(this.props.location.search);
     if (query.has('why')) {
       this.setState({
-        selectedTab: tabs.find((tab) => tab.key === TabKeys.WhyIsThisAnIssue) || tabs[0],
+        selectedTab: tabs.find((tab) => tab.key === TabKeys.WhyIsThisAnIssue) ?? tabs[0],
       });
     }
   }