redlint 3.20.0 → 3.21.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/ChangeLog
CHANGED
package/lib/edit/edit.js
CHANGED
|
@@ -3,12 +3,14 @@ import {execSync} from 'node:child_process';
|
|
|
3
3
|
import {readFileSync} from 'node:fs';
|
|
4
4
|
import {readDirectory} from './read-directory/index.js';
|
|
5
5
|
import {writeTmpFile as _writeTmpFile} from './write-tmp-file.js';
|
|
6
|
+
import {renameFiles as _renameFiles} from './rename-files/index.js';
|
|
6
7
|
|
|
7
8
|
export const edit = (filesystem, {dir, recursive, full}, overrides = {}) => {
|
|
8
9
|
const {
|
|
9
10
|
execute = execSync,
|
|
10
11
|
readFileContent = readFileSync,
|
|
11
12
|
writeTmpFile = _writeTmpFile,
|
|
13
|
+
renameFiles = _renameFiles,
|
|
12
14
|
env = process.env,
|
|
13
15
|
} = overrides;
|
|
14
16
|
|
|
@@ -20,8 +22,8 @@ export const edit = (filesystem, {dir, recursive, full}, overrides = {}) => {
|
|
|
20
22
|
full,
|
|
21
23
|
});
|
|
22
24
|
|
|
23
|
-
const
|
|
24
|
-
const [tmpFile, removeTmpFile] = writeTmpFile(
|
|
25
|
+
const from = names.join('\n');
|
|
26
|
+
const [tmpFile, removeTmpFile] = writeTmpFile(from);
|
|
25
27
|
|
|
26
28
|
const editor = EDITOR || 'vim';
|
|
27
29
|
execute(`${editor} ${tmpFile}`, {
|
|
@@ -33,6 +35,13 @@ export const edit = (filesystem, {dir, recursive, full}, overrides = {}) => {
|
|
|
33
35
|
],
|
|
34
36
|
});
|
|
35
37
|
|
|
36
|
-
readFileContent(tmpFile, 'utf8');
|
|
38
|
+
const to = readFileContent(tmpFile, 'utf8');
|
|
39
|
+
const newNames = to.split('\n');
|
|
40
|
+
|
|
37
41
|
removeTmpFile();
|
|
42
|
+
renameFiles(filesystem, {
|
|
43
|
+
dir,
|
|
44
|
+
from: names,
|
|
45
|
+
to: newNames,
|
|
46
|
+
});
|
|
38
47
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parse,
|
|
3
|
+
print,
|
|
4
|
+
transform,
|
|
5
|
+
} from 'putout';
|
|
6
|
+
import {
|
|
7
|
+
branch as originalBranch,
|
|
8
|
+
merge as originalMerge,
|
|
9
|
+
} from '@putout/processor-filesystem';
|
|
10
|
+
import * as renameFilesPlugin from './rename-files-plugin/index.js';
|
|
11
|
+
|
|
12
|
+
export const renameFiles = (filesystem, {dir, from, to}, overrides = {}) => {
|
|
13
|
+
const {
|
|
14
|
+
branch = originalBranch,
|
|
15
|
+
merge = originalMerge,
|
|
16
|
+
} = overrides;
|
|
17
|
+
|
|
18
|
+
const [{source}] = branch(filesystem);
|
|
19
|
+
|
|
20
|
+
const ast = parse(source);
|
|
21
|
+
|
|
22
|
+
transform(ast, filesystem, {
|
|
23
|
+
fix: true,
|
|
24
|
+
fixCount: 1,
|
|
25
|
+
rules: {
|
|
26
|
+
'rename-files': ['on', {
|
|
27
|
+
dir,
|
|
28
|
+
from,
|
|
29
|
+
to,
|
|
30
|
+
}],
|
|
31
|
+
},
|
|
32
|
+
plugins: [
|
|
33
|
+
['rename-files', renameFilesPlugin],
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const code = print(ast);
|
|
38
|
+
|
|
39
|
+
return merge(filesystem, [code]);
|
|
40
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {join} from 'node:path';
|
|
2
|
+
import {operator} from 'putout';
|
|
3
|
+
|
|
4
|
+
const {renameFile} = operator;
|
|
5
|
+
|
|
6
|
+
export const report = (filePath, {from, to}) => `Rename '${from}' to '${to}'`;
|
|
7
|
+
|
|
8
|
+
export const fix = (filePath, {to}) => {
|
|
9
|
+
renameFile(filePath, to);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const addFromTo = (namesFrom, namesTo) => (a, i) => [
|
|
13
|
+
namesFrom[i],
|
|
14
|
+
namesTo[i],
|
|
15
|
+
a,
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export const scan = (path, {push, trackFile, options}) => {
|
|
19
|
+
const {
|
|
20
|
+
from = [],
|
|
21
|
+
to = [],
|
|
22
|
+
dir = '/',
|
|
23
|
+
} = options;
|
|
24
|
+
|
|
25
|
+
if (isEqual(from, to))
|
|
26
|
+
return;
|
|
27
|
+
|
|
28
|
+
const [fullNames, fromNames, toNames] = getRenamedFiles(dir, from, to);
|
|
29
|
+
const convertToTuple = addFromTo(fromNames, toNames);
|
|
30
|
+
const trackFileIterator = trackFile(path, fullNames).map(convertToTuple);
|
|
31
|
+
|
|
32
|
+
for (const [from, to, currentFile] of trackFileIterator) {
|
|
33
|
+
push(currentFile, {
|
|
34
|
+
from,
|
|
35
|
+
to,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function getRenamedFiles(dir, a, b) {
|
|
41
|
+
const from = [];
|
|
42
|
+
const to = [];
|
|
43
|
+
const full = [];
|
|
44
|
+
const n = a.length;
|
|
45
|
+
let i = -1;
|
|
46
|
+
|
|
47
|
+
while (++i < n) {
|
|
48
|
+
if (a[i] !== b[i]) {
|
|
49
|
+
const currentFrom = a[i];
|
|
50
|
+
const currentTo = b[i];
|
|
51
|
+
|
|
52
|
+
full.push(join(
|
|
53
|
+
dir,
|
|
54
|
+
currentFrom,
|
|
55
|
+
));
|
|
56
|
+
from.push(currentFrom);
|
|
57
|
+
to.push(currentTo);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return [
|
|
62
|
+
full,
|
|
63
|
+
from,
|
|
64
|
+
to,
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isEqual(a, b) {
|
|
69
|
+
if (a.length !== b.length)
|
|
70
|
+
return false;
|
|
71
|
+
|
|
72
|
+
let i = a.length;
|
|
73
|
+
|
|
74
|
+
while (--i >= 0) {
|
|
75
|
+
if (a[i] !== b[i])
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return true;
|
|
80
|
+
}
|
package/lib/lint/lint.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {transformAsync, parse} from 'putout';
|
|
2
2
|
import parseOptions from 'putout/parse-options';
|
|
3
3
|
import {createProgress} from '@putout/engine-runner/progress';
|
|
4
|
-
import {init} from '@putout/operator-filesystem';
|
|
4
|
+
import {deinit, init} from '@putout/operator-filesystem';
|
|
5
5
|
import {toJS, __filesystem} from '@putout/operator-json';
|
|
6
6
|
import filesystemCLI from '@putout/cli-filesystem';
|
|
7
7
|
|
|
@@ -12,8 +12,7 @@ export const lint = async (filesystem, overrides = {}) => {
|
|
|
12
12
|
progress = createProgress(),
|
|
13
13
|
} = overrides;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
init(filesystemCLI);
|
|
15
|
+
!test && init(filesystemCLI);
|
|
17
16
|
|
|
18
17
|
const source = toJS(filesystem, __filesystem);
|
|
19
18
|
|
|
@@ -30,8 +29,7 @@ export const lint = async (filesystem, overrides = {}) => {
|
|
|
30
29
|
progress,
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
init(filesystemCLI);
|
|
32
|
+
!test && deinit(filesystemCLI);
|
|
35
33
|
|
|
36
34
|
return places;
|
|
37
35
|
};
|