-
Notifications
You must be signed in to change notification settings - Fork 843
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
[eslint] Custom lint rule to find non-localized text in JSX #5399
Conversation
Preview documentation changes for this PR: https://eui.elastic.co/pr_5399/ |
👋 Hey there. This PR hasn't had any activity for 90 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment. |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5399/ |
👋 Hey there. This PR hasn't had any activity for 90 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment. |
Nothing like a stale check to remind yourself of the continual passage of time |
👋 Hey there. This PR hasn't had any activity for 90 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment. |
👋 Hey there. This PR hasn't had any activity for 90 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment. |
Summary
Caroline mentioned adding an item to our PR checklist to help catch hard-coded text in our components. I was curious if we could instead enforce this with a lint rule, and this is where I ended up. I disabled the check for jest & cypress tests.
This rule is not comprehensive! There are ways to bypass its logic, some of which are known but I'm sure there are many that are not. For example, you can do something like
<MyComponent customLabel="something" />
and it will be allowed as onlychildren
are verified, and inside MyComponent the rule will seecustomLabel
comes from a prop and assume it's safe.The rule has flagged 44 existing problems in the codebase across 29 files:
Needs to use i18n
src/components/combo_box/combo_box_input/combo_box_input.tsx
removeOptionMessageContent
has hard-coded textsrc/components/datagrid/body/header/data_grid_header_cell.tsx
sortString
conditional should be explicit,sortString != null
sortString
has hard-coded textsrc/components/date_picker/super_date_picker/date_popover/absolute_tab.tsx
sentenceCasedPosition
is technically safe to use, but our sentence-casing strategy is an enemy to localizationsrc/components/date_picker/super_date_picker/date_popover/date_popover_button.tsx
formatTimeString
needs localization work, and then be marked safesrc/components/date_picker/super_date_picker/date_popover/date_popover_content.tsx
src/components/date_picker/super_date_picker/quick_select_popover/recently_used.tsx
prettyDuration
needs localization work, and then be marked safesrc/components/date_picker/super_date_picker/super_date_picker.tsx
prettyInterval
needs localization work, and then be marked safeprettyDuration
needs localization work, and then be marked safesrc/components/markdown_editor/markdown_editor_footer.tsx
src/components/markdown_editor/plugins/markdown_tooltip/plugin.tsx
src/components/notification/notification_event_meta.tsx
src/components/search_bar/filters/field_value_selection_filter.tsx
src/components/stat/stat.tsx
src/components/table/table_pagination/table_pagination.tsx
:
anditemsPerPage
shoul dmove into the rowsPerPage i18n usageSafe code that is flagged
These cases are okay and we need to find a way to ignore the error, my ideas are (in order of personal preference):
src/components/avatar/avatar.tsx
calculatedInitials
is a string computed by a functionsrc/components/basic_table/basic_table.tsx
captionElement
can be thetableCaption
from propssrc/components/datagrid/body/popover_utils.tsx
formattedText
src/components/expression/expression.tsx
src/components/form/form_row/form_row.tsx
src/components/highlight/highlight.tsx
highlight
needs to be marked safesrc/components/markdown_editor/markdown_editor_footer.tsx
message
ultimately comes from props and is safesrc/components/markdown_editor/markdown_format.tsx
result
needs to be marked as safesrc/components/search_bar/filters/field_value_selection_filter.tsx
src/components/search_bar/filters/field_value_toggle_filter.tsx
this.resolveDisplay
needs to be marked safesrc/components/search_bar/filters/field_value_toggle_group_filter.tsx
this.resolveDisplay
needs to be marked safesrc/components/search_bar/filters/is_filter.tsx
this.resolveDisplay
needs to be marked safesrc/components/selectable/selectable.tsx
messageContent
is a ReactNode but being flagged as a stringsrc/components/selectable/selectable_list/selectable_list.tsx
label
is safesrc/components/steps/step_number.tsx
screenReaderText
is safe, perhaps we update the lint rule to understand theuseI18n*Step
hooks as okay?src/components/tabs/tab.tsx
prependNode
is a ReactElement but flagged as a stringappendNode
is a ReactElement but flagged as a stringMiscellaneous
src/components/date_picker/date_picker_range.tsx
→
. I dunno if arrows should be localized or not, need to research.