eslint-plugin-putout 11.11.0 → 11.15.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
@@ -58,7 +58,7 @@ Then configure the rules you want to use under the rules section.
58
58
 
59
59
  ## Supported Rules
60
60
 
61
- - [putout](lib/putout)
61
+ - [Putout](lib/putout)
62
62
  - [Array element newline](/packages/eslint-plugin-putout/lib/array-element-newline)
63
63
  - [Single property destructuring](/packages/eslint-plugin-putout/lib/single-property-destructuring)
64
64
  - [Multiple properties destructuring](/packages/eslint-plugin-putout/lib/multiple-properties-destructuring)
@@ -78,8 +78,9 @@ Then configure the rules you want to use under the rules section.
78
78
  - [Object init](/packages/eslint-plugin-putout/lib/object-init)
79
79
  - [No unresolved](/packages/eslint-plugin-putout/lib/no-unresolved)
80
80
  - [Evaluate](/packages/eslint-plugin-putout/lib/evaluate)
81
- - [Tape: add new line before assertion]('/packages/eslint-plugin-putout/lib/tape-add-new-line-before-assertion)
82
- - [Tape: add new line between tests]('/packages/eslint-plugin-putout/lib/tape-add-new-line-between-tests)
81
+ - [Tape: add newline before assertion]('/packages/eslint-plugin-putout/lib/tape-add-new-line-before-assertion)
82
+ - [Tape: add newline between tests]('/packages/eslint-plugin-putout/lib/tape-add-new-line-between-tests)
83
+ - [Tape: remove newline before t.end()]('/packages/eslint-plugin-putout/lib/tape-remove-newline-before-t-end)
83
84
 
84
85
  ### Safe mode
85
86
 
@@ -0,0 +1,26 @@
1
+ # Add new line before function call (add-newline-before-function-call)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to add newline before function call.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ export function parse() {
11
+ const a = 1;
12
+ const b = 2;
13
+ fn();
14
+ }
15
+ ```
16
+
17
+ Examples of **correct** code for this rule:
18
+
19
+ ```js
20
+ export function parse() {
21
+ const a = 1;
22
+ const b = 2;
23
+
24
+ fn();
25
+ }
26
+ ```
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+
5
+ const {
6
+ isBlockStatement,
7
+ isVariableDeclaration,
8
+ isExpressionStatement,
9
+ } = types;
10
+
11
+ module.exports.category = 'typescript';
12
+ module.exports.report = () => 'Add newline before function call';
13
+
14
+ module.exports.filter = ({text, node, getText, getCommentsBefore}) => {
15
+ if (!isExpressionStatement(node.parent))
16
+ return false;
17
+
18
+ if (getCommentsBefore(node.parent).length)
19
+ return false;
20
+
21
+ const {parent} = node.parent;
22
+
23
+ if (!isBlockStatement(parent))
24
+ return false;
25
+
26
+ const {body} = parent;
27
+ const n = body.length;
28
+
29
+ if (n < 3)
30
+ return false;
31
+
32
+ const spaces = getSpacesBeforeNode(node, {text, getText});
33
+
34
+ if (/^\n +\n +$/.test(spaces))
35
+ return false;
36
+
37
+ for (let i = 2; i < n; i++) {
38
+ const current = body[i];
39
+
40
+ if (current !== node.parent)
41
+ continue;
42
+
43
+ const prevA = body[i - 1];
44
+
45
+ if (!isVariableDeclaration(prevA))
46
+ return false;
47
+
48
+ const spaces = getSpacesBeforeNode(prevA, {getText});
49
+
50
+ if (/^\n +\n +$/.test(spaces))
51
+ return false;
52
+
53
+ return true;
54
+ }
55
+
56
+ return false;
57
+ };
58
+
59
+ module.exports.fix = ({text}) => {
60
+ return `\n${text}`;
61
+ };
62
+
63
+ module.exports.include = () => [
64
+ 'CallExpression',
65
+ ];
66
+
67
+ function getSpacesBeforeNode(node, {getText, text = getText(node)}) {
68
+ let spaces = '';
69
+ let i = 0;
70
+
71
+ while (!spaces || /^[ \n]+$/.test(spaces))
72
+ spaces = getText(node, ++i)
73
+ .replace(text, '');
74
+
75
+ return spaces.slice(1);
76
+ }
package/lib/index.js CHANGED
@@ -27,6 +27,7 @@ module.exports.rules = {
27
27
  ...getWrapRule('newline-function-call-arguments'),
28
28
  ...getWrapRule('function-declaration-paren-newline'),
29
29
  ...getWrapRule('add-newlines-between-types-in-union'),
30
+ ...getWrapRule('add-newline-before-function-call'),
30
31
  ...getWrapRule('remove-newline-after-default-import'),
31
32
  ...getWrapRule('remove-newline-from-empty-object'),
32
33
  ...getWrapRule('remove-empty-newline-before-first-specifier'),
@@ -37,6 +38,7 @@ module.exports.rules = {
37
38
  ...getWrapRule('evaluate'),
38
39
  ...getWrapRule('tape-add-newline-before-assertion'),
39
40
  ...getWrapRule('tape-add-newline-between-tests'),
41
+ ...getWrapRule('tape-remove-newline-before-t-end'),
40
42
  ...getRule('putout'),
41
43
  };
42
44
 
@@ -61,6 +63,7 @@ const recommended = {
61
63
  'putout/newline-function-call-arguments': 'error',
62
64
  'putout/function-declaration-paren-newline': 'error',
63
65
  'putout/add-newlines-between-types-in-union': 'error',
66
+ 'putout/add-newline-before-function-call': 'error',
64
67
  'putout/remove-newline-after-default-import': 'error',
65
68
  'putout/remove-newline-from-empty-object': 'error',
66
69
  'putout/remove-empty-newline-before-first-specifier': 'error',
@@ -71,6 +74,7 @@ const recommended = {
71
74
  'putout/evaluate': 'error',
72
75
  'putout/tape-add-newline-before-assertion': 'error',
73
76
  'putout/tape-add-newline-between-tests': 'error',
77
+ 'putout/tape-remove-newline-before-t-end': 'error',
74
78
  'putout/putout': 'error',
75
79
 
76
80
  'node/no-unsupported-features/es-syntax': 'off',
@@ -1,6 +1,6 @@
1
1
  # Putout (putout)
2
2
 
3
- [Putout](https://github.com/coderaiser/putout) used as eslint plugin.
3
+ 🐊[`Putout`](https://github.com/coderaiser/putout) used as eslint plugin.
4
4
 
5
5
  ## Rule Details
6
6
 
@@ -1,16 +1,18 @@
1
- # Add new line before assertion (add-newline-before-assertion)
1
+ # Add newline before assertion (add-newline-before-assertion)
2
2
 
3
- Add new line before `t.equal()` etc, for [supertape](https://github.com/coderaiser/supertape).
3
+ Add newline before `t.equal()` etc, for [supertape](https://github.com/coderaiser/supertape).
4
4
 
5
5
  ## Rule Details
6
6
 
7
- This rule aims to add new line before assertion.
7
+ This rule aims to add newline before assertion.
8
8
 
9
9
  Examples of **incorrect** code for this rule:
10
10
 
11
11
  ```js
12
12
  test('lint: do some check', (t) => {
13
- const result = 1 + 2;
13
+ const expected = 1 + 2;
14
+
15
+ fn();
14
16
  t.equal(result, 3);
15
17
  t.end();
16
18
  });
@@ -22,6 +24,8 @@ Examples of **correct** code for this rule:
22
24
  test('lint: do some check', (t) => {
23
25
  const result = 1 + 2;
24
26
 
27
+ fn();
28
+
25
29
  t.equal(result, 3);
26
30
  t.end();
27
31
  });
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports.category = 'tape';
4
- module.exports.report = () => 'Add new line before assertion';
4
+ module.exports.report = () => 'Add newline before assertion';
5
5
 
6
6
  const regexp = /;\n +?t\..*;\n +?t.end\(\);/;
7
7
 
@@ -1,10 +1,10 @@
1
- # Add new line between tests (add-newline-between-tests)
1
+ # Add newline between tests (add-newline-between-tests)
2
2
 
3
- Add new line between tests, for [supertape](https://github.com/coderaiser/supertape).
3
+ Add newline between tests, for [supertape](https://github.com/coderaiser/supertape).
4
4
 
5
5
  ## Rule Details
6
6
 
7
- This rule aims to add new line between tests.
7
+ This rule aims to add newline between tests.
8
8
 
9
9
  Examples of **incorrect** code for this rule:
10
10
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports.category = 'tape';
4
- module.exports.report = () => 'Add new line between tests';
4
+ module.exports.report = () => 'Add newline between tests';
5
5
 
6
6
  module.exports.filter = ({text, node, getText, getCommentsBefore}) => {
7
7
  if (!/^test(\.only|\.skip)?\(/.test(text))
@@ -0,0 +1,30 @@
1
+ # Remove newline before `t.end()` (remove-newline-before-t-end)
2
+
3
+ Remove newline before `t.end()`, for [supertape](https://github.com/coderaiser/supertape).
4
+
5
+ ## Rule Details
6
+
7
+ This rule aims to remove newline before `t.end()`.
8
+
9
+ Examples of **incorrect** code for this rule:
10
+
11
+ ```js
12
+ test('lint: do some check', (t) => {
13
+ const result = 1 + 2;
14
+
15
+ t.equal(result, 3);
16
+
17
+ t.end();
18
+ });
19
+ ```
20
+
21
+ Examples of **correct** code for this rule:
22
+
23
+ ```js
24
+ test('lint: do some check', (t) => {
25
+ const result = 1 + 2;
26
+
27
+ t.equal(result, 3);
28
+ t.end();
29
+ });
30
+ ```
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ module.exports.category = 'tape';
4
+ module.exports.report = () => 'Remove newline before t.end()';
5
+
6
+ const newlineReg = /\n( +)?\n +t.end\(\)/;
7
+
8
+ module.exports.filter = ({text}) => {
9
+ if (!/^test(\.only|\.skip)?\(/.test(text))
10
+ return false;
11
+
12
+ if (newlineReg.test(text))
13
+ return true;
14
+
15
+ return false;
16
+ };
17
+
18
+ module.exports.fix = ({text}) => {
19
+ return text.replace(newlineReg, '\n t.end()');
20
+ };
21
+
22
+ module.exports.include = () => [
23
+ 'CallExpression',
24
+ ];
25
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "11.11.0",
3
+ "version": "11.15.0",
4
4
  "description": "eslint plugin for putout",
5
5
  "release": false,
6
6
  "tag": false,