redlint 5.2.1 → 5.2.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 +7 -0
- package/README.md +2 -0
- package/lib/test/init-fixture/index.js +2 -2
- package/lib/test/read-fixture/index.js +42 -0
- package/lib/test/read-fixture/read-fixture-plugin/index.js +28 -0
- package/lib/test/run/run.js +43 -0
- package/lib/test/test.js +51 -6
- package/lib/view/view.js +1 -1
- package/package.json +2 -2
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -75,6 +75,8 @@ To add new rule `create-file` located in plugin `custom` for **RedLint** write a
|
|
|
75
75
|
|
|
76
76
|
- ✅ [get fiture names from `index.spec.js`](https://putout.cloudcmd.io/#/gist/558b38ed5e5e662706f1b8a49a0157a1/8e188e99798246263dbf488b86dc250b8dfa1be3).
|
|
77
77
|
- ✅ [init fixture](https://putout.cloudcmd.io/#/gist/e7614e03b3292a210cfc63265718e955/13ccc3a90a8d9ff28f26474b107c5652928e8d0a);
|
|
78
|
+
- ✅ [read fixture](https://putout.cloudcmd.io/#/gist/f8ab318fa1963508322031483d988ad4/b152c5f796bfab9aa74594c847ddbd1f650efb83);
|
|
79
|
+
- ✅ [run plugin](https://putout.cloudcmd.io/#/gist/8e66e45753dbe9e746c797813eb2723a/9855f9aea57f345492c629c65d9972309d250a91);
|
|
78
80
|
|
|
79
81
|
## License
|
|
80
82
|
|
|
@@ -4,12 +4,12 @@ import * as initFixturePlugin from './init-fixture-plugin/index.js';
|
|
|
4
4
|
export const initFixture = (ast, names) => {
|
|
5
5
|
transform(ast, '', {
|
|
6
6
|
rules: {
|
|
7
|
-
'init-
|
|
7
|
+
'init-fixtures': ['on', {
|
|
8
8
|
names,
|
|
9
9
|
}],
|
|
10
10
|
},
|
|
11
11
|
plugins: [
|
|
12
|
-
['init-
|
|
12
|
+
['init-fixtures', initFixturePlugin],
|
|
13
13
|
],
|
|
14
14
|
});
|
|
15
15
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {basename} from 'node:path';
|
|
2
|
+
import {transform} from 'putout';
|
|
3
|
+
import * as readFixturesPlugin from './read-fixture-plugin/index.js';
|
|
4
|
+
|
|
5
|
+
const {fromEntries} = Object;
|
|
6
|
+
const getMessage = (a) => a.message;
|
|
7
|
+
const SPLITTER = ' -> ';
|
|
8
|
+
|
|
9
|
+
export const readFixture = (ast, names) => {
|
|
10
|
+
const places = transform(ast, '', {
|
|
11
|
+
rules: {
|
|
12
|
+
'read-fixture': ['on', {
|
|
13
|
+
names,
|
|
14
|
+
}],
|
|
15
|
+
},
|
|
16
|
+
plugins: [
|
|
17
|
+
['read-fixture', readFixturesPlugin],
|
|
18
|
+
],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return parseFixtures(places);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const split = (a) => {
|
|
25
|
+
const [name] = a.split(SPLITTER, 1);
|
|
26
|
+
const nameLength = name.length;
|
|
27
|
+
const {length} = SPLITTER;
|
|
28
|
+
const content = a.slice(length + nameLength);
|
|
29
|
+
|
|
30
|
+
return [
|
|
31
|
+
basename(name),
|
|
32
|
+
content,
|
|
33
|
+
];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function parseFixtures(places) {
|
|
37
|
+
const entries = places
|
|
38
|
+
.map(getMessage)
|
|
39
|
+
.map(split);
|
|
40
|
+
|
|
41
|
+
return fromEntries(entries);
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
readDirectory,
|
|
5
|
+
findFile,
|
|
6
|
+
readFileContent,
|
|
7
|
+
getFilename,
|
|
8
|
+
} = operator;
|
|
9
|
+
|
|
10
|
+
export const report = (file) => {
|
|
11
|
+
const name = getFilename(file);
|
|
12
|
+
const content = readFileContent(file);
|
|
13
|
+
|
|
14
|
+
return `${name} -> ${content}`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const fix = () => {};
|
|
18
|
+
|
|
19
|
+
export const scan = (root, {push}) => {
|
|
20
|
+
const [fixture] = findFile(root, 'fixture');
|
|
21
|
+
|
|
22
|
+
if (!fixture)
|
|
23
|
+
return;
|
|
24
|
+
|
|
25
|
+
for (const file of readDirectory(fixture)) {
|
|
26
|
+
push(file);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {putout} from 'putout';
|
|
2
|
+
|
|
3
|
+
const noop = () => {};
|
|
4
|
+
|
|
5
|
+
export const run = (content, options) => {
|
|
6
|
+
const {require = noop, incorrect} = options;
|
|
7
|
+
|
|
8
|
+
if (!incorrect)
|
|
9
|
+
return;
|
|
10
|
+
|
|
11
|
+
const plugin = createPlugin(content, require);
|
|
12
|
+
|
|
13
|
+
return runPlugin(plugin, incorrect);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function runPlugin(plugin, source) {
|
|
17
|
+
const {code} = putout(source, {
|
|
18
|
+
plugins: [
|
|
19
|
+
['run', plugin],
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return code;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function createPlugin(content, require) {
|
|
27
|
+
const {code} = putout(content, {
|
|
28
|
+
plugins: [
|
|
29
|
+
'nodejs/convert-esm-to-commonjs',
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const fn = Function('module, exports, require', code);
|
|
34
|
+
|
|
35
|
+
const exports = {};
|
|
36
|
+
const module = {
|
|
37
|
+
exports,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
fn(module, exports, require);
|
|
41
|
+
|
|
42
|
+
return exports;
|
|
43
|
+
}
|
package/lib/test/test.js
CHANGED
|
@@ -1,30 +1,75 @@
|
|
|
1
|
+
import {createRequire} from 'node:module';
|
|
1
2
|
import {operator, parse} from 'putout';
|
|
2
3
|
import {branch as _branch} from '@putout/processor-filesystem';
|
|
4
|
+
import {codeFrameColumns} from '@putout/babel';
|
|
3
5
|
import {getFixtureNames} from './get-fixture-names/index.js';
|
|
4
6
|
import {initFixture} from './init-fixture/index.js';
|
|
7
|
+
import {readFixture} from './read-fixture/index.js';
|
|
8
|
+
import {run} from './run/run.js';
|
|
9
|
+
|
|
10
|
+
const {entries} = Object;
|
|
5
11
|
|
|
6
12
|
const {
|
|
7
13
|
findFile,
|
|
8
14
|
readFileContent,
|
|
15
|
+
getFilename,
|
|
9
16
|
} = operator;
|
|
10
17
|
|
|
11
18
|
export const test = (filesystem, overrides = {}) => {
|
|
12
19
|
const {branch = _branch} = overrides;
|
|
13
20
|
|
|
14
21
|
const [{source}] = branch(filesystem);
|
|
15
|
-
const
|
|
22
|
+
const ast = parse(source);
|
|
16
23
|
|
|
17
|
-
const [
|
|
24
|
+
const [spec] = findFile(ast, 'index.spec.js');
|
|
18
25
|
|
|
19
|
-
if (!
|
|
26
|
+
if (!spec)
|
|
20
27
|
return [
|
|
21
28
|
Error(`No 'index.spec.js' found`),
|
|
22
29
|
];
|
|
23
30
|
|
|
24
|
-
const
|
|
31
|
+
const [index] = findFile(ast, 'index.js');
|
|
32
|
+
|
|
33
|
+
if (!index)
|
|
34
|
+
return [
|
|
35
|
+
Error(`No 'index.js' found`),
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const specContent = readFileContent(spec);
|
|
25
39
|
const names = getFixtureNames(specContent);
|
|
26
40
|
|
|
27
|
-
initFixture(
|
|
41
|
+
initFixture(ast, names);
|
|
42
|
+
const fixture = readFixture(ast, names);
|
|
43
|
+
|
|
44
|
+
const plugin = readFileContent(index);
|
|
45
|
+
const filename = getFilename(index);
|
|
46
|
+
const require = createRequire(filename);
|
|
47
|
+
|
|
48
|
+
const output = ['\n'];
|
|
49
|
+
const log = (a) => {
|
|
50
|
+
output.push(`${a}\n`);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
for (const [name, incorrect] of entries(fixture)) {
|
|
54
|
+
const correct = run(plugin, {
|
|
55
|
+
require,
|
|
56
|
+
incorrect,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
log(`# ${name}\n`);
|
|
60
|
+
log(`## ❌ Incorrect code\n`);
|
|
61
|
+
log('```js');
|
|
62
|
+
log(codeFrameColumns(incorrect, {}, {
|
|
63
|
+
highlightCode: true,
|
|
64
|
+
}));
|
|
65
|
+
log('```');
|
|
66
|
+
log(`## ✅ Correct code\n`);
|
|
67
|
+
log('```js');
|
|
68
|
+
log(codeFrameColumns(correct, {}, {
|
|
69
|
+
highlightCode: true,
|
|
70
|
+
}));
|
|
71
|
+
log('```\n');
|
|
72
|
+
}
|
|
28
73
|
|
|
29
|
-
return [null,
|
|
74
|
+
return [null, output.join('')];
|
|
30
75
|
};
|
package/lib/view/view.js
CHANGED
|
@@ -17,7 +17,7 @@ export const view = (filename, overrides = {}) => {
|
|
|
17
17
|
for (const [line, nameWithContent] of entries(files)) {
|
|
18
18
|
for (const [name, content] of entries(nameWithContent)) {
|
|
19
19
|
lines.push(codeFrameColumns(dedent(content), {}, {
|
|
20
|
-
|
|
20
|
+
highlightCode: true,
|
|
21
21
|
message: `${name}:${line}`,
|
|
22
22
|
}) + '\n');
|
|
23
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redlint",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Lint Filesystem with 🐊Putout",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@putout/operator-json": "^3.1.0",
|
|
42
42
|
"@putout/plugin-eslint": "^15.0.0",
|
|
43
43
|
"@putout/plugin-filesystem": "^12.0.0",
|
|
44
|
-
"@putout/plugin-nodejs": "^
|
|
44
|
+
"@putout/plugin-nodejs": "^20.0.0",
|
|
45
45
|
"@putout/plugin-react": "^3.0.0",
|
|
46
46
|
"@putout/processor-filesystem": "^7.0.1",
|
|
47
47
|
"chalk": "^5.3.0",
|