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

Improvements for eslint-i18n-package #171588

Merged
merged 17 commits into from
Nov 23, 2023

Conversation

CoenWarmer
Copy link
Contributor

@CoenWarmer CoenWarmer commented Nov 20, 2023

Summary

Screen.Recording.2023-11-20.at.23.01.33.mov

This PR adds the following improvements to the ESLint i18n Translation package:

@kbn/i18n/i18n_translate_should_start_with_the_right_id

This rule checks every instance of i18n.translate() if the first parameter that is passed:

  1. is truthy and is a string value,
  2. starts with the correct i18n app identifier for the file that is being checked.

It checks the repo for the i18nrc.json and /x-pack/i18nrc.json files and determines what the right i18n identifier should be.

If the parameter is missing or does not start with the right i18n identifier, it can autofix the parameter.

This rule is useful when defining translated values in plain functions (non-JSX), but it works in JSX as well.

Example

This code:

// Filename: /x-pack/plugins/observability/public/my_function.ts

function myFunction() {
    const translations = [
        {
            id: 'copy';
            label: i18n.translate()
        }
    ]
}

will be autofixed with:

import { i18n } from '@kbn/i18n';

function myFunction() {
    const translations = [
        {
            id: 'copy';
            label: i18n.translate('xpack.observability.myFunction.', { defaultMessage: '' })
        }
    ]
}

If i18n has not been imported yet, the autofix will automatically add the import statement as well.

Bug fixes:

  • The rule strings_should_be_translated_with_formatted_message rule has been removed for Obs plugins for now, as the autofix conflicts with the strings_should_be_translated_with_i18n_translate and ESLint does not provide a mechanism at present to prefer one autofix suggestion over the other.
  • All the rules in the package now support nested plugins, i.e. /x-pack/parent_folder/plugin_folder/public)
  • All the rules in the package now also support files in the server and common folders, i.e. /x-pack/parent_folder/plugin_folder/server)
  • i18n import lines are added correctly in files that don't have a React import yet.
  • Updated tests

@CoenWarmer CoenWarmer requested a review from a team as a code owner November 20, 2023 22:12
@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@CoenWarmer CoenWarmer added the release_note:skip Skip the PR/issue when compiling release notes label Nov 20, 2023
@CoenWarmer CoenWarmer force-pushed the feat/eslint-translation-fixes branch 2 times, most recently from bcee420 to b6322a4 Compare November 21, 2023 10:17
@CoenWarmer CoenWarmer force-pushed the feat/eslint-translation-fixes branch from b6322a4 to 0e8d2bf Compare November 21, 2023 10:24
@CoenWarmer
Copy link
Contributor Author

@elasticmachine merge upstream

@CoenWarmer
Copy link
Contributor Author

@elasticmachine merge upstream

@CoenWarmer
Copy link
Contributor Author

@elasticmachine merge upstream

@miltonhultgren miltonhultgren self-requested a review November 22, 2023 10:00
@CoenWarmer
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@miltonhultgren miltonhultgren left a comment

Choose a reason for hiding this comment

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

Overall this looks good, some questions and small readability suggestions 👍🏼

@kibanamachine kibanamachine requested a review from a team November 23, 2023 10:52
@CoenWarmer CoenWarmer enabled auto-merge (squash) November 23, 2023 11:29
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
serverlessSearch 369.1KB 369.2KB +147.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@CoenWarmer CoenWarmer merged commit 0bf4998 into elastic:main Nov 23, 2023
27 checks passed
@kibanamachine kibanamachine added v8.12.0 backport:skip This commit does not require backporting labels Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants