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

Add lint hardcoded URLs in JavaScript #10894

Merged
merged 6 commits into from
Jul 1, 2024

Conversation

mitchellhenke
Copy link
Contributor

🛠 Summary of changes

Builds on work from @aduth and learnings from #10882 where hardcoded strings for URLs resulted in untranslated requests from JavaScript. This lint raises errors on new URL(string) to help mitigate against similar issues in the future.

address_search_url is not used currently due to current configurations, the functionality for "/api/addresses" was removed in #9154. The replacement with an empty string is intended to serve as a placeholder while discussion on whether to remove the frontend components of the address search happens here.

aduth and others added 2 commits July 1, 2024 10:25
changelog: Internal, Continuous Integration, Add JavaScript lint to prevent hardcoding URLs
@mitchellhenke mitchellhenke requested a review from aduth July 1, 2024 15:25
@mitchellhenke mitchellhenke force-pushed the mitchellhenke/linting-hardcoded-urls-in-js-2 branch from f09363c to 22c7f09 Compare July 1, 2024 15:25
@@ -52,8 +52,6 @@ interface SessionTimedOutStatus {

export type SessionStatus = SessionLiveStatus | SessionTimedOutStatus;

export const SESSIONS_URL = new URL('/api/internal/sessions', window.location.href).toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

API endpoints are more consistent than the ones that have locales in them, so it could have been fine if we wanted right? This is just for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The session endpoints don't include any user-facing language currently so there aren't any issues right now, so passing in the URL is just for the localization. The other upside is we get path validation with Rails.

I"m not sure I understand what you mean by API endpoints being more consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

consistent meaning they don't change based on locale param

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, got it. I think generally, yes, but there are cases like the country support endpoint that return translated content depending on the requested locale.

Copy link
Member

Choose a reason for hiding this comment

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

I had originally knowingly implemented this without the path helper based on the original comment that we don't need the endpoint to be localized, but agree it's nice to use path helpers for validation and having a single source of truth for routes. And avoids having to create an exception.

app/javascript/packages/session/requests.ts Outdated Show resolved Hide resolved
app/javascript/packs/session-timeout-ping.ts Outdated Show resolved Hide resolved
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Aside from discussion of capitalization, LGTM 👍

@mitchellhenke mitchellhenke merged commit e39eb3e into main Jul 1, 2024
2 checks passed
@mitchellhenke mitchellhenke deleted the mitchellhenke/linting-hardcoded-urls-in-js-2 branch July 1, 2024 21:30
WilliamBirdsall pushed a commit that referenced this pull request Jul 2, 2024
* Lint hard-coded URLs in JavaScript

changelog: Internal, Continuous Integration, Add JavaScript lint to prevent hardcoding URLs

* session timeout

* address search URL

* Update app/javascript/packages/session/requests.ts

Co-authored-by: Zach Margolis <[email protected]>

* Update app/javascript/packs/session-timeout-ping.ts

Co-authored-by: Zach Margolis <[email protected]>

* rename variables

---------

Co-authored-by: Andrew Duthie <[email protected]>
Co-authored-by: Zach Margolis <[email protected]>
WilliamBirdsall pushed a commit that referenced this pull request Jul 2, 2024
* Lint hard-coded URLs in JavaScript

changelog: Internal, Continuous Integration, Add JavaScript lint to prevent hardcoding URLs

* session timeout

* address search URL

* Update app/javascript/packages/session/requests.ts

Co-authored-by: Zach Margolis <[email protected]>

* Update app/javascript/packs/session-timeout-ping.ts

Co-authored-by: Zach Margolis <[email protected]>

* rename variables

---------

Co-authored-by: Andrew Duthie <[email protected]>
Co-authored-by: Zach Margolis <[email protected]>
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