Enable import-x/default

What does this MR do and why?

Enables import-x/default as an error in every config. The rule reports a default import from a module that has no default export. Such an import binds undefined.

The rule reads the export map that import-x/named already builds for every import, so it adds about 3.7 s to a full-repo run of about 5 min in the GitLab monolith. The bundlers fail the build on the same mistake, but only for modules they reach. Specs, helpers, and scripts are only linted, and that is where the rule found its violations.

The rule was off with only the comment inherited from eslint-config-airbnb-base. No issue or MR in this project discusses it.

What the rule found in the monolith:

  • Four specs that imported a default from a module with none. Each binding was undefined, so each test asserted less than it appeared to.
  • Six default imports of web worker modules. Worker files have no exports. The bundler supplies the default through the ?worker loader. The changeset shows how to skip such files with import-x/ignore.

The changeset is minor. Consumers can get new lint errors, but earlier releases enabled rules as error in a minor too, for example tailwindcss/no-arbitrary-value in 21.x.

How to validate

  • yarn test passes.
  • In the monolith, gitlab-org/gitlab!257792 (merged) fixes the four specs the rule finds. The bump to this version must also add _worker\.js$ to import-x/ignore, as the changeset shows.

References

Edited by Miguel Rincon

Merge request reports

Loading
Loading