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

9 views
Skip to first unread message

Gijs Kruitbosch

unread,
Feb 2, 2023, 5:54:19 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


--
You received this message because you are subscribed to the Google Groups "firef...@mozilla.org" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firefox-dev...@mozilla.org.
To view this discussion on the web visit https://groups.google.com/a/mozilla.org/d/msgid/firefox-dev/752a57d5-f1b9-c550-1119-d6f9f893a540%40mozilla.com.
Reply all
Reply to author
Forward
0 new messages