eslint-plugin-putout 11.4.0 → 11.8.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
@@ -1,11 +1,7 @@
1
- # eslint-plugin-putout [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
1
+ # eslint-plugin-putout [![NPM version][NPMIMGURL]][NPMURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
2
2
 
3
3
  [NPMIMGURL]: https://img.shields.io/npm/v/eslint-plugin-putout.svg?style=flat&longCache=true
4
- [BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/eslint-plugin-putout/master.svg?style=flat&longCache=true
5
- [DependencyStatusIMGURL]: https://david-dm.org/coderaiser/eslint-plugin-putout.svg?path=packages/eslint-plugin-putout
6
4
  [NPMURL]: https://npmjs.org/package/eslint-plugin-putout "npm"
7
- [BuildStatusURL]: https://travis-ci.org/coderaiser/eslint-plugin-putout "Build Status"
8
- [DependencyStatusURL]: https://david-dm.org/coderaiser/eslint-plugin-putout?path=packages/eslint-plugin-putout "Dependency Status"
9
5
  [CoverageURL]: https://coveralls.io/github/coderaiser/putout?branch=master
10
6
  [CoverageIMGURL]: https://coveralls.io/repos/coderaiser/putout/badge.svg?branch=master&service=github
11
7
 
@@ -48,8 +44,10 @@ Then configure the rules you want to use under the rules section.
48
44
  "putout/keyword-spacing": "error",
49
45
  "putout/newline-function-call-arguments": "error",
50
46
  "putout/function-declaration-paren-newline": "error",
47
+ "putout/add-newlines-between-types-in-union": "error",
51
48
  "putout/remove-newline-after-default-import": "error",
52
49
  "putout/remove-newline-from-empty-object": "error",
50
+ "putout/remove-empty-newline-before-first-specifier": "error",
53
51
  "putout/remove-empty-newline-after-last-specifier": "error",
54
52
  "putout/objects-braces-inside-array": "error",
55
53
  "putout/object-init": "error"
@@ -69,8 +67,10 @@ Then configure the rules you want to use under the rules section.
69
67
  - [Keyword spacing](/packages/eslint-plugin-putout/lib/keyword-spacing)
70
68
  - [Newline function call arguments](/packages/eslint-plugin-putout/lib/newline-function-call-arguments)
71
69
  - [Function declaration paren newline](/packages/eslint-plugin-putout/lib/function-declaration-paren-newline)
70
+ - [Add newlines between types in union](/packages/eslint-plugin-putout/lib/add-newlines-between-types-in-union)
72
71
  - [Remove newline after default import](/packages/eslint-plugin-putout/lib/remove-newline-after-default-import)
73
72
  - [Remove newline from empty object](/packages/eslint-plugin-putout/lib/remove-newline-from-empty-object)
73
+ - [Remove empty newline before first specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-before-first-specifier)
74
74
  - [Remove empty newline after last specifier](/packages/eslint-plugin-putout/lib/remove-empty-newline-after-last-specifier)
75
75
  - [Objects braces inside array](/packages/eslint-plugin-putout/lib/objects-braces-inside-array)
76
76
  - [Object init](/packages/eslint-plugin-putout/lib/object-init)
@@ -0,0 +1,20 @@
1
+ # Add new lines between types in union (add-newlines-between-types-in-union)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to add newlines between types in union.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ const a = string | number | object | boolean;
11
+ ```
12
+
13
+ Examples of **correct** code for this rule:
14
+
15
+ ```js
16
+ const a = string
17
+ | number
18
+ | object
19
+ | boolean;
20
+ ```
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+
5
+ const {isTSTypeAliasDeclaration} = types;
6
+
7
+ module.exports.category = 'typescript';
8
+ module.exports.report = () => 'Add newlines between types in union';
9
+
10
+ const regExp = /[^\n]\|\s[A-Za-z]/;
11
+
12
+ module.exports.filter = ({text, node}) => {
13
+ if (!isTSTypeAliasDeclaration(node.parent))
14
+ return false;
15
+
16
+ if (text.includes('\n'))
17
+ return false;
18
+
19
+ if (node.types.length <= 3)
20
+ return false;
21
+
22
+ return regExp.test(text);
23
+ };
24
+
25
+ module.exports.fix = ({text}) => {
26
+ return text.replace(/\s\|/g, '\n |');
27
+ };
28
+
29
+ module.exports.include = () => [
30
+ 'TSUnionType',
31
+ ];
32
+
package/lib/index.js CHANGED
@@ -25,8 +25,10 @@ module.exports.rules = {
25
25
  ...getWrapRule('keyword-spacing'),
26
26
  ...getWrapRule('newline-function-call-arguments'),
27
27
  ...getWrapRule('function-declaration-paren-newline'),
28
+ ...getWrapRule('add-newlines-between-types-in-union'),
28
29
  ...getWrapRule('remove-newline-after-default-import'),
29
30
  ...getWrapRule('remove-newline-from-empty-object'),
31
+ ...getWrapRule('remove-empty-newline-before-first-specifier'),
30
32
  ...getWrapRule('remove-empty-newline-after-last-specifier'),
31
33
  ...getWrapRule('objects-braces-inside-array'),
32
34
  ...getWrapRule('object-init'),
@@ -56,8 +58,10 @@ const recommended = {
56
58
  'putout/keyword-spacing': 'error',
57
59
  'putout/newline-function-call-arguments': 'error',
58
60
  'putout/function-declaration-paren-newline': 'error',
61
+ 'putout/add-newlines-between-types-in-union': 'error',
59
62
  'putout/remove-newline-after-default-import': 'error',
60
63
  'putout/remove-newline-from-empty-object': 'error',
64
+ 'putout/remove-empty-newline-before-first-specifier': 'error',
61
65
  'putout/remove-empty-newline-after-last-specifier': 'error',
62
66
  'putout/objects-braces-inside-array': 'error',
63
67
  'putout/object-init': 'error',
package/lib/markdown.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const parserOpts = require('@putout/engine-parser/babel/options');
3
4
  const [ts] = require('./ts');
4
5
 
5
6
  const commonRules = {
@@ -29,6 +30,7 @@ module.exports = [{
29
30
  requireConfigFile: false,
30
31
  babelOptions: {
31
32
  sourceType: 'module',
33
+ parserOpts,
32
34
  plugins: [
33
35
  '@babel/plugin-syntax-class-properties',
34
36
  '@babel/plugin-syntax-top-level-await',
@@ -1,7 +1,7 @@
1
1
  # check if path can be resolved and fix if cannot (no-unresolved)
2
2
 
3
- Similar to [`no-unresolved`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md) from
4
- [`eslint-plugin-putout`](https://github.com/import-js/eslint-plugin-import). But supports only `ESM` and have `autofix`.
3
+ Similar to [`no-unresolved`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md) from
4
+ [`eslint-plugin-putout`](https://github.com/import-js/eslint-plugin-import). But supports only `ESM` and have `autofix`.
5
5
 
6
6
  ## Rule Details
7
7
 
@@ -27,4 +27,3 @@ Examples of **correct** code for this rule:
27
27
  import x from './y.js';
28
28
  import dir from './dir/index.js';
29
29
  ```
30
-
@@ -12,6 +12,12 @@ import {
12
12
  b,
13
13
 
14
14
  } from 'y';
15
+
16
+ push({
17
+ a,
18
+ b,
19
+
20
+ });
15
21
  ```
16
22
 
17
23
  Examples of **correct** code for this rule:
@@ -21,4 +27,9 @@ import {
21
27
  a,
22
28
  b,
23
29
  } from 'y';
30
+
31
+ push({
32
+ a,
33
+ b,
34
+ });
24
35
  ```
@@ -3,7 +3,7 @@
3
3
  module.exports.category = 'import';
4
4
  module.exports.report = () => 'Remove newline after last specifier';
5
5
 
6
- const regExp = /\n\s+}/;
6
+ const regExp = /\n\n(\s+)?}/;
7
7
 
8
8
  module.exports.filter = ({text}) => {
9
9
  return regExp.test(text);
@@ -16,5 +16,6 @@ module.exports.fix = ({text}) => {
16
16
 
17
17
  module.exports.include = () => [
18
18
  'ImportDeclaration',
19
+ 'ObjectExpression',
19
20
  ];
20
21
 
@@ -0,0 +1,35 @@
1
+ # Remove empty new line before first specifier(remove-empty-newline-before-first-specifier)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to remove empty newline before first specifier.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ import {
11
+
12
+ a,
13
+ b,
14
+ } from 'y';
15
+
16
+ push({
17
+
18
+ a,
19
+ b,
20
+ });
21
+ ```
22
+
23
+ Examples of **correct** code for this rule:
24
+
25
+ ```js
26
+ import {
27
+ a,
28
+ b,
29
+ } from 'y';
30
+
31
+ push({
32
+ a,
33
+ b,
34
+ });
35
+ ```
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ module.exports.category = 'import';
4
+ module.exports.report = () => 'Remove newline before first specifier';
5
+
6
+ const regExp = /{\n(\s+)?\n/;
7
+
8
+ module.exports.filter = ({text}) => {
9
+ return regExp.test(text);
10
+ };
11
+
12
+ module.exports.fix = ({text}) => {
13
+ return text
14
+ .replace(regExp, '{\n');
15
+ };
16
+
17
+ module.exports.include = () => [
18
+ 'ImportDeclaration',
19
+ 'ObjectExpression',
20
+ ];
21
+
@@ -8,7 +8,6 @@ Examples of **incorrect** code for this rule:
8
8
 
9
9
  ```js
10
10
  const a = {
11
-
12
11
  };
13
12
  ```
14
13
 
@@ -23,4 +23,8 @@ Examples of **correct** code for this rule:
23
23
  ```js
24
24
  const {username} = user;
25
25
  import {password} from './user.js';
26
+
27
+ import {
28
+ helloWorld as simpleHello,
29
+ } from './hello.js';
26
30
  ```
@@ -1,6 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const {types} = require('putout');
3
+ const {
4
+ operator,
5
+ types,
6
+ } = require('putout');
7
+
4
8
  const {
5
9
  isRestElement,
6
10
  isImportDeclaration,
@@ -10,6 +14,10 @@ const {
10
14
  const NewLinesReg = /([\s,]+)?\n(\s+)?/g;
11
15
  const AssignRegExp = /{\n?.*=.*\n?.*}/;
12
16
 
17
+ const {
18
+ compare,
19
+ } = operator;
20
+
13
21
  module.exports.category = 'destructuring';
14
22
  module.exports.report = () => 'Keep curly braces on one line when you have one destructuring property';
15
23
 
@@ -18,16 +26,19 @@ module.exports.include = () => [
18
26
  'ImportDeclaration[specifiers.length=1]',
19
27
  ];
20
28
 
21
- module.exports.filter = ({node, getText}) => {
22
- const text = getText(node.parent);
29
+ module.exports.filter = ({node, text, getText}) => {
30
+ const parentText = getText(node.parent);
31
+
32
+ if (isImportDeclaration(node) && !compare(node.specifiers[0].local, node.specifiers[0].imported))
33
+ return false;
23
34
 
24
- if (isImportDeclaration(node) && /import {\n/.test(getText(node)))
35
+ if (isImportDeclaration(node) && /import {\n/.test(text))
25
36
  return true;
26
37
 
27
- if (AssignRegExp.test(text))
38
+ if (AssignRegExp.test(parentText))
28
39
  return false;
29
40
 
30
- if (isVariableDeclarator(node) && /(const|let|var) {\n/.test(text))
41
+ if (isVariableDeclarator(node) && /(const|let|var) {\n/.test(parentText))
31
42
  return true;
32
43
 
33
44
  return false;
package/lib/ts.js CHANGED
@@ -1,11 +1,14 @@
1
1
  'use strict';
2
2
 
3
+ const parserOpts = require('@putout/engine-parser/babel/options');
4
+
3
5
  module.exports = [{
4
6
  files: '*.ts',
5
7
  parser: '@babel/eslint-parser/experimental-worker',
6
8
  parserOptions: {
7
9
  requireConfigFile: false,
8
10
  babelOptions: {
11
+ parserOpts,
9
12
  plugins: ['@babel/plugin-syntax-typescript'],
10
13
  },
11
14
  },
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "11.4.0",
3
+ "version": "11.8.0",
4
4
  "description": "eslint plugin for putout",
5
5
  "release": false,
6
6
  "tag": false,
7
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout",
7
8
  "changelog": false,
8
9
  "repository": {
9
10
  "type": "git",
@@ -37,6 +38,7 @@
37
38
  "@babel/plugin-syntax-class-properties": "^7.12.1",
38
39
  "@babel/plugin-syntax-top-level-await": "^7.12.1",
39
40
  "@babel/plugin-syntax-typescript": "^7.12.1",
41
+ "@putout/engine-parser": "^4.6.0",
40
42
  "@putout/eslint-config": "^6.0.0",
41
43
  "align-spaces": "^1.0.0",
42
44
  "eslint-plugin-node": "^11.0.0",