Skip to content

FE: Cleanup lint warnings Part VI - #44741

Merged
RachelElysia merged 2 commits into
mainfrom
lint-warnings-vi
May 5, 2026
Merged

FE: Cleanup lint warnings Part VI#44741
RachelElysia merged 2 commits into
mainfrom
lint-warnings-vi

Conversation

@RachelElysia

@RachelElysia RachelElysia commented May 5, 2026

Copy link
Copy Markdown
Member

Every change is either:

  • Removing dead return false values (no behavior change)
  • Replacing catch (e: any) with catch (e) + safe error extraction (same behavior, better types)
  • Typing location: any with what's actually used (narrower, safer)
  • Using an existing helper (hasStatusKey, getErrorReason) instead of raw property access (safer against unexpected error shapes)
  • Adding a TODO comment on an any that can't be easily fixed

Summary by CodeRabbit

  • Refactor
    • Strengthened type safety across authentication and form pages.
    • Improved error handling consistency in API request handlers.
    • Removed unused imports and added code quality documentation.

@codecov

codecov Bot commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.68%. Comparing base (8140d1b) to head (5c65562).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
frontend/interfaces/errors.ts 0.00% 1 Missing ⚠️
.../AddCustomVariableModal/AddCustomVariableModal.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #44741   +/-   ##
=======================================
  Coverage   66.68%   66.68%           
=======================================
  Files        2652     2652           
  Lines      213674   213674           
  Branches     9698     9698           
=======================================
  Hits       142483   142483           
  Misses      58228    58228           
  Partials    12963    12963           
Flag Coverage Δ
frontend 54.20% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RachelElysia
RachelElysia marked this pull request as ready for review May 5, 2026 15:41
@RachelElysia
RachelElysia requested a review from a team as a code owner May 5, 2026 15:41
Copilot AI review requested due to automatic review settings May 5, 2026 15:41

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the frontend lint/typing cleanup effort by removing unnecessary return false statements, tightening some location prop typings, and improving error handling by avoiding catch (e: any) and using safer helpers (getErrorReason, hasStatusKey) for unknown error shapes.

Changes:

  • Narrowed several location: any props to the specific fields used (hash / query) in a few route components.
  • Replaced catch (e: any) with catch (e) and safer error extraction (String(...), getErrorReason, hasStatusKey).
  • Removed dead/unused returns (return false) and an unused import.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
frontend/router/components/AuthenticatedRoutes/AuthenticatedRoutes.tsx Narrows location typing to hash.
frontend/pages/ResetPasswordPage/ResetPasswordPage.tsx Narrows location typing to query.token.
frontend/pages/RegistrationPage/RegistrationPage.tsx Removes dead return false from page navigation guard.
frontend/pages/queries/live/screens/RunQuery.tsx Removes dead returns; uses String(...) for safer caught error conversion.
frontend/pages/queries/edit/EditQueryPage.tsx Drops : any in catch blocks; uses getErrorReason with unknown.
frontend/pages/policies/ManagePoliciesPage/components/PoliciesTable/PoliciesTableConfig.tsx Adds TODO context around any header props typing.
frontend/pages/policies/live/screens/RunQuery.tsx Removes dead returns; makes error shape checks safe before "message" in ....
frontend/pages/policies/edit/screens/QueryEditor.tsx Switches to getErrorReason instead of deep property access into error payloads.
frontend/pages/ManageControlsPage/Variables/components/AddCustomVariableModal/AddCustomVariableModal.tsx Uses hasStatusKey guard before checking error.status.
frontend/pages/LogoutPage/LogoutPage.tsx Removes dead return renderFlash(...).
frontend/pages/LoginPage/LoginPage.tsx Removes dead return false from SSO error path.
frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx Removes a lint suppression comment; removes dead return false.
frontend/pages/hosts/details/cards/Software/HostSoftwareTable/HostSoftwareTable.tsx Removes unused isAndroid import.
frontend/pages/ConfirmSSOInvitePage/ConfirmSSOInvitePage.tsx Narrows location typing to query.email/name.
frontend/pages/ApiOnlyUser/ApiOnlyUser.tsx Removes dead return false in catch.
frontend/pages/admin/UserManagementPage/EditUserPage/EditUserPage.tsx Narrows location typing to optional query.type.
frontend/pages/AccountPage/AccountSidePanel/AccountSidePanel.tsx Removes dead return false in catch.
frontend/interfaces/errors.ts Improves hasStatusKey typing by avoiding any cast.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 132 to 137
interface IManageHostsProps {
route: RouteProps;
router: InjectedRouter;
params: Params;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
location: any; // no type in react-router v3 TODO: Improve this type
}
id: "selection",
// TODO: headerProps is `any` because local IHeaderProps is a simplified
// subset of react-table's HeaderProps. Fixing requires refactoring
// IDataColumn/IHeaderProps to align with react-table's actual types.
@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR refactors the frontend codebase to improve type safety and consistency. Changes include: replacing any types with specific interface definitions for page location props (adding structured query fields for email, name, token, and type); hardening error handling by importing and using the hasStatusKey type guard instead of unsafe any casts; standardizing function return statements by replacing explicit return false with bare return in early-exit scenarios; adopting the getErrorReason utility for safer error message extraction; removing an unused import; and adding a TODO comment documenting type alignment concerns.

Possibly related PRs

  • fleetdm/fleet#43810: Modifies the same AddCustomVariableModal component that receives error handling improvements in this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'FE: Cleanup lint warnings Part VI' accurately reflects the main objective of the pull request, which is a systematic cleanup of TypeScript lint warnings across multiple frontend files.
Description check ✅ Passed The pull request description clearly outlines five categories of changes made, each with proper explanations. However, the description does not follow the repository's template structure for checklist items or testing documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lint-warnings-vi

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/pages/policies/live/screens/RunQuery.tsx (1)

165-188: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Missing fallback flash for non-object errors in catch path.

On Line [173], the generic flash now only runs when campaignError is an object with message. Primitive errors (e.g., string errors other than "resource already created") can silently teardown with no user feedback.

💡 Proposed fix
-    } catch (campaignError) {
-      if (campaignError === "resource already created") {
+    } catch (campaignError) {
+      if (campaignError === "resource already created") {
         renderFlash(
           "error",
           "A campaign with the provided query text has already been created"
         );
-      }
-
-      if (
+      } else if (
         typeof campaignError === "object" &&
         campaignError !== null &&
         "message" in campaignError
       ) {
         const { message } = campaignError as { message: string };
@@
         } else {
           renderFlash("error", "Something has gone wrong. Please try again.");
         }
+      } else {
+        renderFlash("error", "Something has gone wrong. Please try again.");
       }
 
       return teardownDistributedQuery();
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/pages/policies/live/screens/RunQuery.tsx` around lines 165 - 188,
The catch block handling campaignError in RunQuery.tsx only shows a generic
flash when campaignError is an object with a message, so primitive errors (e.g.,
strings other than "resource already created") produce no user feedback; update
the catch in the async handler (the block referencing campaignError and
renderFlash) to add a final fallback branch that calls renderFlash("error",
"Something has gone wrong. Please try again.") for all other cases (including
non-object/primitive errors) after the existing checks so any thrown value
triggers a user-visible error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/pages/ConfirmSSOInvitePage/ConfirmSSOInvitePage.tsx`:
- Around line 16-18: Change the prop type for location.query to be optional
(location: { query?: { email?: string; name?: string } }) and update the
destructuring/reading of email and name in ConfirmSSOInvitePage (the place where
you currently destructure from location.query) to use optional chaining or a
guarded fallback (e.g., const { email, name } = location.query ?? {} or
reference location.query?.email / location.query?.name) so the code matches the
defensive pattern used elsewhere like EditUserPage.

---

Outside diff comments:
In `@frontend/pages/policies/live/screens/RunQuery.tsx`:
- Around line 165-188: The catch block handling campaignError in RunQuery.tsx
only shows a generic flash when campaignError is an object with a message, so
primitive errors (e.g., strings other than "resource already created") produce
no user feedback; update the catch in the async handler (the block referencing
campaignError and renderFlash) to add a final fallback branch that calls
renderFlash("error", "Something has gone wrong. Please try again.") for all
other cases (including non-object/primitive errors) after the existing checks so
any thrown value triggers a user-visible error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 86d95b54-62ac-4f37-9712-87b97285e765

📥 Commits

Reviewing files that changed from the base of the PR and between 227e94d and 5c65562.

📒 Files selected for processing (18)
  • frontend/interfaces/errors.ts
  • frontend/pages/AccountPage/AccountSidePanel/AccountSidePanel.tsx
  • frontend/pages/ApiOnlyUser/ApiOnlyUser.tsx
  • frontend/pages/ConfirmSSOInvitePage/ConfirmSSOInvitePage.tsx
  • frontend/pages/LoginPage/LoginPage.tsx
  • frontend/pages/LogoutPage/LogoutPage.tsx
  • frontend/pages/ManageControlsPage/Variables/components/AddCustomVariableModal/AddCustomVariableModal.tsx
  • frontend/pages/RegistrationPage/RegistrationPage.tsx
  • frontend/pages/ResetPasswordPage/ResetPasswordPage.tsx
  • frontend/pages/admin/UserManagementPage/EditUserPage/EditUserPage.tsx
  • frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx
  • frontend/pages/hosts/details/cards/Software/HostSoftwareTable/HostSoftwareTable.tsx
  • frontend/pages/policies/ManagePoliciesPage/components/PoliciesTable/PoliciesTableConfig.tsx
  • frontend/pages/policies/edit/screens/QueryEditor.tsx
  • frontend/pages/policies/live/screens/RunQuery.tsx
  • frontend/pages/queries/edit/EditQueryPage.tsx
  • frontend/pages/queries/live/screens/RunQuery.tsx
  • frontend/router/components/AuthenticatedRoutes/AuthenticatedRoutes.tsx
💤 Files with no reviewable changes (4)
  • frontend/pages/AccountPage/AccountSidePanel/AccountSidePanel.tsx
  • frontend/pages/ApiOnlyUser/ApiOnlyUser.tsx
  • frontend/pages/hosts/details/cards/Software/HostSoftwareTable/HostSoftwareTable.tsx
  • frontend/pages/LoginPage/LoginPage.tsx

Comment on lines +16 to +18
location: {
query: { email?: string; name?: string };
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Cross-check how this route is mounted and whether query is guaranteed.
rg -n -C3 'ConfirmSSOInvitePage|confirm-invite|invite_token' frontend/router frontend/pages
rg -n -C2 '\blocation\.query\b' frontend/pages/ConfirmSSOInvitePage frontend/router

# Expected:
# - If route plumbing always provides query object, current typing is acceptable.
# - Otherwise, make query optional and update reads to optional chaining/defaults.

Repository: fleetdm/fleet

Length of output: 7791


🏁 Script executed:

# Check for react-router types/definitions in the codebase
fd -e ts -e tsx | xargs grep -l "react-router" | head -20

# Look at package.json to confirm react-router version
cat package.json | grep -A2 "react-router"

# Check ResetPasswordPage mentioned in the original comment
fd "ResetPasswordPage" -type f

# Look for location.query patterns in the codebase to see how it's commonly handled
rg "location\.query" frontend/ -A2 -B2 | head -40

Repository: fleetdm/fleet

Length of output: 4868


🏁 Script executed:

# Find ResetPasswordPage to see the comparison mentioned in the original comment
fd "ResetPasswordPage" -type f

# Check package.json for more react-router type info
cat package.json | grep -A5 -B5 "react-router"

# Look at one of the pages that uses location.query to see how it's typed
cat -n frontend/pages/queries/details/QueryDetailsPage/QueryDetailsPage.tsx | head -50

# Check if there's a type definition for location in the codebase
rg "location:" frontend/ -A3 -B1 | head -60

Repository: fleetdm/fleet

Length of output: 6985


🏁 Script executed:

# Get the full location interface definition from QueryDetailsPage
cat -n frontend/pages/queries/details/QueryDetailsPage/QueryDetailsPage.tsx | sed -n '47,60p'

# Find and check ResetPasswordPage
fd "ResetPasswordPage"

# Check a few more pages to see the pattern of how location.query is defined
rg "interface.*Props" frontend/pages/ConfirmSSOInvitePage -A10

# Look for any conditional checks on location.query in the codebase
rg "location\.query\?" frontend/ -B2 -A2 | head -50

Repository: fleetdm/fleet

Length of output: 2064


🏁 Script executed:

# Check ResetPasswordPage to see the comparison mentioned in the original comment
cat -n frontend/pages/ResetPasswordPage/ResetPasswordPage.tsx | head -30

# Check the EditUserPage that uses optional chaining on location.query
cat -n frontend/pages/admin/UserManagementPage/EditUserPage/EditUserPage.tsx | head -60

# Check the full interface definition for EditUserPage
rg "interface.*EditUserPageProps" frontend/pages/admin/UserManagementPage/EditUserPage -A15

Repository: fleetdm/fleet

Length of output: 5668


Make location.query optional and use optional chaining for defensive consistency.

Lines 16-18 define query as required, but the codebase inconsistently handles this—EditUserPage marks it optional and uses optional chaining (location.query?.type). While react-router v3 always provides the query object, matching the defensive pattern would improve consistency and code safety. Change to query?: { email?: string; name?: string } and update line 30 to guard the destructuring.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/pages/ConfirmSSOInvitePage/ConfirmSSOInvitePage.tsx` around lines 16
- 18, Change the prop type for location.query to be optional (location: {
query?: { email?: string; name?: string } }) and update the
destructuring/reading of email and name in ConfirmSSOInvitePage (the place where
you currently destructure from location.query) to use optional chaining or a
guarded fallback (e.g., const { email, name } = location.query ?? {} or
reference location.query?.email / location.query?.name) so the code matches the
defensive pattern used elsewhere like EditUserPage.

@RachelElysia
RachelElysia merged commit 575a42b into main May 5, 2026
28 checks passed
@RachelElysia
RachelElysia deleted the lint-warnings-vi branch May 5, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants