redlint 3.22.1 → 3.22.2
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/ChangeLog
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
join,
|
|
3
|
-
basename,
|
|
4
|
-
dirname,
|
|
5
|
-
} from 'node:path';
|
|
1
|
+
import {basename, dirname} from 'node:path';
|
|
6
2
|
import {operator} from 'putout';
|
|
7
3
|
|
|
8
4
|
const {
|
|
@@ -10,6 +6,9 @@ const {
|
|
|
10
6
|
moveFile,
|
|
11
7
|
renameFile,
|
|
12
8
|
getFilename,
|
|
9
|
+
getParentDirectory,
|
|
10
|
+
removeFile,
|
|
11
|
+
readDirectory,
|
|
13
12
|
} = operator;
|
|
14
13
|
|
|
15
14
|
export const report = (filePath, {from, to}) => `Rename '${from}' to '${to}'`;
|
|
@@ -21,6 +20,15 @@ export const fix = (filePath, {to}) => {
|
|
|
21
20
|
const nameTo = basename(to);
|
|
22
21
|
const nameFrom = basename(filename);
|
|
23
22
|
|
|
23
|
+
if (!nameTo) {
|
|
24
|
+
const dir = getParentDirectory(filePath);
|
|
25
|
+
|
|
26
|
+
removeFile(filePath);
|
|
27
|
+
removeEmptyNestedDirectory(dir);
|
|
28
|
+
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
if (nameFrom !== nameTo)
|
|
25
33
|
renameFile(filePath, nameTo);
|
|
26
34
|
|
|
@@ -41,7 +49,6 @@ export const scan = (path, {push, trackFile, options}) => {
|
|
|
41
49
|
const {
|
|
42
50
|
from = [],
|
|
43
51
|
to = [],
|
|
44
|
-
dir = '/',
|
|
45
52
|
} = options;
|
|
46
53
|
|
|
47
54
|
if (from.length !== to.length)
|
|
@@ -50,7 +57,7 @@ export const scan = (path, {push, trackFile, options}) => {
|
|
|
50
57
|
if (isEqual(from, to))
|
|
51
58
|
return;
|
|
52
59
|
|
|
53
|
-
const [fullNames, fromNames, toNames] = getRenamedFiles(
|
|
60
|
+
const [fullNames, fromNames, toNames] = getRenamedFiles(from, to);
|
|
54
61
|
const convertToTuple = addFromTo(fromNames, toNames);
|
|
55
62
|
const trackFileIterator = trackFile(path, fullNames).map(convertToTuple);
|
|
56
63
|
|
|
@@ -62,7 +69,7 @@ export const scan = (path, {push, trackFile, options}) => {
|
|
|
62
69
|
}
|
|
63
70
|
};
|
|
64
71
|
|
|
65
|
-
function getRenamedFiles(
|
|
72
|
+
function getRenamedFiles(a, b) {
|
|
66
73
|
const from = [];
|
|
67
74
|
const to = [];
|
|
68
75
|
const full = [];
|
|
@@ -74,10 +81,7 @@ function getRenamedFiles(dir, a, b) {
|
|
|
74
81
|
const currentFrom = a[i];
|
|
75
82
|
const currentTo = b[i];
|
|
76
83
|
|
|
77
|
-
full.push(
|
|
78
|
-
dir,
|
|
79
|
-
currentFrom,
|
|
80
|
-
));
|
|
84
|
+
full.push(currentFrom);
|
|
81
85
|
from.push(currentFrom);
|
|
82
86
|
to.push(currentTo);
|
|
83
87
|
}
|
|
@@ -92,11 +96,29 @@ function getRenamedFiles(dir, a, b) {
|
|
|
92
96
|
|
|
93
97
|
function isEqual(a, b) {
|
|
94
98
|
let i = a.length;
|
|
99
|
+
let is = true;
|
|
95
100
|
|
|
96
101
|
while (--i >= 0) {
|
|
97
|
-
if (a[i] !== b[i])
|
|
98
|
-
|
|
102
|
+
if (a[i] !== b[i]) {
|
|
103
|
+
is = false;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
99
106
|
}
|
|
100
107
|
|
|
101
|
-
return
|
|
108
|
+
return is;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function removeEmptyNestedDirectory(parentDir) {
|
|
112
|
+
let nextParentDir = parentDir;
|
|
113
|
+
|
|
114
|
+
while (!readDirectory(parentDir).length) {
|
|
115
|
+
const name = getFilename(parentDir);
|
|
116
|
+
|
|
117
|
+
if (name === '/')
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
nextParentDir = getParentDirectory(parentDir);
|
|
121
|
+
removeFile(parentDir);
|
|
122
|
+
parentDir = nextParentDir;
|
|
123
|
+
}
|
|
102
124
|
}
|