eslint-plugin-putout 16.4.0 β†’ 16.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
@@ -21,12 +21,8 @@ Add `putout` to the plugins section of your `.eslintrc.json` configuration file.
21
21
 
22
22
  ```json
23
23
  {
24
- "extends": [
25
- "plugin:putout/recommended"
26
- ],
27
- "plugins": [
28
- "putout"
29
- ]
24
+ "extends": ["plugin:putout/recommended"],
25
+ "plugins": ["putout"]
30
26
  }
31
27
  ```
32
28
 
@@ -123,12 +119,8 @@ When using 🐊**Putout** in IDE with `--fix` on save, or when you want to disab
123
119
 
124
120
  ```json
125
121
  {
126
- "extends": [
127
- "plugin:putout/safe"
128
- ],
129
- "plugins": [
130
- "putout"
131
- ]
122
+ "extends": ["plugin:putout/safe"],
123
+ "plugins": ["putout"]
132
124
  }
133
125
  ```
134
126
 
@@ -162,16 +154,28 @@ Disabled 🐊**Putout** rules:
162
154
 
163
155
  When you want to enable ability to align spaces on empty lines, while have all benefits of `safe` preset: use `safe+align`.
164
156
 
157
+ ### jsx
158
+
159
+ When you need to support `jsx` in files using `js` extension, use:
160
+
161
+ ```json
162
+ {
163
+ "extends": [
164
+ "plugin:putout/jsx"
165
+ ],
166
+ "plugins": [
167
+ "putout"
168
+ ]
169
+ }
170
+ ```
171
+
165
172
  ## Flat
166
173
 
167
174
  The time is came for a [FlatConfig](https://eslint.org/blog/2022/08/new-config-system-part-2/). To use it with `eslint-plugin-putout` add to `eslint.config.js`:
168
175
 
169
176
  ```js
170
177
  const {recommended} = require('eslint-plugin-putout/config');
171
- module.exports = [
172
- ...recommended, {
173
- },
174
- ];
178
+ module.exports = [...recommended, {}];
175
179
  ```
176
180
 
177
181
  `safe` and `safeAlign` supported as well.
@@ -1,4 +1,4 @@
1
- # array-elements-newline
1
+ # array-element-newline
2
2
 
3
3
  This rule aims to add newlines between array elements.
4
4
  It exists because [`array-element-newline`](https://eslint.org/docs/rules/array-element-newline) requires [`array-bracket-newline`](https://eslint.org/docs/rules/array-bracket-newline) which conflicts with [`object-braces-inside-array`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/objects-braces-inside-array#readme).
@@ -2,15 +2,18 @@
2
2
 
3
3
  const {types} = require('putout');
4
4
  const {
5
+ isArrayExpression,
5
6
  isMemberExpression,
6
- isVariableDeclarator,
7
+ isCallExpression,
7
8
  } = types;
8
9
 
10
+ const isString = (a) => typeof a === 'string';
11
+ const isBool = (a) => typeof a === 'boolean';
12
+
9
13
  module.exports.category = 'array';
10
14
  module.exports.report = () => 'Add newlines between array elements';
11
15
 
12
- const regexp = /['\da-zA-Z]+, ['\da-zA-Z]/;
13
-
16
+ const regexp = /['"\da-zA-Z]+, ['"\da-zA-Z]/;
14
17
  const isSupportedNode = (a) => {
15
18
  if (!a)
16
19
  return false;
@@ -23,21 +26,34 @@ const isSupportedNode = (a) => {
23
26
 
24
27
  return false;
25
28
  };
26
-
27
29
  module.exports.filter = ({text, node}) => {
28
30
  if (isMemberExpression(node.parent))
29
31
  return false;
30
32
 
31
- const supported = node.elements
32
- .every(isSupportedNode);
33
+ const supported = node.elements.every(isSupportedNode);
33
34
 
34
35
  if (!supported)
35
36
  return false;
36
37
 
37
- if (!isVariableDeclarator(node.parent))
38
+ if (isCallExpression(node.parent))
39
+ return false;
40
+
41
+ if (node.parent.parent.type === 'Property')
38
42
  return false;
39
43
 
40
- if (node.elements.length < 5)
44
+ if (node.parent.type === 'Property' && node.parent.key.value !== 'plugins')
45
+ return false;
46
+
47
+ if (isArrayExpression(node.parent))
48
+ return false;
49
+
50
+ if (differentTypes(node))
51
+ return false;
52
+
53
+ if (/Statement/.test(node.parent.type))
54
+ return false;
55
+
56
+ if (node.elements.length < 5 && isShortValues(node.elements))
41
57
  return false;
42
58
 
43
59
  if (regexp.test(text))
@@ -45,15 +61,48 @@ module.exports.filter = ({text, node}) => {
45
61
 
46
62
  return false;
47
63
  };
48
-
49
64
  module.exports.fix = ({text}) => {
50
- return text
51
- .replace(/\[/g, '[\n')
52
- .replace(/\]/g, '\n]')
65
+ return text.replace(/\[/g, '[\n').replace(/\]/g, '\n]')
53
66
  .replace(/,/g, ',\n');
54
67
  };
68
+ module.exports.include = () => ['ArrayExpression'];
55
69
 
56
- module.exports.include = () => [
57
- 'ArrayExpression',
58
- ];
70
+ function isShortValues(elements) {
71
+ for (const {type, value} of elements) {
72
+ if (type === 'Literal' && value.length > 1)
73
+ return false;
74
+ }
75
+
76
+ return true;
77
+ }
78
+
79
+ function differentTypes({elements}) {
80
+ let hasLiteral = false;
81
+ let hasIdentifier = false;
82
+ let hasBool = false;
83
+ let hasStr = false;
84
+
85
+ for (const {type, value} of elements) {
86
+ if (type === 'Literal') {
87
+ hasLiteral = true;
88
+
89
+ if (isString(value))
90
+ hasStr = true;
91
+
92
+ if (isBool(value))
93
+ hasBool = true;
94
+
95
+ if (hasStr && hasBool)
96
+ return true;
97
+ }
98
+
99
+ if (type === 'Identifier')
100
+ hasIdentifier = true;
101
+
102
+ if (hasLiteral && hasIdentifier)
103
+ return true;
104
+ }
105
+
106
+ return false;
107
+ }
59
108
 
package/lib/index.js CHANGED
@@ -6,15 +6,13 @@ const json = require('./json');
6
6
  const yaml = require('./yaml');
7
7
  const html = require('./html');
8
8
  const ts = require('./ts');
9
-
9
+ const jsx = require('./jsx');
10
10
  const getRule = (a) => ({
11
11
  [a]: require(`./${a}`),
12
12
  });
13
-
14
13
  const getWrapRule = (a) => ({
15
14
  [a]: createPlugin(require(`./${a}`)),
16
15
  });
17
-
18
16
  module.exports.rules = {
19
17
  ...getWrapRule('array-element-newline'),
20
18
  ...getWrapRule('single-property-destructuring'),
@@ -50,17 +48,14 @@ module.exports.rules = {
50
48
  ...getRule('remove-empty-newline-after-import'),
51
49
  ...getRule('remove-empty-newline-between-declarations'),
52
50
  };
53
-
54
51
  const config = require('@putout/eslint-config');
55
52
  const {rules} = config;
56
-
57
53
  const recommended = {
58
54
  ...config,
59
55
  rules: {
60
56
  ...rules,
61
57
  'no-debugger': 'off',
62
58
  'no-unused-vars': 'off',
63
-
64
59
  'putout/array-element-newline': 'error',
65
60
  'putout/single-property-destructuring': 'error',
66
61
  'putout/multiple-properties-destructuring': 'error',
@@ -94,24 +89,14 @@ const recommended = {
94
89
  'putout/tape-remove-newline-before-t-end': 'error',
95
90
  'putout/nonblock-statement-body-newline': 'error',
96
91
  'putout/putout': 'error',
97
-
98
92
  'n/no-unsupported-features/es-syntax': 'off',
99
93
  'n/no-missing-import': 'off',
100
94
  'n/no-missing-require': 'off',
101
95
  'n/no-process-exit': 'off',
102
96
  },
103
- overrides: [
104
- ...markdown,
105
- ...json,
106
- ...yaml,
107
- ...html,
108
- ...ts,
109
- ],
110
- plugins: [
111
- 'n',
112
- ],
97
+ overrides: [...markdown, ...json, ...yaml, ...html, ...ts, ...jsx],
98
+ plugins: ['n'],
113
99
  };
114
-
115
100
  const safe = {
116
101
  ...recommended,
117
102
  rules: {
@@ -143,9 +128,9 @@ const safe = {
143
128
  }],
144
129
  },
145
130
  };
146
-
147
131
  module.exports.configs = {
148
132
  recommended,
133
+ 'jsx': jsx.jsx,
149
134
  safe,
150
135
  'safe+align': {
151
136
  ...safe,
@@ -155,4 +140,3 @@ module.exports.configs = {
155
140
  },
156
141
  },
157
142
  };
158
-
package/lib/jsx.js ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ const jsx = {
4
+ rules: {
5
+ 'react/jsx-indent': 'error',
6
+ 'react/jsx-wrap-multilines': ['error', {
7
+ arrow: 'ignore',
8
+ return: 'parens-new-line',
9
+ declaration: 'ignore',
10
+ }],
11
+ },
12
+ plugins: ['react'],
13
+ settings: {
14
+ react: {
15
+ version: 'latest',
16
+ },
17
+ },
18
+ };
19
+
20
+ module.exports = [{
21
+ files: ['*.jsx'],
22
+ ...jsx,
23
+ }];
24
+
25
+ module.exports.jsx = jsx;
26
+
package/lib/markdown.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const parserOpts = require('@putout/engine-parser/babel/options');
4
4
  const parserPlugins = require('@putout/engine-parser/babel/plugins');
5
5
  const [ts, tsx] = require('./ts');
6
+ const {jsx} = require('./jsx');
6
7
 
7
8
  const commonRules = {
8
9
  'no-undef': 'off',
@@ -38,20 +39,35 @@ const parserOptions = {
38
39
  };
39
40
 
40
41
  module.exports = [{
41
- files: ['*.md{js}', '*.md{jsx}'],
42
+ files: ['*.md{js}'],
42
43
  rules: commonRules,
43
44
  parser: '@babel/eslint-parser/experimental-worker',
44
45
  parserOptions,
46
+ }, {
47
+ files: ['*.md{jsx}'],
48
+ rules: {
49
+ ...commonRules,
50
+ ...jsx.rules,
51
+ },
52
+ plugins: jsx.plugins,
53
+ parser: '@babel/eslint-parser/experimental-worker',
54
+ parserOptions,
45
55
  }, {
46
56
  ...tsx,
57
+ ...jsx,
47
58
  files: '*.md{tsx}',
48
59
  rules: {
49
60
  ...commonRules,
50
61
  ...ts.rules,
62
+ ...jsx.rules,
51
63
  '@typescript-eslint/no-unused-vars': 'off',
52
64
  '@typescript-eslint/no-explicit-any': 'off',
53
65
  '@typescript-eslint/no-inferrable-types': 'off',
54
66
  },
67
+ plugins: [
68
+ ...tsx.plugins,
69
+ ...jsx.plugins,
70
+ ],
55
71
  }, {
56
72
  ...ts,
57
73
  files: '*.md{ts}',
package/lib/ts.js CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  const {rules} = require('@putout/eslint-config');
4
+ const jsx = require('./jsx');
5
+
4
6
  const warnOnUnsupportedTypeScriptVersion = false;
5
7
 
6
8
  const extensionRules = {
@@ -91,6 +93,7 @@ const ts = {
91
93
  module.exports = [
92
94
  ts, {
93
95
  ...ts,
96
+ ...jsx.jsx,
94
97
  files: '*.tsx',
95
98
  parserOptions: {
96
99
  warnOnUnsupportedTypeScriptVersion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "16.4.0",
3
+ "version": "16.6.0",
4
4
  "type": "commonjs",
5
5
  "description": "ESLint plugin for 🐊Putout",
6
6
  "release": false,
@@ -51,6 +51,7 @@
51
51
  "@typescript-eslint/parser": "^5.4.0",
52
52
  "align-spaces": "^1.0.0",
53
53
  "eslint-plugin-n": "^15.2.4",
54
+ "eslint-plugin-react": "^7.32.2",
54
55
  "try-catch": "^3.0.0",
55
56
  "typescript": "^4.5.2"
56
57
  },