source: frontend/node_modules/eslint-plugin-import/docs/rules/newline-after-import.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.8 KB
Line 
1# import/newline-after-import
2
3🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
4
5<!-- end auto-generated rule header -->
6
7Enforces having one or more empty lines after the last top-level import statement or require call.
8
9## Rule Details
10
11This rule supports the following options:
12
13 - `count` which sets the number of newlines that are enforced after the last top-level import statement or require call. This option defaults to `1`.
14
15 - `exactCount` which enforce the exact numbers of newlines that is mentioned in `count`. This option defaults to `false`.
16
17 - `considerComments` which enforces the rule on comments after the last import-statement as well when set to true. This option defaults to `false`.
18
19Valid:
20
21```js
22import defaultExport from './foo';
23
24const FOO = 'BAR';
25```
26
27```js
28import defaultExport from './foo';
29import { bar } from 'bar-lib';
30
31const FOO = 'BAR';
32```
33
34```js
35const FOO = require('./foo');
36const BAR = require('./bar');
37
38const BAZ = 1;
39```
40
41Invalid:
42
43```js
44import * as foo from 'foo'
45const FOO = 'BAR';
46```
47
48```js
49import * as foo from 'foo';
50const FOO = 'BAR';
51
52import { bar } from 'bar-lib';
53```
54
55```js
56const FOO = require('./foo');
57const BAZ = 1;
58const BAR = require('./bar');
59```
60
61With `count` set to `2` this will be considered valid:
62
63```js
64import defaultExport from './foo';
65
66
67const FOO = 'BAR';
68```
69
70```js
71import defaultExport from './foo';
72
73
74
75const FOO = 'BAR';
76```
77
78With `count` set to `2` these will be considered invalid:
79
80```js
81import defaultExport from './foo';
82const FOO = 'BAR';
83```
84
85```js
86import defaultExport from './foo';
87
88const FOO = 'BAR';
89```
90
91With `count` set to `2` and `exactCount` set to `true` this will be considered valid:
92
93```js
94import defaultExport from './foo';
95
96
97const FOO = 'BAR';
98```
99
100With `count` set to `2` and `exactCount` set to `true` these will be considered invalid:
101
102```js
103import defaultExport from './foo';
104const FOO = 'BAR';
105```
106
107```js
108import defaultExport from './foo';
109
110const FOO = 'BAR';
111```
112
113```js
114import defaultExport from './foo';
115
116
117
118const FOO = 'BAR';
119```
120
121```js
122import defaultExport from './foo';
123
124
125
126
127const FOO = 'BAR';
128```
129
130With `considerComments` set to `false` this will be considered valid:
131
132```js
133import defaultExport from './foo'
134// some comment here.
135const FOO = 'BAR'
136```
137
138With `considerComments` set to `true` this will be considered valid:
139
140```js
141import defaultExport from './foo'
142
143// some comment here.
144const FOO = 'BAR'
145```
146
147With `considerComments` set to `true` this will be considered invalid:
148
149```js
150import defaultExport from './foo'
151// some comment here.
152const FOO = 'BAR'
153```
154
155## Example options usage
156
157```json
158{
159 "rules": {
160 "import/newline-after-import": ["error", { "count": 2 }]
161 }
162}
163```
164
165## When Not To Use It
166
167If you like to visually group module imports with its usage, you don't want to use this rule.
Note: See TracBrowser for help on using the repository browser.