import/first
This rule reports any imports that come after non-import statements.
Rule Details
Providing absolute-first as an option will report any absolute imports (i.e. packages) that come after any relative imports:
If you really want import type ordering, check out import/order.
Notably, imports are hoisted, which means the imported modules will be evaluated before any of the statements interspersed between them. Keeping all imports together at the top of the file may prevent surprises resulting from this part of the spec.
On directives
Directives are allowed as long as they occur strictly before any import declarations, as follows:
A directive in this case is assumed to be a single statement that contains only a literal string-valued expression.
'use strict' would be a good example, except that modules are always in strict mode so it would be surprising to see a 'use strict' sharing a file with imports and exports.
Given that, see #255 for the reasoning.
With Fixer
This rule contains a fixer to reorder in-body import to top, the following criteria applied:
Never re-order relative to each other, even if
absolute-firstis set.If an import creates an identifier, and that identifier is referenced at module level before the import itself, that won't be re-ordered.
When Not To Use It
If you don't mind imports being sprinkled throughout, you may not want to enable this rule.
Further Reading
import/order: a major step up fromabsolute-firstIssue #255