Skip to content

Commit 43ccc3f

Browse files
committed
Enable imports/imports-first rule
Since imports are hoisted, keeping them all at the top prevents surprising behavior.
1 parent e32079d commit 43ccc3f

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,25 @@ Other Style Guides
11651165
export default function foo() {}
11661166
```
11671167
1168+
<a name="modules--imports-first"></a>
1169+
- [10.7](#modules--imports-first) Put all `import`s above non-import statements.
1170+
eslint: [`import/imports-first`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md)
1171+
> Why? Since `import`s are hoisted, keeping them all at the top prevents surprising behavior.
1172+
1173+
```javascript
1174+
// bad
1175+
import foo from 'foo';
1176+
foo.init();
1177+
1178+
import bar from 'bar';
1179+
1180+
// good
1181+
import foo from 'foo';
1182+
import bar from 'bar';
1183+
1184+
foo.init();
1185+
```
1186+
11681187
**[⬆ back to top](#table-of-contents)**
11691188
11701189
## Iterators and Generators

packages/eslint-config-airbnb-base/rules/imports.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ module.exports = {
8686

8787
// disallow non-import statements appearing before import statements
8888
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md
89-
// TODO: enable?
90-
'import/imports-first': [0, 'absolute-first'],
89+
'import/imports-first': [2, 'absolute-first'],
9190

9291
// disallow duplicate imports
9392
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md

0 commit comments

Comments
 (0)