redlint 3.2.1 → 3.4.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 CHANGED
@@ -1,3 +1,13 @@
1
+ 2023.12.21, v3.4.0
2
+
3
+ feature:
4
+ - 1e3d44a extract: add
5
+
6
+ 2023.12.21, v3.3.0
7
+
8
+ feature:
9
+ - a5fdd8b redlint: move out run
10
+
1
11
  2023.12.20, v3.2.1
2
12
 
3
13
  fix:
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  >
14
14
  > **(c) The Book of Kon, PoKon and ZaKon**
15
15
 
16
- ![image](https://github.com/putoutjs/redlint/assets/1573141/09bed270-cbf5-484f-bdd6-dd031ae38703)
16
+ ![image](https://github.com/putoutjs/redlint/assets/1573141/3f239180-a378-48b7-9e68-9cc66e762e2b)
17
17
 
18
18
  What if **Filesystem** was a simple **JSON** file [`.filesystem.json`](https://github.com/putoutjs/redlint/blob/master/.filesystem.json). What if you can transform **JSON** file with 🐊[**Putout**](https://github.com/coderaiser/putout) code transformer and this changes modify **Filesystem**?
19
19
 
@@ -31,7 +31,7 @@ npm i redlint -g
31
31
 
32
32
  You can choose interactively when run `redlint`:
33
33
 
34
- ![image](https://github.com/putoutjs/redlint/assets/1573141/c5d3a231-6caf-4dcb-9410-1d4dda48d9e0)
34
+ ![image](https://github.com/putoutjs/redlint/assets/1573141/32a8e9f0-f073-43e7-a592-3bbc7bf056a4)
35
35
 
36
36
  ## Scan
37
37
 
package/bin/redlint.js CHANGED
@@ -11,14 +11,16 @@ import stripAnsi from 'strip-ansi';
11
11
  import formatterCodeFrame from '@putout/formatter-codeframe';
12
12
  import formatterDump from '@putout/formatter-dump';
13
13
  import ora from 'ora';
14
- import {help} from '../lib/help.js';
14
+ import {help} from '../lib/help/help.js';
15
15
  import {choose} from '../lib/choose.js';
16
16
  import {buildTree} from '../lib/redlint.js';
17
17
  import {convertToSimple} from '../lib/simple.js';
18
- import {masterLint} from '../lib/master.js';
18
+ import {masterLint} from '../lib/lint/master.js';
19
19
  import {masterPack} from '../lib/pack/master.js';
20
- import {lint} from '../lib/lint.js';
20
+ import {masterExtract} from '../lib/extract/master.js';
21
+ import {lint} from '../lib/lint/lint.js';
21
22
  import {pack} from '../lib/pack/pack.js';
23
+ import {extract} from '../lib/extract/extract.js';
22
24
  import {debug} from '../lib/debug.js';
23
25
 
24
26
  const {stringify, parse} = JSON;
@@ -112,6 +114,24 @@ async function uiLoop(arg) {
112
114
  process.exit();
113
115
  }
114
116
 
117
+ if (arg === 'extract') {
118
+ const filesystem = await readFile(join(CWD, 'filesystem.red'), result);
119
+ const result = await masterExtract(CWD, filesystem);
120
+ const spinner = ora(`extract 'filesystem.red'`).start();
121
+
122
+ spinner.succeed();
123
+ process.exit();
124
+ }
125
+
126
+ if (arg === 'extract:debug') {
127
+ const filesystem = await readFile(join(CWD, 'filesystem.red'), result);
128
+ const result = await extract(CWD, filesystem);
129
+ const spinner = ora(`extract 'filesystem.red'`).start();
130
+
131
+ spinner.succeed();
132
+ process.exit();
133
+ }
134
+
115
135
  if (arg === 'pack:debug') {
116
136
  const result = pack(CWD, filesystem);
117
137
  await writeFile(join(CWD, 'filesystem.red'), result);
@@ -122,7 +142,7 @@ async function uiLoop(arg) {
122
142
 
123
143
  if (arg === 'scan:debug') {
124
144
  const places = lint(filesystem, {
125
- fix: true,
145
+ fix: false,
126
146
  });
127
147
 
128
148
  const result = await formatterCodeFrame({
@@ -139,6 +159,25 @@ async function uiLoop(arg) {
139
159
  process.exit(1);
140
160
  }
141
161
 
162
+ if (arg === 'fix:debug') {
163
+ const places = lint(filesystem, {
164
+ fix: true,
165
+ });
166
+
167
+ const result = await formatterCodeFrame({
168
+ name: '.filesystem.json',
169
+ source: filesystem,
170
+ places,
171
+ index: 0,
172
+ count: places.length,
173
+ filesCount: 1,
174
+ errorsCount: places.length,
175
+ });
176
+
177
+ process.stdout.write(result);
178
+ process.exit();
179
+ }
180
+
142
181
  if (arg === 'fix') {
143
182
  await masterLint(filesystem, {
144
183
  fix: true,
package/lib/choose.js CHANGED
@@ -1,4 +1,4 @@
1
- import {logo} from './logo.js';
1
+ import {logo} from './help/logo.js';
2
2
  import process from 'node:process';
3
3
  import {choose as chooseDialog} from '@putout/cli-choose';
4
4
 
@@ -11,6 +11,7 @@ export const choose = async () => {
11
11
  'scan',
12
12
  'fix',
13
13
  'pack',
14
+ 'extract',
14
15
  'generate',
15
16
  'generate:simple',
16
17
  'help',
package/lib/debug.js CHANGED
@@ -3,6 +3,7 @@ import {choose as chooseDialog} from '@putout/cli-choose';
3
3
  export const debug = async () => {
4
4
  const command = await chooseDialog('Debug:', [
5
5
  'scan:debug',
6
+ 'fix:debug',
6
7
  'pack:debug',
7
8
  'back',
8
9
  'exit',
@@ -0,0 +1,43 @@
1
+ import {
2
+ parse,
3
+ transform,
4
+ print,
5
+ } from 'putout';
6
+ import {createProgress} from '@putout/engine-runner/progress';
7
+ import * as pluginFilesystem from '@putout/plugin-filesystem';
8
+ import {
9
+ branch as originalBranch,
10
+ merge as originalMerge,
11
+ } from '@putout/processor-filesystem';
12
+
13
+ const [, readAllFiles] = pluginFilesystem.rules['read-all-files'];
14
+ const [, replaceCwd] = pluginFilesystem.rules['replace-cwd'];
15
+
16
+ export const extract = (to, filesystem, {
17
+ progress = createProgress(),
18
+ branch = originalBranch,
19
+ merge = originalMerge,
20
+ } = {}) => {
21
+ const [{source}] = branch(filesystem);
22
+ const ast = parse(source);
23
+
24
+ transform(ast, filesystem, {
25
+ fix: true,
26
+ fixCount: 1,
27
+ progress,
28
+ rules: {
29
+ 'replace-cwd': ['on', {
30
+ from: '/',
31
+ to,
32
+ }],
33
+ },
34
+ plugins: [
35
+ ['replace-cwd', replaceCwd],
36
+ ['write-all-files', readAllFiles],
37
+ ],
38
+ });
39
+
40
+ const code = print(ast);
41
+
42
+ return merge(filesystem, [code]);
43
+ };
@@ -0,0 +1,29 @@
1
+ import {run} from '../run.js';
2
+ import {
3
+ setStart,
4
+ setEnd,
5
+ setPush,
6
+ setFail,
7
+ setSuccess,
8
+ } from '../spinner.js';
9
+
10
+ export function masterExtract(cwd, filesystem, {
11
+ start = setStart,
12
+ end = setEnd,
13
+ push = setPush,
14
+ fail = setFail,
15
+ success = setSuccess,
16
+ } = {}) {
17
+ const slave = new URL('./slave.js', import.meta.url);
18
+ const fix = true;
19
+
20
+ return run(cwd, filesystem, {
21
+ fix,
22
+ start,
23
+ end,
24
+ push,
25
+ fail,
26
+ success,
27
+ slave,
28
+ });
29
+ }
@@ -0,0 +1,33 @@
1
+ import {
2
+ parentPort,
3
+ workerData,
4
+ } from 'node:worker_threads';
5
+ import {pack} from './pack.js';
6
+ import {createProgress} from '@putout/engine-runner/progress';
7
+
8
+ const {filesystem, cwd} = workerData;
9
+ const progress = createProgress();
10
+
11
+ progress.on('start', ({rule}) => {
12
+ parentPort.postMessage(['rule:start', rule]);
13
+ });
14
+
15
+ progress.on('push', ({rule}) => {
16
+ parentPort.postMessage(['rule:push', rule]);
17
+ });
18
+
19
+ progress.on('end', ({rule}) => {
20
+ parentPort.postMessage(['rule:end', rule]);
21
+ });
22
+
23
+ progress.on('file', ({rule, i, n}) => {
24
+ parentPort.postMessage(['file', {
25
+ i,
26
+ n,
27
+ rule,
28
+ }]);
29
+ });
30
+
31
+ parentPort.postMessage(['end', pack(cwd, filesystem, {
32
+ progress,
33
+ })]);
@@ -10,10 +10,11 @@ export const help = ({header = true}) => {
10
10
 
11
11
  console.log(`Usage: redlint [command]`);
12
12
 
13
- console.log(`Commands:
13
+ process.stdout.write(`Commands:
14
14
  scan - scan files according to 🐊Putout rules
15
15
  fix - fix files according to 🐊Putout rules
16
16
  pack - pack 'filesystem.red' with directory contents
17
+ extract - extract directory contents from 'filesystem.red'
17
18
  help - show help screen and exit
18
19
  generate - generate .filesystem.json file and exit
19
20
  generate:simple - generate simple .filesystem.json file and exit
@@ -0,0 +1,28 @@
1
+ import {run} from '../run.js';
2
+ import {
3
+ setStart,
4
+ setEnd,
5
+ setPush,
6
+ setFail,
7
+ setSuccess,
8
+ } from '../spinner.js';
9
+
10
+ export function masterLint(filesystem, {fix, test, start = setStart, end = setEnd, push = setPush, fail = setFail, success = setSuccess}) {
11
+ const slave = new URL('./slave.js', import.meta.url);
12
+ const workerData = {
13
+ filesystem,
14
+ fix,
15
+ };
16
+
17
+ return run({
18
+ workerData,
19
+ fix,
20
+ start,
21
+ end,
22
+ push,
23
+ fail,
24
+ success,
25
+ test,
26
+ slave,
27
+ });
28
+ }
@@ -6,7 +6,6 @@ import {lint} from './lint.js';
6
6
  import {createProgress} from '@putout/engine-runner/progress';
7
7
 
8
8
  const {fix, filesystem} = workerData;
9
-
10
9
  const progress = createProgress();
11
10
 
12
11
  progress.on('start', ({rule}) => {
@@ -21,6 +20,14 @@ progress.on('end', ({rule}) => {
21
20
  parentPort.postMessage(['rule:end', rule]);
22
21
  });
23
22
 
23
+ progress.on('file', ({rule, i, n}) => {
24
+ parentPort.postMessage(['file', {
25
+ rule,
26
+ i,
27
+ n,
28
+ }]);
29
+ });
30
+
24
31
  parentPort.postMessage(['end', lint(filesystem, {
25
32
  fix,
26
33
  progress,
@@ -1,7 +1,12 @@
1
- import {Worker} from 'node:worker_threads';
2
- import ora from 'ora';
3
- import chalk from 'chalk';
4
- import fullstore from 'fullstore';
1
+ import {run} from '../run.js';
2
+ import {
3
+ setStart,
4
+ setEnd,
5
+ setPush,
6
+ setFail,
7
+ setSuccess,
8
+ setSuffixText,
9
+ } from '../spinner.js';
5
10
 
6
11
  export function masterPack(cwd, filesystem, {
7
12
  start = setStart,
@@ -9,128 +14,23 @@ export function masterPack(cwd, filesystem, {
9
14
  push = setPush,
10
15
  fail = setFail,
11
16
  success = setSuccess,
17
+ suffix = setSuffixText,
12
18
  } = {}) {
13
- return run(cwd, filesystem, {
19
+ const slave = new URL('./slave.js', import.meta.url);
20
+ const workerData = {
21
+ cwd,
22
+ filesystem,
23
+ };
24
+
25
+ return run({
26
+ fix: true,
14
27
  start,
15
28
  end,
16
29
  push,
17
30
  fail,
18
31
  success,
19
- });
20
- }
21
-
22
- function setStart(rule, store) {
23
- const spinner = ora(rule).start();
24
-
25
- spinner.suffixText = '';
26
-
27
- store({
28
- rule,
29
- count: 0,
30
- spinner,
31
- });
32
- }
33
-
34
- function setPush(store) {
35
- const {
36
- rule,
37
- count,
38
- spinner,
39
- } = store();
40
-
41
- store({
42
- rule,
43
- count: count + 1,
44
- spinner,
45
- });
46
- }
47
-
48
- function setFail(store) {
49
- const {
50
- rule,
51
- count,
52
- spinner,
53
- } = store();
54
-
55
- spinner.suffixText = chalk.red(count);
56
- spinner.fail();
57
-
58
- store({
59
- rule,
60
- count,
61
- spinner,
62
- });
63
- }
64
-
65
- function setSuccess(store) {
66
- const {spinner} = store();
67
-
68
- spinner.succeed();
69
- spinner.suffixText = '';
70
-
71
- store({
72
- ...store(),
73
- spinner: null,
74
- });
75
- }
76
-
77
- function setEnd(data, resolve) {
78
- resolve(data);
79
- }
80
-
81
- function run(cwd, filesystem, {start, end, fail, success}) {
82
- return new Promise((resolve, reject) => {
83
- const worker = new Worker(new URL('./slave.js', import.meta.url), {
84
- workerData: {
85
- cwd,
86
- filesystem,
87
- },
88
- });
89
-
90
- const store = fullstore({});
91
-
92
- worker.on('message', ([event, data]) => {
93
- if (event === 'end') {
94
- end(data, resolve);
95
- return;
96
- }
97
-
98
- if (event === 'rule:start') {
99
- start(data, store);
100
- return;
101
- }
102
-
103
- const {
104
- rule,
105
- count,
106
- spinner,
107
- } = store();
108
-
109
- if (!spinner)
110
- return;
111
-
112
- store({
113
- rule,
114
- count,
115
- spinner,
116
- });
117
-
118
- const endFail = count && event === 'rule:end';
119
- const endSuccess = !count && event === 'rule:end';
120
-
121
- if (endFail) {
122
- fail(store);
123
- return;
124
- }
125
-
126
- if (endSuccess) {
127
- success(store);
128
- return;
129
- }
130
- });
131
- worker.on('error', reject);
132
- worker.on('exit', (code) => {
133
- reject(Error(`Worker stopped with exit code ${code}`));
134
- });
32
+ slave,
33
+ workerData,
34
+ suffix,
135
35
  });
136
36
  }
package/lib/pack/pack.js CHANGED
@@ -3,7 +3,6 @@ import {
3
3
  transform,
4
4
  print,
5
5
  } from 'putout';
6
-
7
6
  import {createProgress} from '@putout/engine-runner/progress';
8
7
  import * as pluginFilesystem from '@putout/plugin-filesystem';
9
8
  import {
@@ -14,7 +13,11 @@ import {
14
13
  const [, readAllFiles] = pluginFilesystem.rules['read-all-files'];
15
14
  const [, replaceCwd] = pluginFilesystem.rules['replace-cwd'];
16
15
 
17
- export const pack = (from, filesystem, {progress = createProgress(), branch = originalBranch, merge = originalMerge} = {}) => {
16
+ export const pack = (from, filesystem, {
17
+ progress = createProgress(),
18
+ branch = originalBranch,
19
+ merge = originalMerge,
20
+ } = {}) => {
18
21
  const [{source}] = branch(filesystem);
19
22
  const ast = parse(source);
20
23
 
package/lib/pack/slave.js CHANGED
@@ -20,6 +20,14 @@ progress.on('end', ({rule}) => {
20
20
  parentPort.postMessage(['rule:end', rule]);
21
21
  });
22
22
 
23
+ progress.on('file', ({rule, i, n}) => {
24
+ parentPort.postMessage(['file', {
25
+ i,
26
+ n,
27
+ rule,
28
+ }]);
29
+ });
30
+
23
31
  parentPort.postMessage(['end', pack(cwd, filesystem, {
24
32
  progress,
25
33
  })]);
@@ -1,87 +1,10 @@
1
1
  import {Worker} from 'node:worker_threads';
2
- import ora from 'ora';
3
- import chalk from 'chalk';
4
2
  import fullstore from 'fullstore';
5
3
 
6
- export function masterLint(filesystem, {fix, test, start = setStart, end = setEnd, push = setPush, fail = setFail, success = setSuccess}) {
7
- return run(filesystem, {
8
- fix,
9
- start,
10
- end,
11
- push,
12
- fail,
13
- success,
14
- test,
15
- });
16
- }
17
-
18
- function setStart(rule, store) {
19
- const spinner = ora(rule).start();
20
-
21
- spinner.suffixText = '';
22
-
23
- store({
24
- rule,
25
- count: 0,
26
- spinner,
27
- });
28
- }
29
-
30
- function setPush(store) {
31
- const {
32
- rule,
33
- count,
34
- spinner,
35
- } = store();
36
-
37
- store({
38
- rule,
39
- count: count + 1,
40
- spinner,
41
- });
42
- }
43
-
44
- function setFail(store) {
45
- const {
46
- rule,
47
- count,
48
- spinner,
49
- } = store();
50
-
51
- spinner.suffixText = chalk.red(count);
52
- spinner.fail();
53
-
54
- store({
55
- rule,
56
- count,
57
- spinner,
58
- });
59
- }
60
-
61
- function setSuccess(store) {
62
- const {spinner} = store();
63
-
64
- spinner.succeed();
65
- spinner.suffixText = '';
66
-
67
- store({
68
- ...store(),
69
- spinner: null,
70
- });
71
- }
72
-
73
- function setEnd(data, resolve) {
74
- resolve(data);
75
- }
76
-
77
- function run(filesystem, {fix, start, end, push, fail, success, test}) {
4
+ export function run({workerData, slave, push, fix, start, end, fail, success, suffix}) {
78
5
  return new Promise((resolve, reject) => {
79
- const worker = new Worker(new URL('./slave.js', import.meta.url), {
80
- workerData: {
81
- filesystem,
82
- fix,
83
- test,
84
- },
6
+ const worker = new Worker(slave, {
7
+ workerData,
85
8
  });
86
9
 
87
10
  const store = fullstore({});
@@ -92,14 +15,16 @@ function run(filesystem, {fix, start, end, push, fail, success, test}) {
92
15
  return;
93
16
  }
94
17
 
95
- if (test)
96
- return;
97
-
98
18
  if (event === 'rule:start') {
99
19
  start(data, store);
100
20
  return;
101
21
  }
102
22
 
23
+ if (event === 'file') {
24
+ suffix(store, data);
25
+ return;
26
+ }
27
+
103
28
  const {
104
29
  rule,
105
30
  count,
package/lib/spinner.js ADDED
@@ -0,0 +1,67 @@
1
+ import ora from 'ora';
2
+ import chalk from 'chalk';
3
+
4
+ export function setStart(rule, store) {
5
+ const spinner = ora(rule).start();
6
+
7
+ spinner.suffixText = '';
8
+
9
+ store({
10
+ rule,
11
+ count: 0,
12
+ spinner,
13
+ });
14
+ }
15
+
16
+ export function setPush(store) {
17
+ const {
18
+ rule,
19
+ count,
20
+ spinner,
21
+ } = store();
22
+
23
+ store({
24
+ rule,
25
+ count: count + 1,
26
+ spinner,
27
+ });
28
+ }
29
+
30
+ export function setFail(store) {
31
+ const {
32
+ rule,
33
+ count,
34
+ spinner,
35
+ } = store();
36
+
37
+ spinner.suffixText = chalk.red(count);
38
+ spinner.fail();
39
+
40
+ store({
41
+ rule,
42
+ count,
43
+ spinner,
44
+ });
45
+ }
46
+
47
+ export function setSuffixText(store, {percent}) {
48
+ const {spinner} = store();
49
+
50
+ spinner.suffixText = percent;
51
+ }
52
+
53
+ export function setSuccess(store) {
54
+ const {spinner} = store();
55
+
56
+ spinner.succeed();
57
+ spinner.suffixText = '';
58
+
59
+ store({
60
+ ...store(),
61
+ spinner: null,
62
+ });
63
+ }
64
+
65
+ export function setEnd(data, resolve) {
66
+ resolve(data);
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redlint",
3
- "version": "3.2.1",
3
+ "version": "3.4.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Lint Filesystem with 🐊Putout",
File without changes
File without changes