redlint 5.2.0 → 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 +13 -0
- package/README.md +7 -0
- package/bin/redlint.js +5 -1
- package/lib/choose.js +5 -1
- package/lib/debug.js +5 -1
- package/lib/help/help.js +6 -4
- package/lib/test/init-fixture/index.js +17 -0
- package/lib/test/init-fixture/init-fixture-plugin/index.js +31 -0
- 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 +58 -4
- package/lib/view/view.js +1 -1
- package/package.json +2 -2
package/ChangeLog
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
2026.01.24, v5.2.2
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- aeb6b12 redlint: test: run
|
|
5
|
+
- 9db12a6 redlint: @putout/plugin-nodejs v20.0.0
|
|
6
|
+
- 026f9b7 redlint: test: readFixture: add
|
|
7
|
+
|
|
8
|
+
2026.01.24, v5.2.1
|
|
9
|
+
|
|
10
|
+
feature:
|
|
11
|
+
- 52a7c5f redlint: test: init-fixture: add
|
|
12
|
+
- eac41aa test: no index.spec.js
|
|
13
|
+
|
|
1
14
|
2026.01.23, v5.2.0
|
|
2
15
|
|
|
3
16
|
feature:
|
package/README.md
CHANGED
|
@@ -71,6 +71,13 @@ To add new rule `create-file` located in plugin `custom` for **RedLint** write a
|
|
|
71
71
|
}
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
## Test
|
|
75
|
+
|
|
76
|
+
- ✅ [get fiture names from `index.spec.js`](https://putout.cloudcmd.io/#/gist/558b38ed5e5e662706f1b8a49a0157a1/8e188e99798246263dbf488b86dc250b8dfa1be3).
|
|
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);
|
|
80
|
+
|
|
74
81
|
## License
|
|
75
82
|
|
|
76
83
|
MIT
|
package/bin/redlint.js
CHANGED
|
@@ -149,8 +149,12 @@ async function uiLoop(arg) {
|
|
|
149
149
|
|
|
150
150
|
spinner.succeed();
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
const [error, result] = test(filesystem);
|
|
153
153
|
|
|
154
|
+
if (error)
|
|
155
|
+
return console.error('\n🌴 ' + error.message + '');
|
|
156
|
+
|
|
157
|
+
console.log(result);
|
|
154
158
|
return;
|
|
155
159
|
}
|
|
156
160
|
|
package/lib/choose.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
1
2
|
import {choose as chooseDialog} from '@putout/cli-choose';
|
|
2
3
|
import {
|
|
3
4
|
SCAN,
|
|
@@ -17,6 +18,8 @@ import {
|
|
|
17
18
|
TEST,
|
|
18
19
|
} from './menu.js';
|
|
19
20
|
|
|
21
|
+
const {stdout} = process;
|
|
22
|
+
|
|
20
23
|
export const choose = async () => {
|
|
21
24
|
const command = await chooseDialog('Command:', [
|
|
22
25
|
SCAN,
|
|
@@ -36,7 +39,8 @@ export const choose = async () => {
|
|
|
36
39
|
EXIT,
|
|
37
40
|
]);
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
stdout.write('\n');
|
|
40
43
|
|
|
41
44
|
return command;
|
|
42
45
|
};
|
|
46
|
+
|
package/lib/debug.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
1
2
|
import {choose as chooseDialog} from '@putout/cli-choose';
|
|
2
3
|
import {
|
|
3
4
|
SCAN_DEBUG,
|
|
@@ -11,6 +12,8 @@ import {
|
|
|
11
12
|
BUNDLE_DEBUG,
|
|
12
13
|
} from './menu.js';
|
|
13
14
|
|
|
15
|
+
const {stdout} = process;
|
|
16
|
+
|
|
14
17
|
export const debug = async () => {
|
|
15
18
|
const command = await chooseDialog('Debug:', [
|
|
16
19
|
SCAN_DEBUG,
|
|
@@ -25,7 +28,8 @@ export const debug = async () => {
|
|
|
25
28
|
EXIT,
|
|
26
29
|
]);
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
stdout.write('\n');
|
|
29
32
|
|
|
30
33
|
return command;
|
|
31
34
|
};
|
|
35
|
+
|
package/lib/help/help.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import {logo} from './logo.js';
|
|
3
3
|
|
|
4
|
+
const {stdout} = process;
|
|
5
|
+
|
|
4
6
|
export const help = ({header = true}) => {
|
|
5
7
|
if (header) {
|
|
6
|
-
|
|
8
|
+
stdout.write('Lint your files according to 🐊Putout rules.\n\n');
|
|
7
9
|
process.stdout.write(logo);
|
|
8
|
-
|
|
10
|
+
stdout.write('\n');
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
stdout.write(`Usage: redlint [command]\n`);
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
stdout.write(`Commands:
|
|
14
16
|
scan - scan files according to 🐊Putout rules
|
|
15
17
|
fix - fix files according to 🐊Putout rules
|
|
16
18
|
pack - pack 'filesystem.red' with directory contents
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {transform} from 'putout';
|
|
2
|
+
import * as initFixturePlugin from './init-fixture-plugin/index.js';
|
|
3
|
+
|
|
4
|
+
export const initFixture = (ast, names) => {
|
|
5
|
+
transform(ast, '', {
|
|
6
|
+
rules: {
|
|
7
|
+
'init-fixtures': ['on', {
|
|
8
|
+
names,
|
|
9
|
+
}],
|
|
10
|
+
},
|
|
11
|
+
plugins: [
|
|
12
|
+
['init-fixtures', initFixturePlugin],
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return ast;
|
|
17
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
createDirectory,
|
|
5
|
+
createFile,
|
|
6
|
+
} = operator;
|
|
7
|
+
|
|
8
|
+
export const report = (dir, {name}) => `Init fixture '${name}'`;
|
|
9
|
+
|
|
10
|
+
export const fix = (root, {name}) => {
|
|
11
|
+
const fixtureDir = createDirectory(root, 'fixture');
|
|
12
|
+
|
|
13
|
+
createFile(fixtureDir, name);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const scan = (root, {options, push}) => {
|
|
17
|
+
const {names = []} = options;
|
|
18
|
+
|
|
19
|
+
if (!names.length)
|
|
20
|
+
return;
|
|
21
|
+
|
|
22
|
+
for (const [a, b] of names) {
|
|
23
|
+
push(root, {
|
|
24
|
+
name: a,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
push(root, {
|
|
28
|
+
name: b,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -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,21 +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';
|
|
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;
|
|
4
11
|
|
|
5
12
|
const {
|
|
6
13
|
findFile,
|
|
7
14
|
readFileContent,
|
|
15
|
+
getFilename,
|
|
8
16
|
} = operator;
|
|
9
17
|
|
|
10
18
|
export const test = (filesystem, overrides = {}) => {
|
|
11
19
|
const {branch = _branch} = overrides;
|
|
12
20
|
|
|
13
21
|
const [{source}] = branch(filesystem);
|
|
14
|
-
const
|
|
22
|
+
const ast = parse(source);
|
|
23
|
+
|
|
24
|
+
const [spec] = findFile(ast, 'index.spec.js');
|
|
25
|
+
|
|
26
|
+
if (!spec)
|
|
27
|
+
return [
|
|
28
|
+
Error(`No 'index.spec.js' found`),
|
|
29
|
+
];
|
|
30
|
+
|
|
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);
|
|
39
|
+
const names = getFixtureNames(specContent);
|
|
40
|
+
|
|
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);
|
|
15
47
|
|
|
16
|
-
const
|
|
48
|
+
const output = ['\n'];
|
|
49
|
+
const log = (a) => {
|
|
50
|
+
output.push(`${a}\n`);
|
|
51
|
+
};
|
|
17
52
|
|
|
18
|
-
const
|
|
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
|
+
}
|
|
19
73
|
|
|
20
|
-
return
|
|
74
|
+
return [null, output.join('')];
|
|
21
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",
|