redlint 5.2.2 β 5.2.3
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 +2 -2
- package/lib/choose.js +0 -1
- package/lib/debug.js +0 -1
- 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 +20 -11
- package/package.json +1 -1
package/ChangeLog
CHANGED
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
|
@@ -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
|
@@ -7,7 +7,9 @@ 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
9
|
|
|
10
|
-
const
|
|
10
|
+
const createLog = (output) => (a) => {
|
|
11
|
+
output.push(`${a}\n`);
|
|
12
|
+
};
|
|
11
13
|
|
|
12
14
|
const {
|
|
13
15
|
findFile,
|
|
@@ -15,6 +17,9 @@ const {
|
|
|
15
17
|
getFilename,
|
|
16
18
|
} = operator;
|
|
17
19
|
|
|
20
|
+
const SUCCESS = 'π';
|
|
21
|
+
const FAIL = 'π';
|
|
22
|
+
|
|
18
23
|
export const test = (filesystem, overrides = {}) => {
|
|
19
24
|
const {branch = _branch} = overrides;
|
|
20
25
|
|
|
@@ -46,29 +51,33 @@ export const test = (filesystem, overrides = {}) => {
|
|
|
46
51
|
const require = createRequire(filename);
|
|
47
52
|
|
|
48
53
|
const output = ['\n'];
|
|
49
|
-
const log = (
|
|
50
|
-
output.push(`${a}\n`);
|
|
51
|
-
};
|
|
54
|
+
const log = createLog(output);
|
|
52
55
|
|
|
53
|
-
for (const [name, incorrect] of
|
|
54
|
-
const
|
|
56
|
+
for (const [name, [incorrect, correct]] of fixture) {
|
|
57
|
+
const output = run(plugin, {
|
|
55
58
|
require,
|
|
56
59
|
incorrect,
|
|
57
60
|
});
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
const status = correct === output ? SUCCESS : FAIL;
|
|
63
|
+
|
|
64
|
+
log(`# ${status} ${name}`);
|
|
65
|
+
|
|
66
|
+
if (status === SUCCESS)
|
|
67
|
+
continue;
|
|
68
|
+
|
|
69
|
+
log('');
|
|
60
70
|
log(`## β Incorrect code\n`);
|
|
61
|
-
log('```js');
|
|
62
71
|
log(codeFrameColumns(incorrect, {}, {
|
|
63
72
|
highlightCode: true,
|
|
64
73
|
}));
|
|
65
|
-
log('
|
|
74
|
+
log('');
|
|
66
75
|
log(`## β
Correct code\n`);
|
|
67
|
-
|
|
76
|
+
|
|
68
77
|
log(codeFrameColumns(correct, {}, {
|
|
69
78
|
highlightCode: true,
|
|
70
79
|
}));
|
|
71
|
-
log('
|
|
80
|
+
log('');
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
return [null, output.join('')];
|