Add configurable vue-mixin-pairing ESLint rule

What does this MR do and why?

This MR replaces three "ad hoc" ESLint rules with one configurable rule that covers nine mixins. Three of them are the ones the old rules guarded. Six had no guard at all so it was easy to make a mistake.

With this change we can cover 9 different mixins with one rule (and a more complicated config entry).

From...

Each time the Vue 3 migration hit a mixin that had to be declared where it is used, we wrote a rule for that one mixin:

  • vue3-gl-slots-mixin-pairing for glSlotsMixin
  • vue3-gl-listeners-mixin-pairing for glListenersMixin
  • gl-toast-mixin for GlToastMixin

Each rule solved the same problem again: walk the script and the template, find the usages, find the registration, report when one side is missing. Two of the three had no autofix. The one that did knew a single import and a single name. Nothing guarded glFeatureFlagsMixin, glAbilitiesMixin, glLicensedFeaturesMixin, timeagoMixin, InternalEvents.mixin() or Tracking.mixin(), and together those are registered in about 750 component files.

...to

One rule, local-rules/vue-mixin-pairing, driven by a table in eslint.config.mjs. The table is the structured statement of how we use mixins in this codebase: which module supplies the mixin, how it is registered, and which instance members it provides.

{ source: '~/vue_shared/mixins/gl_feature_flags_mixin', imported: 'default', localName: 'glFeatureFlagsMixin', factory: true, members: ['glFeatures'] }

For every entry the rule enforces, in the same component file:

  • a member used in the template or script has a registration of a mixin that supplies it, or the file fails lint;
  • a registration whose members are never used is reported as unused.

The rule handles what the codebase actually does rather than what a single rule needed:

  • Mixins are matched by import, so glFeatureFlagMixin, TimeagoMixin and a relative ../mixins/timeago resolve to the same entry. There are 75 such registrations.
  • A registration is a bare identifier, a factory call, a Name.mixin() call, or a module-scope const trackingMixin = InternalEvents.mixin(). 57 files use the alias form.
  • A member the component declares itself under props, computed, methods, inject or data() is not a mixin usage. inject: ['glFeatures'] stays valid, and a local trackEvent method does not demand InternalEvents.
  • Two entries can supply the same member. InternalEvents is importable from two paths.

Configured entries: GlToastMixin, glSlotsMixin, glListenersMixin, glFeatureFlagsMixin, glAbilitiesMixin, glLicensedFeaturesMixin, timeagoMixin, InternalEvents.mixin() (both import paths), Tracking.mixin().

A companion MR, !256699 (closed), applies the same idea to directives. It is stacked on this one because it shares the small options-object helper added here. The two rules are otherwise independent.

Why now?

The Vue 3 migration. Today if a component forgets adding GlToastMixin we can still access this.$toast because some other bundle on the page ran Vue.use(GlToastPlugin) on the shared Vue 2 constructor. Vue 3 apps are isolated, so the same component would throw under Vue 3.

Jest can't find these gaps because specs inject the missing pieces. Example: MR 255388 is one of these found by a failing feature spec, and finding them one at a time does not scale.

Rollout: missing half now, unused half after the cleanups

Running the rule over app/ and ee/ found no missing registration and about 110 files with an unused one. The missing half is what prevents Vue 3 breakage, so it ships now for every entry. The unused half is a code-quality concern and waits:

  • reportUnused: false is set on the entries that still have unused registrations (glFeatureFlagsMixin, glAbilitiesMixin, timeagoMixin, InternalEvents, Tracking). The four entries with zero unused registrations keep both halves on, so nothing the old rules enforced is lost.

  • 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 flags once the cleanups are in. No todo list is added anywhere.

  • !256666 (merged) (Remove unused glFeatureFlagsMixin registrations in CE)

  • !256677 (merged) (Remove unused glFeatureFlagsMixin registrations in EE)

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

What moves where

  • Deleted vue3-gl-slots-mixin-pairing, vue3-gl-listeners-mixin-pairing and gl-toast-mixin with their specs. Their behaviour is now three table entries.
  • The $root.$toast check from gl-toast-mixin moves to a new local-rules/no-root-toast rule, unchanged. It is a different concern from pairing.
  • The rule has no autofix. The gl-toast-mixin fixer is dropped rather than generalised: the cleanup below was generated with an autofix once, and from here on a violation is one import and one array entry to edit by hand. Shared helpers live in tooling/eslint-config/eslint-local-rules/utils/component_options.mjs.

Known limit

The rule only sees same-file evidence. A mixin arriving through another mixin or extends, or a member reached through $options or this[name], needs an eslint-disable with a comment. No such case exists in app/ or ee/ today (which is a good thing! That would be a lot of spaghetti!).

How to set up and validate locally

  1. Lint the frontend. No local-rules/vue-mixin-pairing error is reported:

    ./node_modules/.bin/eslint 'app/assets/javascripts/**/*.vue' 'ee/app/assets/javascripts/**/*.vue'
  2. Remove mixins: [GlToastMixin] from any component that calls this.$toast and lint the file. The rule reports $toast. 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