redlint 3.2.0 → 3.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 CHANGED
@@ -1,3 +1,13 @@
1
+ 2023.12.21, v3.3.0
2
+
3
+ feature:
4
+ - a5fdd8b redlint: move out run
5
+
6
+ 2023.12.20, v3.2.1
7
+
8
+ fix:
9
+ - 9bb40b8 redlint: help: = -> -
10
+
1
11
  2023.12.20, v3.2.0
2
12
 
3
13
  feature:
package/bin/redlint.js CHANGED
@@ -11,13 +11,13 @@ 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 {lint} from '../lib/lint/lint.js';
21
21
  import {pack} from '../lib/pack/pack.js';
22
22
  import {debug} from '../lib/debug.js';
23
23
 
@@ -122,7 +122,7 @@ async function uiLoop(arg) {
122
122
 
123
123
  if (arg === 'scan:debug') {
124
124
  const places = lint(filesystem, {
125
- fix: true,
125
+ fix: false,
126
126
  });
127
127
 
128
128
  const result = await formatterCodeFrame({
@@ -139,6 +139,25 @@ async function uiLoop(arg) {
139
139
  process.exit(1);
140
140
  }
141
141
 
142
+ if (arg === 'fix:debug') {
143
+ const places = lint(filesystem, {
144
+ fix: true,
145
+ });
146
+
147
+ const result = await formatterCodeFrame({
148
+ name: '.filesystem.json',
149
+ source: filesystem,
150
+ places,
151
+ index: 0,
152
+ count: places.length,
153
+ filesCount: 1,
154
+ errorsCount: places.length,
155
+ });
156
+
157
+ process.stdout.write(result);
158
+ process.exit();
159
+ }
160
+
142
161
  if (arg === 'fix') {
143
162
  await masterLint(filesystem, {
144
163
  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 = (from, 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
+ ['read-all-files', readAllFiles],
36
+ ['replace-cwd', replaceCwd],
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
+ })]);
@@ -18,6 +18,6 @@ export const help = ({header = true}) => {
18
18
  generate - generate .filesystem.json file and exit
19
19
  generate:simple - generate simple .filesystem.json file and exit
20
20
  version - show version and exit
21
- debug = run commands without workers
21
+ debug - run commands without workers
22
22
  `);
23
23
  };
@@ -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
@@ -6,14 +6,18 @@ import {
6
6
  import {createProgress} from '@putout/engine-runner/progress';
7
7
  import * as pluginFilesystem from '@putout/plugin-filesystem';
8
8
  import {
9
- branch,
10
- merge,
9
+ branch as originalBranch,
10
+ merge as originalMerge,
11
11
  } from '@putout/processor-filesystem';
12
12
 
13
13
  const [, readAllFiles] = pluginFilesystem.rules['read-all-files'];
14
14
  const [, replaceCwd] = pluginFilesystem.rules['replace-cwd'];
15
15
 
16
- export const pack = (from, filesystem, {progress = createProgress()} = {}) => {
16
+ export const pack = (from, filesystem, {
17
+ progress = createProgress(),
18
+ branch = originalBranch,
19
+ merge = originalMerge,
20
+ } = {}) => {
17
21
  const [{source}] = branch(filesystem);
18
22
  const ast = parse(source);
19
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,85 +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, 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
- });
15
- }
16
-
17
- function setStart(rule, store) {
18
- const spinner = ora(rule).start();
19
-
20
- spinner.suffixText = '';
21
-
22
- store({
23
- rule,
24
- count: 0,
25
- spinner,
26
- });
27
- }
28
-
29
- function setPush(store) {
30
- const {
31
- rule,
32
- count,
33
- spinner,
34
- } = store();
35
-
36
- store({
37
- rule,
38
- count: count + 1,
39
- spinner,
40
- });
41
- }
42
-
43
- function setFail(store) {
44
- const {
45
- rule,
46
- count,
47
- spinner,
48
- } = store();
49
-
50
- spinner.suffixText = chalk.red(count);
51
- spinner.fail();
52
-
53
- store({
54
- rule,
55
- count,
56
- spinner,
57
- });
58
- }
59
-
60
- function setSuccess(store) {
61
- const {spinner} = store();
62
-
63
- spinner.succeed();
64
- spinner.suffixText = '';
65
-
66
- store({
67
- ...store(),
68
- spinner: null,
69
- });
70
- }
71
-
72
- function setEnd(data, resolve) {
73
- resolve(data);
74
- }
75
-
76
- function run(filesystem, {fix, start, end, push, fail, success}) {
4
+ export function run({workerData, slave, push, fix, start, end, fail, success, suffix}) {
77
5
  return new Promise((resolve, reject) => {
78
- const worker = new Worker(new URL('./slave.js', import.meta.url), {
79
- workerData: {
80
- filesystem,
81
- fix,
82
- },
6
+ const worker = new Worker(slave, {
7
+ workerData,
83
8
  });
84
9
 
85
10
  const store = fullstore({});
@@ -95,6 +20,11 @@ function run(filesystem, {fix, start, end, push, fail, success}) {
95
20
  return;
96
21
  }
97
22
 
23
+ if (event === 'file') {
24
+ suffix(store, data);
25
+ return;
26
+ }
27
+
98
28
  const {
99
29
  rule,
100
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.0",
3
+ "version": "3.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",
@@ -34,6 +34,7 @@
34
34
  "@putout/engine-runner": "^20.1.0",
35
35
  "@putout/formatter-codeframe": "^6.0.0",
36
36
  "@putout/formatter-dump": "^4.0.1",
37
+ "@putout/operator-json": "^1.3.0",
37
38
  "@putout/plugin-filesystem": "^3.6.0",
38
39
  "@putout/processor-filesystem": "^3.0.0",
39
40
  "chalk": "^5.3.0",
File without changes
File without changes