Skip to content

Add lint hardcoded URLs in JavaScript#10894

Merged
mitchellhenke merged 6 commits intomainfrom
mitchellhenke/linting-hardcoded-urls-in-js-2
Jul 1, 2024
Merged

Add lint hardcoded URLs in JavaScript#10894
mitchellhenke merged 6 commits intomainfrom
mitchellhenke/linting-hardcoded-urls-in-js-2

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

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
Contributor

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.

Copy link
Contributor

@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 👍

Mitchell Henke and others added 3 commits July 1, 2024 15:09
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
@mitchellhenke mitchellhenke merged commit e39eb3e into main Jul 1, 2024
@mitchellhenke mitchellhenke deleted the mitchellhenke/linting-hardcoded-urls-in-js-2 branch July 1, 2024 21:30
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