Skip to content
Snippets Groups Projects

Add ESLint vue rules to detect vue i18n offences

Merged Ezekiel Kigbo requested to merge 63560-add-vue-i18n-eslint into master
All threads resolved!

What does this MR do?

Adds eslint-plugin-vue-i18n to provide i18n linting for .vue files.

New Rules

  • Introduces 2 new rules
    • no-bare-strings: providing an error on bare strings
<template>
<div>
 <h1>This is a translatable string</h1> // Error: Content should be marked for translation
</div>
</template>
  • no-bare-attribute-strings: providing an error on bare attributes
<template>
<div>
 <h1 title="This is translatable">{{ __('This is a translatable string') }}</h1> // Error: Attribute should be marked for translation
</div>
</template>

EE Port

EE Port

Does this MR meet the acceptance criteria?

Conformity

Performance and testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Closes #63560 (closed)

Edited by Ezekiel Kigbo

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Ezekiel Kigbo changed milestone to %12.2

    changed milestone to %12.2

  • Ezekiel Kigbo marked the checklist item Changelog entry for user-facing changes, or community contribution. Check the link for other scenarios. as completed

    marked the checklist item Changelog entry for user-facing changes, or community contribution. Check the link for other scenarios. as completed

  • Ezekiel Kigbo marked the checklist item Separation of EE specific content as completed

    marked the checklist item Separation of EE specific content as completed

  • Ezekiel Kigbo added 1 commit

    added 1 commit

    • 7919a732 - Disable vue-i18n for non-autofix files

    Compare with previous version

  • 1 Warning
    :warning: This merge request changed files with disabled eslint rules. Please consider fixing them.
    1 Message
    :book: This merge request includes changes to Vue files that have both CE and EE versions.

    Disabled eslint rules

    The following files have disabled eslint rules. Please consider fixing them:

    • app/assets/javascripts/boards/components/board_list.vue
    • app/assets/javascripts/boards/components/modal/header.vue
    • app/assets/javascripts/boards/components/modal/tabs.vue
    • app/assets/javascripts/clusters/components/application_row.vue
    • app/assets/javascripts/diffs/components/compare_versions.vue
    • app/assets/javascripts/diffs/components/hidden_files_warning.vue
    • app/assets/javascripts/environments/components/environment_item.vue
    • app/assets/javascripts/environments/components/stop_environment_modal.vue
    • app/assets/javascripts/ide/components/branches/item.vue
    • app/assets/javascripts/ide/components/ide_status_bar.vue
    • app/assets/javascripts/issuable_suggestions/components/item.vue
    • app/assets/javascripts/issue_show/components/edit_actions.vue
    • app/assets/javascripts/issue_show/components/edited.vue
    • app/assets/javascripts/issue_show/components/fields/description_template.vue
    • app/assets/javascripts/jobs/components/commit_block.vue
    • app/assets/javascripts/mr_popover/components/mr_popover.vue
    • app/assets/javascripts/notes/components/diff_with_note.vue
    • app/assets/javascripts/notes/components/note_edited_text.vue
    • app/assets/javascripts/pages/projects/shared/permissions/components/settings_panel.vue
    • app/assets/javascripts/pipelines/components/pipelines_artifacts.vue
    • app/assets/javascripts/releases/components/release_block.vue
    • app/assets/javascripts/reports/components/report_link.vue
    • app/assets/javascripts/repository/components/last_commit.vue
    • app/assets/javascripts/vue_merge_request_widget/components/states/mr_widget_merged.vue
    • app/assets/javascripts/vue_shared/components/markdown/toolbar.vue

    Run the following command for more details

    node_modules/.bin/eslint --report-unused-disable-directives --no-inline-config \
      'app/assets/javascripts/boards/components/board_list.vue' \
      'app/assets/javascripts/boards/components/modal/header.vue' \
      'app/assets/javascripts/boards/components/modal/tabs.vue' \
      'app/assets/javascripts/clusters/components/application_row.vue' \
      'app/assets/javascripts/diffs/components/compare_versions.vue' \
      'app/assets/javascripts/diffs/components/hidden_files_warning.vue' \
      'app/assets/javascripts/environments/components/environment_item.vue' \
      'app/assets/javascripts/environments/components/stop_environment_modal.vue' \
      'app/assets/javascripts/ide/components/branches/item.vue' \
      'app/assets/javascripts/ide/components/ide_status_bar.vue' \
      'app/assets/javascripts/issuable_suggestions/components/item.vue' \
      'app/assets/javascripts/issue_show/components/edit_actions.vue' \
      'app/assets/javascripts/issue_show/components/edited.vue' \
      'app/assets/javascripts/issue_show/components/fields/description_template.vue' \
      'app/assets/javascripts/jobs/components/commit_block.vue' \
      'app/assets/javascripts/mr_popover/components/mr_popover.vue' \
      'app/assets/javascripts/notes/components/diff_with_note.vue' \
      'app/assets/javascripts/notes/components/note_edited_text.vue' \
      'app/assets/javascripts/pages/projects/shared/permissions/components/settings_panel.vue' \
      'app/assets/javascripts/pipelines/components/pipelines_artifacts.vue' \
      'app/assets/javascripts/releases/components/release_block.vue' \
      'app/assets/javascripts/reports/components/report_link.vue' \
      'app/assets/javascripts/repository/components/last_commit.vue' \
      'app/assets/javascripts/vue_merge_request_widget/components/states/mr_widget_merged.vue' \
      'app/assets/javascripts/vue_shared/components/markdown/toolbar.vue'

    Reviewer roulette

    Changes that require review have been detected! A merge request is normally reviewed by both a reviewer and a maintainer in its primary category (e.g. frontend or backend), and by a maintainer in all other categories.

    To spread load more evenly across eligible reviewers, Danger has randomly picked a candidate for each review slot. Feel free to override this selection if you think someone else would be better-suited, or the chosen person is unavailable.

    Once you've decided who will review this merge request, mention them as you normally would! Danger does not (yet?) automatically notify them for you.

    Category Reviewer Maintainer
    frontend Martin Wortschack (@wortschi) Filipa Lacerda (@filipa)

    Vue <template> in CE and EE

    Some Vue files in CE have a counterpart in EE. (For example, path/to/file.vue and ee/path/to/file.vue.)

    When run in the context of CE, the <template> of the CE Vue file is used. When run in the context of EE, the <template> of the EE Vue file is used.

    It's easy to accidentally make a change to a CE <template> that should appear in both CE and EE without making the change in both places. When this happens, the change only takes effect in CE.

    The following Vue files were changed as part of this merge request that include both a CE and EE version of the file:

    • app/assets/javascripts/vue_merge_request_widget/mr_widget_options.vue

    If you made a change to the <template> of any of these Vue files that should be visible in both CE and EE, please ensure you have made your change to both versions of the file.

    A better alternative

    An even better alternative is to refactor this component to only use a single template for both CE and EE. More info on this approach here: https://docs.gitlab.com/ee/development/ee_features.html#template-tag

    Generated by :no_entry_sign: Danger

    Edited by 🤖 GitLab Bot 🤖
  • Ezekiel Kigbo added 1 commit

    added 1 commit

    • 86ad2219 - Disable vue-i18n for non-autofix files

    Compare with previous version

  • Ezekiel Kigbo added 2 commits

    added 2 commits

    • d46af03e - Add @gitlab/eslint-plugin-vue-i18n plugin
    • f418214d - Disable vue-i18n for non-autofix files

    Compare with previous version

  • Ezekiel Kigbo mentioned in merge request !31125 (merged)

    mentioned in merge request !31125 (merged)

  • Ezekiel Kigbo unmarked as a Work In Progress

    unmarked as a Work In Progress

  • Ezekiel Kigbo assigned to @nfriend and unassigned @ekigbo

    assigned to @nfriend and unassigned @ekigbo

  • Ezekiel Kigbo mentioned in merge request !29589 (closed)

    mentioned in merge request !29589 (closed)

  • mentioned in issue #57969 (moved)

  • Ezekiel Kigbo added 1 commit

    added 1 commit

    Compare with previous version

  • mentioned in issue #63458 (moved)

  • Ezekiel Kigbo added 28 commits

    added 28 commits

    Compare with previous version

  • Ezekiel Kigbo added 28 commits

    added 28 commits

    Compare with previous version

  • Ezekiel Kigbo added 28 commits

    added 28 commits

    Compare with previous version

  • Ezekiel Kigbo added 28 commits

    added 28 commits

    Compare with previous version

  • Nathan Friend resolved all threads

    resolved all threads

  • Nathan Friend
  • Nathan Friend approved this merge request

    approved this merge request

    • Resolved by Mike Greiling

      @ekigbo I really like the idea of this rule! I'm assuming this rule is something we developed ourselves?

      My main concern is that it seems like this rule will generate a lot of false positives going forward. I don't think it's healthy to get us into the habit of frequently disabling ESLint rules, and this rule seems like it will need to be disabled at least once per Vue file (on the name property, and potentially elsewhere in the file).

      I'll defer to a maintainer as to whether we want to enable this rule or not (and maybe this discussion has already happened elsewhere). Assuming we do want to enable this rule, I think this merge request looks good :thumbsup:. I'll go ahead and approve this merge request with this assumption. Back to you!

  • Nathan Friend assigned to @ekigbo and unassigned @nfriend

    assigned to @ekigbo and unassigned @nfriend

  • Ezekiel Kigbo added 60 commits

    added 60 commits

    Compare with previous version

  • Ezekiel Kigbo added 1 commit

    added 1 commit

    • c9319db6 - Added link to component name issue

    Compare with previous version

  • Ezekiel Kigbo resolved all threads

    resolved all threads

  • Ezekiel Kigbo resolved all threads

    resolved all threads

  • Ezekiel Kigbo assigned to @timzallmann and unassigned @ekigbo

    assigned to @timzallmann and unassigned @ekigbo

  • Ezekiel Kigbo added 201 commits

    added 201 commits

    Compare with previous version

  • assigned to @mikegreiling and unassigned @timzallmann

  • Mike Greiling
  • I think this looks good to me. Just a couple of comments above regarding the proliferation of eslint-disable comments. I'm curious what alternatives have been considered.

  • assigned to @ekigbo

    • Resolved by Ezekiel Kigbo

      @ekigbo can you please create an EE branch with these changes to ensure we will not introduce any linter violations with these rule additions? I see gitlab-ee!14837 has already done an auto-fix pass against EE, but I'm not sure that accounts for any lines where we need to disable some rules.

  • Ezekiel Kigbo added 67 commits

    added 67 commits

    Compare with previous version

  • Ezekiel Kigbo added 1 commit

    added 1 commit

    • 30fd4d01 - Remove unused eslint-disable

    Compare with previous version

  • Ezekiel Kigbo changed the description

    changed the description

  • Ezekiel Kigbo added 173 commits

    added 173 commits

    Compare with previous version

  • Ezekiel Kigbo added 11 commits

    added 11 commits

    Compare with previous version

  • Ezekiel Kigbo added 48 commits

    added 48 commits

    Compare with previous version

  • Ezekiel Kigbo changed the description

    changed the description

  • Ezekiel Kigbo added 138 commits

    added 138 commits

    Compare with previous version

  • Ezekiel Kigbo added 65 commits

    added 65 commits

    Compare with previous version

  • Ezekiel Kigbo added 1 commit

    added 1 commit

    • 8f8ec5c2 - Remove unused eslint-disable

    Compare with previous version

  • Ezekiel Kigbo assigned to @mikegreiling and unassigned @ekigbo

    assigned to @mikegreiling and unassigned @ekigbo

  • Ezekiel Kigbo added 73 commits

    added 73 commits

    Compare with previous version

  • Mike Greiling approved this merge request

    approved this merge request

  • Mike Greiling resolved all threads

    resolved all threads

  • merged

  • Laura Montemayor mentioned in merge request !30760 (merged)

    mentioned in merge request !30760 (merged)

  • mentioned in issue #65856 (moved)

  • Please register or sign in to reply
    Loading