eslint-plugin-putout 13.5.0 → 13.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,6 +52,7 @@ Then configure the rules you want to use under the rules section.
52
52
  "putout/remove-newline-from-empty-object": "error",
53
53
  "putout/remove-empty-newline-before-first-specifier": "error",
54
54
  "putout/remove-empty-newline-after-last-specifier": "error",
55
+ "putout/remove-empty-newline-after-import": "error",
55
56
  "putout/remove-empty-specifiers": "error",
56
57
  "putout/objects-braces-inside-array": "error",
57
58
  "putout/object-init": "error"
@@ -80,6 +81,7 @@ Then configure the rules you want to use under the rules section.
80
81
  - [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
81
82
  - [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier)
82
83
  - [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier)
84
+ - [Remove empty newline after import](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-import)
83
85
  - [Remove empty specifiers](/packages/eslint-plugin-putout/lib/remove-empty-specifiers)
84
86
  - [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array)
85
87
  - [Object init](/packages/eslint-plugin-putout/lib/object-init)
package/lib/index.js CHANGED
@@ -42,6 +42,7 @@ module.exports.rules = {
42
42
  ...getWrapRule('tape-add-newline-between-tests'),
43
43
  ...getWrapRule('tape-remove-newline-before-t-end'),
44
44
  ...getRule('putout'),
45
+ ...getRule('remove-empty-newline-after-import'),
45
46
  };
46
47
 
47
48
  const config = require('@putout/eslint-config');
@@ -71,6 +72,7 @@ const recommended = {
71
72
  'putout/remove-newline-from-empty-object': 'error',
72
73
  'putout/remove-empty-newline-before-first-specifier': 'error',
73
74
  'putout/remove-empty-newline-after-last-specifier': 'error',
75
+ 'putout/remove-empty-newline-after-import': 'error',
74
76
  'putout/remove-empty-specifiers': 'error',
75
77
  'putout/objects-braces-inside-array': 'error',
76
78
  'putout/object-init': 'error',
@@ -0,0 +1,24 @@
1
+ # Remove empty newline after import (`remove-empty-newline-after-import`)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to remove empty newline after `import`.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ import {readFile} from 'fs';
11
+
12
+ import {promisify} from 'util';
13
+
14
+ import index from './index.js';
15
+ ```
16
+
17
+ Examples of **correct** code for this rule:
18
+
19
+ ```js
20
+ import {readFile} from 'fs';
21
+ import {promisify} from 'util';
22
+
23
+ import index from './index.js';
24
+ ```
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ const {isBuiltIn} = require('./is-built-in');
4
+ const isLocal = (a) => /^\./.test(a.source.value);
5
+ const isNode = (a) => isBuiltIn(a.source.value);
6
+
7
+ const isSameGroup = (a, b) => {
8
+ if (isLocal(a) && isLocal(b))
9
+ return true;
10
+
11
+ if (isNode(a) && isNode(b))
12
+ return true;
13
+
14
+ return false;
15
+ };
16
+
17
+ module.exports = {
18
+ meta: {
19
+ type: 'suggestion',
20
+ docs: {
21
+ description: 'Putout',
22
+ category: 'putout',
23
+ recommended: true,
24
+ },
25
+ fixable: 'code',
26
+ },
27
+
28
+ create(context) {
29
+ return {
30
+ ImportDeclaration(node) {
31
+ const source = context.getSourceCode();
32
+ const text = source.getText(node);
33
+ const newline = source.getText(node, 0, 2).replace(text, '');
34
+
35
+ if (node.specifiers.length > 1)
36
+ return;
37
+
38
+ if (newline !== '\n\n')
39
+ return;
40
+
41
+ const nextNode = context.getNodeByRangeIndex(node.range[1] + 2);
42
+
43
+ if (!nextNode || nextNode.type !== 'ImportDeclaration')
44
+ return;
45
+
46
+ if (nextNode.specifiers.length > 1)
47
+ return;
48
+
49
+ const allImports = getImports(node.parent);
50
+
51
+ if (!isSameGroup(node, nextNode) && allImports.length > 2)
52
+ return;
53
+
54
+ context.report({
55
+ node,
56
+ message: 'Remove empty newline after import',
57
+
58
+ fix(fixer) {
59
+ return [
60
+ fixer.removeRange([node.range[1], node.range[1] + 1]),
61
+ ];
62
+ },
63
+ });
64
+ },
65
+ };
66
+ },
67
+ };
68
+
69
+ function getImports(node) {
70
+ const imports = [];
71
+ for (const current of node.body) {
72
+ if (current.type === 'ImportDeclaration')
73
+ imports.push(current);
74
+ }
75
+
76
+ return imports;
77
+ }
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ const builtInsList = [
4
+ 'assert',
5
+ 'async_hooks',
6
+ 'buffer',
7
+ 'child_process',
8
+ 'cluster',
9
+ 'console',
10
+ 'crypto',
11
+ 'dgram',
12
+ 'diagnostics_channel',
13
+ 'dns',
14
+ 'domain',
15
+ 'fs',
16
+ 'fs/promises',
17
+ 'http',
18
+ 'http2',
19
+ 'https',
20
+ 'inspector',
21
+ 'module',
22
+ 'os',
23
+ 'path',
24
+ 'perf_hooks',
25
+ 'process',
26
+ 'punycode',
27
+ 'querystring',
28
+ 'readline',
29
+ 'repl',
30
+ 'stream',
31
+ 'string_decoder',
32
+ 'timers',
33
+ 'tls',
34
+ 'trace_events',
35
+ 'tty',
36
+ 'url',
37
+ 'util',
38
+ 'vm',
39
+ 'web_crypto_api',
40
+ 'web_streams_api',
41
+ 'wasi',
42
+ 'worker_threads',
43
+ 'zlib',
44
+ ];
45
+
46
+ module.exports.isBuiltIn = (name) => builtInsList.includes(name);
@@ -9,22 +9,23 @@ This rule aims to shorten destructuring of one property.
9
9
  Examples of **incorrect** code for this rule:
10
10
 
11
11
  ```js
12
+ import {
13
+ password,
14
+ } from './user.js';
15
+
12
16
  const {
13
17
  username,
14
18
  } = user;
15
19
 
16
- import {
17
- password,
18
- } from './user.js';
19
20
  ```
20
21
 
21
22
  Examples of **correct** code for this rule:
22
23
 
23
24
  ```js
24
- const {username} = user;
25
25
  import {password} from './user.js';
26
-
27
26
  import {
28
27
  helloWorld as simpleHello,
29
28
  } from './hello.js';
29
+
30
+ const {username} = user;
30
31
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "13.5.0",
3
+ "version": "13.6.0",
4
4
  "type": "commonjs",
5
5
  "description": "eslint plugin for putout",
6
6
  "release": false,