eslint-plugin-putout 16.3.0 → 16.4.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 +2 -0
- package/lib/add-newline-after-function-call/index.js +0 -1
- package/lib/add-newline-before-function-call/index.js +0 -1
- package/lib/add-newlines-between-types-in-union/index.js +0 -1
- package/lib/index.js +2 -0
- package/lib/remove-empty-newline-between-declarations/README.md +17 -0
- package/lib/remove-empty-newline-between-declarations/index.js +60 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
51
51
|
"putout/newline-function-call-arguments": "error",
|
|
52
52
|
"putout/function-declaration-paren-newline": "error",
|
|
53
53
|
"putout/remove-newline-after-default-import": "error",
|
|
54
|
+
"putout/remove-newline-between-declarations": "error",
|
|
54
55
|
"putout/remove-newline-from-empty-object": "error",
|
|
55
56
|
"putout/remove-empty-newline-before-first-specifier": "error",
|
|
56
57
|
"putout/remove-empty-newline-after-last-specifier": "error",
|
|
@@ -105,6 +106,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
105
106
|
- ✅ [Keyword spacing](/packages/eslint-plugin-putout/lib/keyword-spacing#readme)
|
|
106
107
|
- ✅ [Newline function call arguments](/packages/eslint-plugin-putout/lib/newline-function-call-arguments#readme)
|
|
107
108
|
- ✅ [Function declaration paren newline](/packages/eslint-plugin-putout/lib/function-declaration-paren-newline#readme)
|
|
109
|
+
- ✅ [Remove newline between declarations](/packages/eslint-plugin-putout/lib/remove-newline-between-declarations#readme)
|
|
108
110
|
- ✅ [Remove newline after default import](/packages/eslint-plugin-putout/lib/remove-newline-after-default-import#readme)
|
|
109
111
|
- ✅ [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object#readme)
|
|
110
112
|
- ✅ [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier#readme)
|
package/lib/index.js
CHANGED
|
@@ -48,6 +48,7 @@ module.exports.rules = {
|
|
|
48
48
|
...getWrapRule('nonblock-statement-body-newline'),
|
|
49
49
|
...getRule('putout'),
|
|
50
50
|
...getRule('remove-empty-newline-after-import'),
|
|
51
|
+
...getRule('remove-empty-newline-between-declarations'),
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
const config = require('@putout/eslint-config');
|
|
@@ -81,6 +82,7 @@ const recommended = {
|
|
|
81
82
|
'putout/remove-empty-newline-after-last-specifier': 'error',
|
|
82
83
|
'putout/remove-empty-newline-after-last-element': 'error',
|
|
83
84
|
'putout/remove-empty-newline-after-import': 'error',
|
|
85
|
+
'putout/remove-empty-newline-between-declarations': 'error',
|
|
84
86
|
'putout/remove-empty-specifiers': 'error',
|
|
85
87
|
'putout/objects-braces-inside-array': 'error',
|
|
86
88
|
'putout/object-property-newline': 'error',
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# remove-empty-newline-between-declarations
|
|
2
|
+
|
|
3
|
+
This rule aims to remove empty newline between Variable Declarations. Part of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout#rules).
|
|
4
|
+
|
|
5
|
+
## ❌ Example of incorrect code
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
const {a} = b;
|
|
9
|
+
const {c} = a;
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## ✅ Example of correct code
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
const {a} = b;
|
|
16
|
+
const {c} = a;
|
|
17
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isObjectPattern} = require('putout').types;
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'suggestion',
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Remove newline between declarations',
|
|
10
|
+
category: 'putout',
|
|
11
|
+
recommended: true,
|
|
12
|
+
},
|
|
13
|
+
fixable: 'code',
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
create(context) {
|
|
17
|
+
return {
|
|
18
|
+
VariableDeclaration(node) {
|
|
19
|
+
const source = context.getSourceCode();
|
|
20
|
+
const text = source.getText(node);
|
|
21
|
+
const newline = source.getText(node, 0, 2).replace(text, '');
|
|
22
|
+
|
|
23
|
+
if (newline !== '\n\n')
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
const nextNode = context.getNodeByRangeIndex(node.range[1] + 2);
|
|
27
|
+
|
|
28
|
+
if (!nextNode || nextNode.type !== 'VariableDeclaration')
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
const nodeId = node.declarations[0].id;
|
|
32
|
+
|
|
33
|
+
if (!isObjectPattern(nodeId))
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
if (nodeId.properties.length !== 1)
|
|
37
|
+
return;
|
|
38
|
+
|
|
39
|
+
const textId = source.getText(nodeId.properties[0].value);
|
|
40
|
+
|
|
41
|
+
const nextNodeInit = nextNode.declarations[0].init;
|
|
42
|
+
const nextTextInit = source.getText(nextNodeInit);
|
|
43
|
+
|
|
44
|
+
if (textId !== nextTextInit)
|
|
45
|
+
return;
|
|
46
|
+
|
|
47
|
+
context.report({
|
|
48
|
+
node,
|
|
49
|
+
message: 'Remove empty newline between declarations',
|
|
50
|
+
|
|
51
|
+
fix(fixer) {
|
|
52
|
+
return [
|
|
53
|
+
fixer.removeRange([node.range[1], node.range[1] + 1]),
|
|
54
|
+
];
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-putout",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.4.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "ESLint plugin for 🐊Putout",
|
|
6
6
|
"release": false,
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@putout/test": "^5.0.0",
|
|
60
60
|
"c8": "^7.5.0",
|
|
61
61
|
"eslint": "^8.0.1",
|
|
62
|
-
"eslint-plugin-eslint-plugin": "^
|
|
62
|
+
"eslint-plugin-eslint-plugin": "^5.0.6",
|
|
63
63
|
"madrun": "^9.0.0",
|
|
64
64
|
"mocha": "^10.0.0",
|
|
65
65
|
"montag": "^1.0.0",
|