redlint 5.2.2 → 5.3.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 +10 -0
- package/README.md +1 -0
- package/bin/redlint.js +2 -2
- package/lib/choose.js +0 -1
- package/lib/debug.js +0 -1
- package/lib/test/compare-files.js +43 -0
- package/lib/test/get-fixture-names/get-fixture-names-plugin/index.js +16 -5
- package/lib/test/init-fixture/init-fixture-plugin/index.js +11 -6
- package/lib/test/read-fixture/index.js +37 -4
- package/lib/test/test.js +39 -15
- package/package.json +2 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ To add new rule `create-file` located in plugin `custom` for **RedLint** write a
|
|
|
77
77
|
- ✅ [init fixture](https://putout.cloudcmd.io/#/gist/e7614e03b3292a210cfc63265718e955/13ccc3a90a8d9ff28f26474b107c5652928e8d0a);
|
|
78
78
|
- ✅ [read fixture](https://putout.cloudcmd.io/#/gist/f8ab318fa1963508322031483d988ad4/b152c5f796bfab9aa74594c847ddbd1f650efb83);
|
|
79
79
|
- ✅ [run plugin](https://putout.cloudcmd.io/#/gist/8e66e45753dbe9e746c797813eb2723a/9855f9aea57f345492c629c65d9972309d250a91);
|
|
80
|
+
- ✅ [get file name with content](https://putout.cloudcmd.io/#/gist/30721329e845f61c0c6105105bdffbdc);
|
|
80
81
|
|
|
81
82
|
## License
|
|
82
83
|
|
package/bin/redlint.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import {join} from 'node:path';
|
|
4
|
-
import process from 'node:process';
|
|
4
|
+
import process, {stdout} from 'node:process';
|
|
5
5
|
import {readFile, writeFile} from 'node:fs/promises';
|
|
6
6
|
import {lintJSON} from 'putout/lint/json';
|
|
7
7
|
import formatterCodeFrame from '@putout/formatter-codeframe';
|
|
@@ -154,7 +154,7 @@ async function uiLoop(arg) {
|
|
|
154
154
|
if (error)
|
|
155
155
|
return console.error('\n🌴 ' + error.message + '');
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
stdout.write(result);
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
|
package/lib/choose.js
CHANGED
package/lib/debug.js
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {diff} from 'jest-diff';
|
|
2
|
+
import {parseFiles} from '../view/parse-files/index.js';
|
|
3
|
+
|
|
4
|
+
const {entries} = Object;
|
|
5
|
+
|
|
6
|
+
export function compareFiles({transformed, correct}) {
|
|
7
|
+
const output = [];
|
|
8
|
+
|
|
9
|
+
if (!transformed || !correct)
|
|
10
|
+
return output;
|
|
11
|
+
|
|
12
|
+
const outputFiles = parseFiles(transformed);
|
|
13
|
+
const correctFiles = parseFiles(correct);
|
|
14
|
+
|
|
15
|
+
for (const [line, files] of entries(outputFiles)) {
|
|
16
|
+
for (const [name, content] of entries(files)) {
|
|
17
|
+
const correctContent = correctFiles[line][name];
|
|
18
|
+
|
|
19
|
+
if (correctContent === content)
|
|
20
|
+
continue;
|
|
21
|
+
|
|
22
|
+
output.push(`## ${name}:${line}\n\n`);
|
|
23
|
+
output.push(doDiff(
|
|
24
|
+
correctContent,
|
|
25
|
+
content,
|
|
26
|
+
));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return output.join('');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const doDiff = (a, b) => {
|
|
34
|
+
let diffed = diff(a, b);
|
|
35
|
+
|
|
36
|
+
if (diffed.includes('\n'))
|
|
37
|
+
diffed = diffed
|
|
38
|
+
.split('\n')
|
|
39
|
+
.slice(3)
|
|
40
|
+
.join('\n');
|
|
41
|
+
|
|
42
|
+
return diffed;
|
|
43
|
+
};
|
|
@@ -2,12 +2,23 @@ import {operator} from 'putout';
|
|
|
2
2
|
|
|
3
3
|
const {getTemplateValues} = operator;
|
|
4
4
|
const TRANSFORM = 't.transform(__a)';
|
|
5
|
+
const TRANSFORM_COUPLE = 't.transform(__a, __b)';
|
|
5
6
|
|
|
6
|
-
export const report = (path) =>
|
|
7
|
-
const {__a} = getTemplateValues(path, TRANSFORM);
|
|
8
|
-
return __a.value;
|
|
9
|
-
};
|
|
7
|
+
export const report = (path) => parseValue(path);
|
|
10
8
|
|
|
11
9
|
export const fix = () => {};
|
|
12
10
|
|
|
13
|
-
export const include = () => [TRANSFORM];
|
|
11
|
+
export const include = () => [TRANSFORM, TRANSFORM_COUPLE];
|
|
12
|
+
|
|
13
|
+
function parseValue(path) {
|
|
14
|
+
const {length} = path.node.arguments;
|
|
15
|
+
|
|
16
|
+
if (length === 1) {
|
|
17
|
+
const {__a} = getTemplateValues(path, TRANSFORM);
|
|
18
|
+
return __a.value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const {__a} = getTemplateValues(path, TRANSFORM_COUPLE);
|
|
22
|
+
|
|
23
|
+
return __a.value;
|
|
24
|
+
}
|
|
@@ -3,6 +3,7 @@ import {operator} from 'putout';
|
|
|
3
3
|
const {
|
|
4
4
|
createDirectory,
|
|
5
5
|
createFile,
|
|
6
|
+
getFile,
|
|
6
7
|
} = operator;
|
|
7
8
|
|
|
8
9
|
export const report = (dir, {name}) => `Init fixture '${name}'`;
|
|
@@ -19,13 +20,17 @@ export const scan = (root, {options, push}) => {
|
|
|
19
20
|
if (!names.length)
|
|
20
21
|
return;
|
|
21
22
|
|
|
23
|
+
const fixtureDir = getFile(root, 'fixture');
|
|
24
|
+
|
|
22
25
|
for (const [a, b] of names) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
if (!fixtureDir || !getFile(fixtureDir, a))
|
|
27
|
+
push(root, {
|
|
28
|
+
name: a,
|
|
29
|
+
});
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
if (!fixtureDir || !getFile(fixtureDir, b))
|
|
32
|
+
push(root, {
|
|
33
|
+
name: b,
|
|
34
|
+
});
|
|
30
35
|
}
|
|
31
36
|
};
|
|
@@ -2,7 +2,7 @@ import {basename} from 'node:path';
|
|
|
2
2
|
import {transform} from 'putout';
|
|
3
3
|
import * as readFixturesPlugin from './read-fixture-plugin/index.js';
|
|
4
4
|
|
|
5
|
-
const {fromEntries} = Object;
|
|
5
|
+
const {fromEntries, entries} = Object;
|
|
6
6
|
const getMessage = (a) => a.message;
|
|
7
7
|
const SPLITTER = ' -> ';
|
|
8
8
|
|
|
@@ -18,7 +18,9 @@ export const readFixture = (ast, names) => {
|
|
|
18
18
|
],
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const parsedFixtures = parseFixtures(places);
|
|
22
|
+
|
|
23
|
+
return mergeFixtures(parsedFixtures);
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
const split = (a) => {
|
|
@@ -34,9 +36,40 @@ const split = (a) => {
|
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
function parseFixtures(places) {
|
|
37
|
-
const
|
|
39
|
+
const result = places
|
|
38
40
|
.map(getMessage)
|
|
39
41
|
.map(split);
|
|
40
42
|
|
|
41
|
-
return fromEntries(
|
|
43
|
+
return fromEntries(result);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const isFixFileName = (a) => a.endsWith('-fix.js');
|
|
47
|
+
const getNameFix = (a) => a.replace('.js', '-fix.js');
|
|
48
|
+
const cutExtension = (a) => a.replace('.js', '');
|
|
49
|
+
|
|
50
|
+
function mergeFixtures(fixture) {
|
|
51
|
+
const result = new Map();
|
|
52
|
+
const filesFix = new Map();
|
|
53
|
+
const files = new Map();
|
|
54
|
+
const names = new Map();
|
|
55
|
+
|
|
56
|
+
for (const [name, content] of entries(fixture)) {
|
|
57
|
+
if (isFixFileName(name)) {
|
|
58
|
+
filesFix.set(name, content);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
files.set(name, content);
|
|
63
|
+
names.set(name, getNameFix(name));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const [name, content] of files) {
|
|
67
|
+
const nameFix = names.get(name);
|
|
68
|
+
const contentFix = filesFix.get(nameFix);
|
|
69
|
+
const shortName = cutExtension(name);
|
|
70
|
+
|
|
71
|
+
result.set(shortName, [content, contentFix]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return result;
|
|
42
75
|
}
|
package/lib/test/test.js
CHANGED
|
@@ -6,8 +6,11 @@ import {getFixtureNames} from './get-fixture-names/index.js';
|
|
|
6
6
|
import {initFixture} from './init-fixture/index.js';
|
|
7
7
|
import {readFixture} from './read-fixture/index.js';
|
|
8
8
|
import {run} from './run/run.js';
|
|
9
|
+
import {compareFiles} from './compare-files.js';
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
+
const createLog = (output) => (a) => {
|
|
12
|
+
output.push(`${a}\n`);
|
|
13
|
+
};
|
|
11
14
|
|
|
12
15
|
const {
|
|
13
16
|
findFile,
|
|
@@ -15,6 +18,9 @@ const {
|
|
|
15
18
|
getFilename,
|
|
16
19
|
} = operator;
|
|
17
20
|
|
|
21
|
+
const SUCCESS = '🍀';
|
|
22
|
+
const FAIL = '🍄';
|
|
23
|
+
|
|
18
24
|
export const test = (filesystem, overrides = {}) => {
|
|
19
25
|
const {branch = _branch} = overrides;
|
|
20
26
|
|
|
@@ -46,29 +52,47 @@ export const test = (filesystem, overrides = {}) => {
|
|
|
46
52
|
const require = createRequire(filename);
|
|
47
53
|
|
|
48
54
|
const output = ['\n'];
|
|
49
|
-
const log = (
|
|
50
|
-
output.push(`${a}\n`);
|
|
51
|
-
};
|
|
55
|
+
const log = createLog(output);
|
|
52
56
|
|
|
53
|
-
for (const [name, incorrect] of
|
|
54
|
-
const
|
|
57
|
+
for (const [name, [incorrect, correct]] of fixture) {
|
|
58
|
+
const transformed = run(plugin, {
|
|
55
59
|
require,
|
|
56
60
|
incorrect,
|
|
57
61
|
});
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
log(
|
|
62
|
-
|
|
63
|
+
const status = correct === transformed ? SUCCESS : FAIL;
|
|
64
|
+
|
|
65
|
+
log(`# ${status} ${name}`);
|
|
66
|
+
|
|
67
|
+
if (status === SUCCESS)
|
|
68
|
+
continue;
|
|
69
|
+
|
|
70
|
+
const differentFiles = compareFiles({
|
|
71
|
+
correct,
|
|
72
|
+
transformed,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (differentFiles.length) {
|
|
76
|
+
log('');
|
|
77
|
+
log(differentFiles);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!transformed || !correct)
|
|
82
|
+
continue;
|
|
83
|
+
|
|
84
|
+
log('');
|
|
85
|
+
log(`## ✅ Expected\n`);
|
|
86
|
+
|
|
87
|
+
log(codeFrameColumns(correct, {}, {
|
|
63
88
|
highlightCode: true,
|
|
64
89
|
}));
|
|
65
|
-
log('
|
|
66
|
-
log(`##
|
|
67
|
-
log(
|
|
68
|
-
log(codeFrameColumns(correct, {}, {
|
|
90
|
+
log('');
|
|
91
|
+
log(`## ❌ Received\n`);
|
|
92
|
+
log(codeFrameColumns(transformed, {}, {
|
|
69
93
|
highlightCode: true,
|
|
70
94
|
}));
|
|
71
|
-
log('
|
|
95
|
+
log('');
|
|
72
96
|
}
|
|
73
97
|
|
|
74
98
|
return [null, output.join('')];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redlint",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Lint Filesystem with 🐊Putout",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"enquirer": "^2.4.1",
|
|
51
51
|
"fullstore": "^4.0.0",
|
|
52
52
|
"ignore": "^7.0.0",
|
|
53
|
+
"jest-diff": "^30.2.0",
|
|
53
54
|
"obligator": "^3.0.0",
|
|
54
55
|
"ora": "^9.0.0",
|
|
55
56
|
"putout": "^41.2.0",
|