deno_lint
deno_lint copied to clipboard
Lint rule: Import declarations must precede other statements/declarations
This rule would be useful to catch cases like this, in which you might expect an imported module's top-level code to be eval'd at the position of its import declaration, when instead it will be eval'd before the current module (or possibly afterwards, if there's an import cycle).
doSomethingThatAffectsGlobalState();
import "./module-that-reads-and-affects-global-state.js";
readGlobalState();
Some pending questions:
- What about export declarations? IMO it's fine to not allow them to be interspersed with imports, but should there be an exception for
export * from "a"
? - Should any TS declarations be allowed interspersed with imports? Most probably shouldn't, but there's things like ambient module declarations.
- An empty statement (i.e. an extra semicolon after an import declaration) could not possibly affect global state, and if it causes this lint to go off, it might be extremely confusing for developers.
-
"use strict"
is useless on modules, but it should probably still be exempt.