redlint 3.19.1 → 3.20.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 +5 -0
- package/bin/redlint.js +18 -1
- package/lib/choose.js +2 -0
- package/lib/edit/edit.js +38 -0
- package/lib/edit/read-directory/get-filenames/index.js +45 -0
- package/lib/edit/read-directory/index.js +27 -0
- package/lib/edit/write-tmp-file.js +32 -0
- package/lib/menu.js +2 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/bin/redlint.js
CHANGED
|
@@ -28,6 +28,7 @@ import {convert} from '../lib/convert/convert.js';
|
|
|
28
28
|
import {masterConvert} from '../lib/convert/master.js';
|
|
29
29
|
import {askFilename} from '../lib/dialog.js';
|
|
30
30
|
import {masterRename} from '../lib/rename/master.js';
|
|
31
|
+
import {edit} from '../lib/edit/edit.js';
|
|
31
32
|
import {
|
|
32
33
|
isScan,
|
|
33
34
|
isScanDebug,
|
|
@@ -52,6 +53,7 @@ import {
|
|
|
52
53
|
isExit,
|
|
53
54
|
isBundleDebug,
|
|
54
55
|
isConvertRCToFlat,
|
|
56
|
+
isEdit,
|
|
55
57
|
} from '../lib/menu.js';
|
|
56
58
|
|
|
57
59
|
const {log} = console;
|
|
@@ -59,7 +61,7 @@ const {exit} = process;
|
|
|
59
61
|
|
|
60
62
|
const {stringify} = JSON;
|
|
61
63
|
|
|
62
|
-
const [arg] = process.argv.slice(2);
|
|
64
|
+
const [arg, ...argOptions] = process.argv.slice(2);
|
|
63
65
|
let header = true;
|
|
64
66
|
|
|
65
67
|
await uiLoop(arg);
|
|
@@ -126,6 +128,21 @@ async function uiLoop(arg) {
|
|
|
126
128
|
|
|
127
129
|
const filesystem = lintJSON(stringify(result));
|
|
128
130
|
|
|
131
|
+
if (isEdit(arg)) {
|
|
132
|
+
const spinner = ora(`🪶edit filesystem`).start();
|
|
133
|
+
const args = argOptions.join('');
|
|
134
|
+
const recursive = /-r|--recursive/.test(args);
|
|
135
|
+
const full = /-f|--full/.test(args);
|
|
136
|
+
|
|
137
|
+
spinner.succeed();
|
|
138
|
+
return edit(filesystem, {
|
|
139
|
+
dir: CWD,
|
|
140
|
+
type: 'rename',
|
|
141
|
+
full,
|
|
142
|
+
recursive,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
129
146
|
if (isConvertChosen(arg)) {
|
|
130
147
|
let filename = '.eslintrc.json';
|
|
131
148
|
|
package/lib/choose.js
CHANGED
package/lib/edit/edit.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import {execSync} from 'node:child_process';
|
|
3
|
+
import {readFileSync} from 'node:fs';
|
|
4
|
+
import {readDirectory} from './read-directory/index.js';
|
|
5
|
+
import {writeTmpFile as _writeTmpFile} from './write-tmp-file.js';
|
|
6
|
+
|
|
7
|
+
export const edit = (filesystem, {dir, recursive, full}, overrides = {}) => {
|
|
8
|
+
const {
|
|
9
|
+
execute = execSync,
|
|
10
|
+
readFileContent = readFileSync,
|
|
11
|
+
writeTmpFile = _writeTmpFile,
|
|
12
|
+
env = process.env,
|
|
13
|
+
} = overrides;
|
|
14
|
+
|
|
15
|
+
const {EDITOR} = env;
|
|
16
|
+
|
|
17
|
+
const names = readDirectory(filesystem, {
|
|
18
|
+
dir,
|
|
19
|
+
recursive,
|
|
20
|
+
full,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const content = names.join('\n');
|
|
24
|
+
const [tmpFile, removeTmpFile] = writeTmpFile(content);
|
|
25
|
+
|
|
26
|
+
const editor = EDITOR || 'vim';
|
|
27
|
+
execute(`${editor} ${tmpFile}`, {
|
|
28
|
+
stdio: [
|
|
29
|
+
0,
|
|
30
|
+
1,
|
|
31
|
+
2,
|
|
32
|
+
'pipe',
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
readFileContent(tmpFile, 'utf8');
|
|
37
|
+
removeTmpFile();
|
|
38
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {basename, dirname} from 'node:path';
|
|
2
|
+
import {operator} from 'putout';
|
|
3
|
+
|
|
4
|
+
const {getFilename} = operator;
|
|
5
|
+
|
|
6
|
+
export const report = (path, {name}) => name;
|
|
7
|
+
export const fix = () => {};
|
|
8
|
+
export const scan = (path, {push, trackFile, options}) => {
|
|
9
|
+
const {
|
|
10
|
+
dir = '/',
|
|
11
|
+
full,
|
|
12
|
+
recursive,
|
|
13
|
+
} = options;
|
|
14
|
+
|
|
15
|
+
for (const file of trackFile(path, '*')) {
|
|
16
|
+
const path = getFilename(file);
|
|
17
|
+
const currentDir = dirname(path);
|
|
18
|
+
|
|
19
|
+
if (dir === path)
|
|
20
|
+
continue;
|
|
21
|
+
|
|
22
|
+
if (!recursive && currentDir !== dir)
|
|
23
|
+
continue;
|
|
24
|
+
|
|
25
|
+
if (!full && recursive) {
|
|
26
|
+
const name = path
|
|
27
|
+
.replace(dir, '')
|
|
28
|
+
.replace(/^\//, '');
|
|
29
|
+
|
|
30
|
+
if (!name)
|
|
31
|
+
continue;
|
|
32
|
+
|
|
33
|
+
push(file, {
|
|
34
|
+
name,
|
|
35
|
+
});
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const name = full ? path : basename(path);
|
|
40
|
+
|
|
41
|
+
push(file, {
|
|
42
|
+
name,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {parse, transform} from 'putout';
|
|
2
|
+
import {__filesystem, toJS} from '@putout/operator-json';
|
|
3
|
+
import * as getFileNames from './get-filenames/index.js';
|
|
4
|
+
|
|
5
|
+
const getMessage = ({message}) => message;
|
|
6
|
+
|
|
7
|
+
export const readDirectory = (filesystem, {dir, recursive, full}) => {
|
|
8
|
+
const source = toJS(filesystem, __filesystem);
|
|
9
|
+
const ast = parse(source);
|
|
10
|
+
|
|
11
|
+
const places = transform(ast, filesystem, {
|
|
12
|
+
fix: true,
|
|
13
|
+
fixCount: 1,
|
|
14
|
+
rules: {
|
|
15
|
+
'get-filenames': ['on', {
|
|
16
|
+
dir,
|
|
17
|
+
full,
|
|
18
|
+
recursive,
|
|
19
|
+
}],
|
|
20
|
+
},
|
|
21
|
+
plugins: [
|
|
22
|
+
['get-filenames', getFileNames],
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return places.map(getMessage);
|
|
27
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {join} from 'node:path';
|
|
2
|
+
import {tmpdir} from 'node:os';
|
|
3
|
+
import {
|
|
4
|
+
mkdtempSync,
|
|
5
|
+
writeFileSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
} from 'node:fs';
|
|
8
|
+
|
|
9
|
+
const createRemoveTmpFile = (tmpDir, removeDirectory) => () => {
|
|
10
|
+
removeDirectory(tmpDir, {
|
|
11
|
+
recursive: true,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const writeTmpFile = (content, overrides = {}) => {
|
|
16
|
+
const {
|
|
17
|
+
createTmpDirectory = mkdtempSync,
|
|
18
|
+
writeFileContent = writeFileSync,
|
|
19
|
+
generateTmpName = tmpdir,
|
|
20
|
+
removeDirectory = rmSync,
|
|
21
|
+
} = overrides;
|
|
22
|
+
|
|
23
|
+
const tmpDir = createTmpDirectory(join(generateTmpName(), 'redlint-'));
|
|
24
|
+
const tmpFile = join(tmpDir, 'edit.tmp');
|
|
25
|
+
|
|
26
|
+
writeFileContent(tmpFile, content);
|
|
27
|
+
|
|
28
|
+
const removeTmpFile = createRemoveTmpFile(tmpDir, removeDirectory);
|
|
29
|
+
|
|
30
|
+
return [tmpFile, removeTmpFile];
|
|
31
|
+
};
|
|
32
|
+
|
package/lib/menu.js
CHANGED
|
@@ -3,6 +3,7 @@ export const SCAN_DEBUG = '🔍 scan: debug';
|
|
|
3
3
|
export const BUNDLE = 'bundle';
|
|
4
4
|
export const BUNDLE_DEBUG = '🧺 bundle';
|
|
5
5
|
export const FIX = '🔨 fix';
|
|
6
|
+
export const EDIT = '🪶 edit';
|
|
6
7
|
export const FIX_DEBUG = '🔨 fix: debug';
|
|
7
8
|
export const PACK = '🔬 pack';
|
|
8
9
|
export const PACK_DEBUG = '🔬 pack: debug';
|
|
@@ -47,6 +48,7 @@ export const isBack = (a) => a === BACK || a === 'back';
|
|
|
47
48
|
export const isExit = (a) => a === EXIT || a === 'exit';
|
|
48
49
|
export const isConvert = (a) => a === CONVERT || a === 'convert';
|
|
49
50
|
export const isRename = (a) => a === RENAME || a === 'rename';
|
|
51
|
+
export const isEdit = (a) => a === EDIT || a === 'edit';
|
|
50
52
|
export const isConvertChosen = (a) => {
|
|
51
53
|
return [
|
|
52
54
|
CONVERT_JSON_TO_JS,
|