eslint-plugin-putout 16.5.0 β 16.7.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 +20 -16
- package/lib/add-newline-before-function-call/index.js +8 -3
- package/lib/array-element-newline/index.js +1 -0
- package/lib/index.js +4 -18
- package/lib/jsx.js +26 -0
- package/lib/markdown.js +17 -1
- package/lib/ts.js +3 -0
- package/package.json +2 -1
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
|
-
|
|
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
|
-
|
|
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.
|
|
@@ -5,9 +5,10 @@ const {
|
|
|
5
5
|
isBlockStatement,
|
|
6
6
|
isVariableDeclaration,
|
|
7
7
|
isExpressionStatement,
|
|
8
|
+
isProgram,
|
|
8
9
|
} = types;
|
|
9
10
|
|
|
10
|
-
const regExp = /^\n( +)?\n
|
|
11
|
+
const regExp = /^\n( +)?\n( +)?$/;
|
|
11
12
|
|
|
12
13
|
module.exports.report = () => 'Add newline before expression';
|
|
13
14
|
|
|
@@ -20,7 +21,7 @@ module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) =
|
|
|
20
21
|
|
|
21
22
|
const {parent} = node.parent;
|
|
22
23
|
|
|
23
|
-
if (!isBlockStatement(parent))
|
|
24
|
+
if (!isBlockStatement(parent) && !isProgram(parent))
|
|
24
25
|
return false;
|
|
25
26
|
|
|
26
27
|
const {body} = parent;
|
|
@@ -29,6 +30,9 @@ module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) =
|
|
|
29
30
|
if (n < 3)
|
|
30
31
|
return false;
|
|
31
32
|
|
|
33
|
+
if (body[0].expression === node)
|
|
34
|
+
return false;
|
|
35
|
+
|
|
32
36
|
const spaces = getSpacesBeforeNode(node, text);
|
|
33
37
|
|
|
34
38
|
if (!spaces)
|
|
@@ -55,6 +59,8 @@ module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) =
|
|
|
55
59
|
|
|
56
60
|
return true;
|
|
57
61
|
}
|
|
62
|
+
|
|
63
|
+
return false;
|
|
58
64
|
};
|
|
59
65
|
|
|
60
66
|
module.exports.fix = ({text}) => {
|
|
@@ -64,5 +70,4 @@ module.exports.fix = ({text}) => {
|
|
|
64
70
|
module.exports.include = () => [
|
|
65
71
|
'CallExpression',
|
|
66
72
|
'AssignmentExpression',
|
|
67
|
-
'ReturnStatement',
|
|
68
73
|
];
|
package/lib/index.js
CHANGED
|
@@ -6,11 +6,10 @@ 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
|
});
|
|
@@ -50,17 +49,14 @@ module.exports.rules = {
|
|
|
50
49
|
...getRule('remove-empty-newline-after-import'),
|
|
51
50
|
...getRule('remove-empty-newline-between-declarations'),
|
|
52
51
|
};
|
|
53
|
-
|
|
54
52
|
const config = require('@putout/eslint-config');
|
|
55
53
|
const {rules} = config;
|
|
56
|
-
|
|
57
54
|
const recommended = {
|
|
58
55
|
...config,
|
|
59
56
|
rules: {
|
|
60
57
|
...rules,
|
|
61
58
|
'no-debugger': 'off',
|
|
62
59
|
'no-unused-vars': 'off',
|
|
63
|
-
|
|
64
60
|
'putout/array-element-newline': 'error',
|
|
65
61
|
'putout/single-property-destructuring': 'error',
|
|
66
62
|
'putout/multiple-properties-destructuring': 'error',
|
|
@@ -94,24 +90,14 @@ const recommended = {
|
|
|
94
90
|
'putout/tape-remove-newline-before-t-end': 'error',
|
|
95
91
|
'putout/nonblock-statement-body-newline': 'error',
|
|
96
92
|
'putout/putout': 'error',
|
|
97
|
-
|
|
98
93
|
'n/no-unsupported-features/es-syntax': 'off',
|
|
99
94
|
'n/no-missing-import': 'off',
|
|
100
95
|
'n/no-missing-require': 'off',
|
|
101
96
|
'n/no-process-exit': 'off',
|
|
102
97
|
},
|
|
103
|
-
overrides: [
|
|
104
|
-
|
|
105
|
-
...json,
|
|
106
|
-
...yaml,
|
|
107
|
-
...html,
|
|
108
|
-
...ts,
|
|
109
|
-
],
|
|
110
|
-
plugins: [
|
|
111
|
-
'n',
|
|
112
|
-
],
|
|
98
|
+
overrides: [...markdown, ...json, ...yaml, ...html, ...ts, ...jsx],
|
|
99
|
+
plugins: ['n'],
|
|
113
100
|
};
|
|
114
|
-
|
|
115
101
|
const safe = {
|
|
116
102
|
...recommended,
|
|
117
103
|
rules: {
|
|
@@ -146,6 +132,7 @@ const safe = {
|
|
|
146
132
|
|
|
147
133
|
module.exports.configs = {
|
|
148
134
|
recommended,
|
|
135
|
+
'jsx': jsx.jsx,
|
|
149
136
|
safe,
|
|
150
137
|
'safe+align': {
|
|
151
138
|
...safe,
|
|
@@ -155,4 +142,3 @@ module.exports.configs = {
|
|
|
155
142
|
},
|
|
156
143
|
},
|
|
157
144
|
};
|
|
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}'
|
|
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.
|
|
3
|
+
"version": "16.7.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
|
},
|