import-js/eslint-plugin-import

Proposal: `default-import-match-filename`

Open

#325 aperta il 9 mag 2016

Vedi su GitHub
 (20 commenti) (43 reazioni) (0 assegnatari)JavaScript (1540 fork)batch import
help wantedrule proposalstyle-guide

Metriche repository

Star
 (4946 star)
Metriche merge PR
 (Merge medio 138g 22h) (3 PR mergiate in 30 g)

Descrizione

I often see things such as:

import parseDate from './types/date';
import float from './types/parseFloat';

The disparity between the default import name (parseDate) and file name (date) often indicates that one or the other is named inappropriately. In the first case, thats the file name. In the second case, thats the local variable name.

Valid code:

import parseFloat from './types/parseFloat';
import parseDate from './types/parseDate';

Invalid code:

import parseDate from './types/date';
import float from './types/parseFloat';

There is no way to enforce a right name, e.g. user could just as well end up with:

import date from './types/date';
import float from './types/float';

However, I would argue that these issues are easy to notice in the code. Having this rule would prevent lazy developers from using a better variable name in a local file and ignore the need to rename the file and other references.

Furthermore, this enables easier code inspection (because it is easy to recognise what a variable represents when it is being used consistently between many files).

Guida contributor