eslint-plugin-putout 22.5.1 → 22.6.1
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/lib/evaluate/index.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {types} = require('putout');
|
|
3
4
|
const {isCorrectLoc} = require('../common');
|
|
5
|
+
const {
|
|
6
|
+
isImportDeclaration,
|
|
7
|
+
isForOfStatement,
|
|
8
|
+
} = types;
|
|
9
|
+
|
|
10
|
+
const parseOptions = (options) => {
|
|
11
|
+
const {maxLength = 15} = options[0] || {};
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
maxLength,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
4
17
|
|
|
5
18
|
module.exports.category = 'destructuring';
|
|
6
19
|
module.exports.report = () => 'Keep each property on separate lines when destructuring long properties';
|
|
7
20
|
|
|
8
21
|
module.exports.include = () => [
|
|
9
22
|
'VariableDeclarator[id.type="ObjectPattern"][id.properties.length>=2]',
|
|
23
|
+
'ImportDeclaration[specifiers.length>=2]',
|
|
10
24
|
];
|
|
11
25
|
|
|
12
26
|
module.exports.fix = ({text}) => {
|
|
@@ -23,26 +37,56 @@ module.exports.fix = ({text}) => {
|
|
|
23
37
|
return `${startText}${endText}`;
|
|
24
38
|
};
|
|
25
39
|
|
|
26
|
-
module.exports.filter = ({node}) => {
|
|
40
|
+
module.exports.filter = ({node}, options) => {
|
|
27
41
|
const {parent} = node.parent;
|
|
42
|
+
const {maxLength} = parseOptions(options);
|
|
28
43
|
|
|
29
|
-
if (parent
|
|
44
|
+
if (isForOfStatement(parent))
|
|
30
45
|
return false;
|
|
31
46
|
|
|
47
|
+
if (isImportDeclaration(node)) {
|
|
48
|
+
const {specifiers} = node;
|
|
49
|
+
const {line} = node.loc.start;
|
|
50
|
+
const isLoc = isCorrectLoc(line, specifiers);
|
|
51
|
+
|
|
52
|
+
const isLength = isCorrectSpecifiersLength(specifiers, {
|
|
53
|
+
maxLength,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return !(isLoc || isLength);
|
|
57
|
+
}
|
|
58
|
+
|
|
32
59
|
const {id} = node;
|
|
33
60
|
const {properties} = id;
|
|
34
61
|
const {line} = node.loc.start;
|
|
35
62
|
const isLoc = isCorrectLoc(line, properties);
|
|
36
|
-
|
|
63
|
+
|
|
64
|
+
const isLength = isCorrectPropertiesLength(properties, {
|
|
65
|
+
maxLength,
|
|
66
|
+
});
|
|
37
67
|
|
|
38
68
|
return !(isLoc || isLength);
|
|
39
69
|
};
|
|
40
70
|
|
|
41
|
-
function
|
|
71
|
+
function isCorrectPropertiesLength(properties, {maxLength}) {
|
|
42
72
|
for (const prop of properties) {
|
|
43
73
|
const {name} = prop.key || prop.argument;
|
|
44
74
|
|
|
45
|
-
if (name.length >=
|
|
75
|
+
if (name.length >= maxLength)
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function isCorrectSpecifiersLength(specifiers, {maxLength}) {
|
|
83
|
+
for (const {imported} of specifiers) {
|
|
84
|
+
if (!imported)
|
|
85
|
+
continue;
|
|
86
|
+
|
|
87
|
+
const {name} = imported;
|
|
88
|
+
|
|
89
|
+
if (name.length >= maxLength)
|
|
46
90
|
return false;
|
|
47
91
|
}
|
|
48
92
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const process = require('process');
|
|
3
|
+
const process = require('node:process');
|
|
4
4
|
const tryCatch = require('try-catch');
|
|
5
5
|
|
|
6
|
-
const {accessSync} = require('fs');
|
|
6
|
+
const {accessSync} = require('node:fs');
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
extname,
|
|
10
10
|
dirname,
|
|
11
11
|
join,
|
|
12
|
-
} = require('path');
|
|
12
|
+
} = require('node:path');
|
|
13
13
|
|
|
14
14
|
const cwd = process.cwd();
|
|
15
15
|
|
package/lib/putout/sync/index.js
CHANGED
package/lib/ts.js
CHANGED
|
@@ -66,21 +66,23 @@ const ts = {
|
|
|
66
66
|
},
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
module.exports = [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
module.exports = [
|
|
70
|
+
ts, {
|
|
71
|
+
...ts,
|
|
72
|
+
...jsx,
|
|
73
|
+
plugins: [
|
|
74
|
+
...ts.plugins,
|
|
75
|
+
...jsx.plugins,
|
|
76
|
+
],
|
|
77
|
+
files: '*.tsx',
|
|
78
|
+
parserOptions: {
|
|
79
|
+
warnOnUnsupportedTypeScriptVersion,
|
|
80
|
+
ecmaFeatures: {
|
|
81
|
+
jsx: true,
|
|
82
|
+
},
|
|
81
83
|
},
|
|
82
84
|
},
|
|
83
|
-
|
|
85
|
+
];
|
|
84
86
|
|
|
85
87
|
function convertPaddingLines([state, ...lines]) {
|
|
86
88
|
const newLines = [];
|