Draft: Add vue-directive-pairing ESLint rule

What does this MR do and why?

Adds a local ESLint rule, local-rules/vue-directive-pairing, that keeps every custom directive used in a Vue template paired with a registration in the component's directives option, both ways.

Uses the small options-object helper added in !256664 (merged).

Why now

!255388 (merged) fixed a component that used v-gl-tooltip without registering GlTooltipDirective. Vue 2 logged Failed to resolve directive and the tooltip never rendered. The Jest spec passed because it used createMockDirective. Under Vue 3, where apps do not share global registrations, every such gap is a runtime failure. The rule turns it into a lint error on every MR.

The rule

  • Needs no table for detection. Every custom v-x in the template must match a directives key that Vue resolves to it (x, camelCase or PascalCase), and every key must be used.
  • Covers local directives such as SafeHtml and validation the same way as @gitlab/ui ones.
  • No options beyond reportUnused. Nothing in app/ or ee/ registers a directive globally, spreads a directives object or uses a computed key, so the rule does not handle those cases. vue/no-undef-directives in eslint-plugin-vue 10.7 takes the same approach.
  • No autofix. The cleanup below was generated with an autofix once; from here on a violation is one import and one directives key to edit by hand.

Rollout: missing half now, unused half after the cleanups

Running the rule over app/ and ee/ found no missing registration and about 130 files with an unused one. Cleaning those up takes longer and is not critical, so this MR does not wait for it:

  • reportUnused: false is set on the rule. The missing half is on.

  • The cleanup MRs below remove the existing unused registrations. They were produced with an earlier autofix of this rule, since removed to keep the rule small, and can merge in any order.

  • A last MR removes the reportUnused: false flag once the cleanups are in. No todo list is added anywhere.

  • !256665 (closed) (Remove unused GlTooltip directive registrations)

  • !256667 (merged) (Remove unused SafeHtml directive registrations)

  • !256668 (merged) (Remove unused GlModal directive registrations)

  • !256669 (closed) (Remove unused mixin and directive registrations)

Same-file evidence only

The rule only sees the component file. Two DAST forms use v-validation, which dastProfileFormMixin() registered. The registration moves out of the mixin and into each form's directives option, so the rule sees it and no eslint-disable is needed.

How to set up and validate locally

  1. Run the rule specs:

    yarn vitest:eslint --run
  2. Lint the frontend. No local-rules/vue-directive-pairing error is reported:

    ./node_modules/.bin/eslint 'app/assets/javascripts/**/*.vue' 'ee/app/assets/javascripts/**/*.vue'
  3. Reproduce the motivating bug. Remove the directives option from app/assets/javascripts/personal_access_tokens/components/personal_access_token_status_badge.vue and lint the file. The rule reports v-gl-tooltip. Put it back and the error goes away.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

References

🤖 Generated with Claude Code

Edited by Miguel Rincon

Merge request reports

Loading
Loading