Skip to content

Latest commit

 

History

History
38 lines (24 loc) · 936 Bytes

require-fetch-import.md

File metadata and controls

38 lines (24 loc) · 936 Bytes

require-fetch-import

Using fetch() without importing it causes the browser to use the native, non-wrapped window.fetch(). This is generally fine, but makes testing harder because this non-wrapped version does not have a built-in test waiter. Because of this it is generally better to use ember-fetch and explicitly import fetch from 'fetch'.

Rule Details

The rule looks for fetch() calls and reports them as issues if no corresponding import declaration is found.

Examples

Examples of incorrect code for this rule:

const result = fetch('/something');

Examples of correct code for this rule:

import fetch from 'fetch';

const result = fetch('/something');

Migration

  • Add import fetch from 'fetch'; to all files that need it

References