Duplicate imports in browser mochitest files now get flagged up by eslint (and --fix removes them)

3 views
Skip to first unread message

Gijs Kruitbosch

unread,
Feb 2, 2023, 5:54:18 AM2/2/23
to dev-pl...@mozilla.org, firefox-dev

Hello,

The eslint `no-redeclare` rule flags up duplicate globals in JS. Unfortunately it can't do anything to fix issues, and our window environments in JS are... a little complex, so it isn't enabled on most of the tree.

However, over in bug 1795255 I've landed a patch that takes that builtin rule and builds on top of it to flag up unnecessary `ChromeUtils.import` calls, and enabled it for browser test files. It will auto-fix to remove imports that you don't need (e.g. TestUtils, BrowserTestUtils, etc.). This removed some 700-odd lines of imports we didn't need.

Right now it isn't turned on outside of browser tests, and also doesn't flag up non-imports, as that hits lots of other conflicts like `let URL = "mytestpage";` (which conflicts with the global DOM `URL` constructor).

Going forward we'll do some automated rewriting of some of those issues and then work to turn on that part of the rule (which can't auto-fix - you'll need to rename variables!) for browser tests too.

Finally, if you hit a problem where this rule flags up imports that you definitely do need (either because the eslint environment is confused about what globals are/aren't available, or because the module name conflicts with a DOM global) you can use

```
// eslint-disable-next-line mozilla/no-redeclare-with-import-autofix

```

to stop it complaining.

Thanks,
Gijs


Reply all
Reply to author
Forward
0 new messages