Explicitly import the specific method needed
1/* eslint-disable no-await-in-loop */
2import * as fse from 'fs-extra'; 3
4import test from 'ava';
5
Explicitly import the specific method needed
1import test from 'ava';
2
3import * as fse from 'fs-extra'; 4
5import { join, dirname, basename } from '../src/path';
6import {
Explicitly import the specific method needed
1/* eslint-disable max-len */
2import * as fse from 'fs-extra'; 3
4import * as readline from 'readline';
5import {
Explicitly import the specific method needed
1/* eslint-disable max-len */
2import * as fse from 'fs-extra';
3
4import * as readline from 'readline'; 5import {
6 isAbsolute, join, resolve, relative, normalize,
7} from './src/path';
Description
Wildcard imports are easier to write, but make it harder to pick out the specific functions or objects from a dependency that are used in a file.
import * from 'module';
// there is no clear way to tell if
// `someFunction` has been imported
// from 'module'.
someFunction();
Therefore, it is recommended to explicit imports wherever possible.
NOTE: Some libraries do not expose themselves as ESModules. In cases like these, it is recommended to use a skipcq comment to suppress this issue.
Bad Practice
import * as axios from 'axios'
import * as Sentry from '@sentry/node'
try {
const result = await axios.get();
// ...
} catch (err) {
Sentry.captureException(err);
}
Recommended
import axios from 'axios'
// skipcq: JS-C1003 - sentry does not expose itself as an ES Module.
import * as Sentry from '@sentry/node'
try {
const result = await axios.get();
// ...
} catch (err) {
Sentry.captureException(err);
}