redlint 6.5.2 → 6.7.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/CONTRIBUTING.md +274 -0
- package/ChangeLog +13 -1
- package/README.md +1 -0
- package/bin/redlint.js +6 -0
- package/lib/convert/converters/convert-js-to-json.js +14 -0
- package/lib/convert/converters/convert-json-to-js.js +14 -0
- package/lib/convert/converters/convert-json-to-yaml.js +14 -0
- package/lib/convert/converters/convert-rc-to-flat.js +12 -0
- package/lib/convert/converters/convert-yaml-to-json.js +14 -0
- package/lib/convert/create-options.js +29 -41
- package/lib/convert/index.js +4 -0
- package/lib/debug.js +4 -0
- package/lib/menu.js +44 -3
- package/package.json +3 -1
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Contributing to RedLint
|
|
2
|
+
|
|
3
|
+
## Quick Reference
|
|
4
|
+
|
|
5
|
+
- **No unused variables or imports** — clean them up before committing.
|
|
6
|
+
- **No `t.pass('everything ok')` in tests** — every assertion must test something meaningful.
|
|
7
|
+
- **100% coverage required** — checked via [`.nycrc.json`](.nycrc.json). Run `redrun coverage` to verify.
|
|
8
|
+
- **Tests use [supertape](https://github.com/coderaiser/supertape)** with `stub()` for mocking.
|
|
9
|
+
- **TDD is encouraged** — write a failing test first, then implement, then `redrun fix:lint coverage`.
|
|
10
|
+
- **Run `redrun fix:lint coverage` before every commit** — linter must be clean, all tests green, coverage 100%.
|
|
11
|
+
|
|
12
|
+
## Table of Contents
|
|
13
|
+
|
|
14
|
+
- [Do / Don't](#do--dont)
|
|
15
|
+
- [Workflow](#workflow)
|
|
16
|
+
- [Architecture](#architecture)
|
|
17
|
+
- [How to add a new converter](#how-to-add-a-new-converter)
|
|
18
|
+
- [Import Map](#import-map)
|
|
19
|
+
- [File Tree](#file-tree)
|
|
20
|
+
- [Overrides Pattern](#overrides-pattern)
|
|
21
|
+
- [Tools we use](#tools-we-use)
|
|
22
|
+
|
|
23
|
+
## Do / Don't
|
|
24
|
+
|
|
25
|
+
| Do | Don't |
|
|
26
|
+
|--------------------------------------------------|------------------------------------------------|
|
|
27
|
+
| Write one assertion per test | Use `t.pass('ok')` or `t.comment()` |
|
|
28
|
+
| Use descriptive test names | Use vague names like `'test1'` |
|
|
29
|
+
| Inject deps via `overrides` | Import real modules inline (hard to stub) |
|
|
30
|
+
| Use early returns to flatten logic | Nest deeply with `if/else` chains |
|
|
31
|
+
| Keep modules small, one concern per file | Put multiple operations in one file |
|
|
32
|
+
| Use `async` for tests that `await` | Forget `await` in async test functions |
|
|
33
|
+
| Run `redrun fix:lint coverage` before commit | Commit red linter output |
|
|
34
|
+
|
|
35
|
+
## Workflow
|
|
36
|
+
|
|
37
|
+
Install [`redrun`](https://github.com/coderaiser/redrun) (faster than `npm run`):
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
bun i redrun -g
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Every commit should pass:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
redrun fix:lint # runs putout . --fix
|
|
47
|
+
redrun test # runs all .spec.js tests
|
|
48
|
+
redrun coverage # run coverage (aim for 100%):
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Architecture
|
|
52
|
+
|
|
53
|
+
### Worker / Direct Pattern
|
|
54
|
+
|
|
55
|
+
Each filesystem operation (`scan`, `fix`, `pack`, `extract`, `convert`) has two paths:
|
|
56
|
+
|
|
57
|
+
| Mode | Function | Thread |
|
|
58
|
+
|------------|-----------------------------------------|----------------|
|
|
59
|
+
| **Normal** | `master*()` + `slave.js` | Web Worker |
|
|
60
|
+
| **Debug** | Direct import (e.g. `lint()`, `convert()`) | Main thread |
|
|
61
|
+
|
|
62
|
+
The debug mode is an escape hatch when workers misbehave.
|
|
63
|
+
|
|
64
|
+
### Module layout
|
|
65
|
+
|
|
66
|
+
- `lib/<operation>/master.js` — spawns a worker, returns a promise.
|
|
67
|
+
- `lib/<operation>/slave.js` — runs inside the worker, calls the real logic.
|
|
68
|
+
- `lib/<operation>/<operation>.js` — the actual implementation (imported by slave and tests).
|
|
69
|
+
- `lib/<operation>/<operation>.spec.js` — tests.
|
|
70
|
+
- `lib/<operation>/fixture/` — test fixtures.
|
|
71
|
+
|
|
72
|
+
### Testing
|
|
73
|
+
|
|
74
|
+
- Framework: [supertape](https://github.com/coderaiser/supertape)
|
|
75
|
+
- Mocking: `stub()` from supertape (no external mocking library)
|
|
76
|
+
- Fixtures: plain `.js` files in `fixture/` directories
|
|
77
|
+
|
|
78
|
+
## How to add a new converter (e.g. `convert-json-to-yaml`)?
|
|
79
|
+
|
|
80
|
+
All converters live in `lib/convert/converters/` and follow the same pattern. Adding a new one requires changes in **6 files** (1 new, 5 modified):
|
|
81
|
+
|
|
82
|
+
### 1. Create the converter — `lib/convert/converters/convert-X-to-Y.js`
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
import * as pluginFilesystem from '@putout/plugin-filesystem';
|
|
86
|
+
|
|
87
|
+
const [, pluginConvertXToY] = pluginFilesystem.rules['convert-X-to-Y'];
|
|
88
|
+
|
|
89
|
+
export const convertXToY = (filename) => ({
|
|
90
|
+
rules: {
|
|
91
|
+
'filesystem/convert-X-to-Y': ['on', {
|
|
92
|
+
filename,
|
|
93
|
+
}],
|
|
94
|
+
},
|
|
95
|
+
plugins: [
|
|
96
|
+
['filesystem/convert-X-to-Y', pluginConvertXToY],
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The `[@putout/plugin-filesystem](https://github.com/coderaiser/putout/tree/master/packages/plugin-filesystem)`
|
|
102
|
+
package must already export the rule (use `[@putout/plugin-filesystem](https://github.com/coderaiser/putout/tree/master/packages/plugin-filesystem)` >= 13.2.0 for `convert-json-to-yaml`).
|
|
103
|
+
|
|
104
|
+
### 2. Register menu constants — `lib/menu.js`
|
|
105
|
+
|
|
106
|
+
Add a pair of exports (normal + debug):
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
export const CONVERT_X_TO_Y = '🦏 convert x to y';
|
|
110
|
+
export const CONVERT_X_TO_Y_DEBUG = '🦏 convert x to y: debug';
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Then add `CONVERT_X_TO_Y` to the array in `isConvertChosen()` and `CONVERT_X_TO_Y_DEBUG` to the array in `isConvertChosenDebug()`.
|
|
114
|
+
|
|
115
|
+
### 3. Add to converters map — `lib/convert/create-options.js`
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import {convertXToY} from './converters/convert-X-to-Y.js';
|
|
119
|
+
|
|
120
|
+
const CONVERTERS = {
|
|
121
|
+
// ...existing...
|
|
122
|
+
[CONVERT_X_TO_Y]: convertXToY,
|
|
123
|
+
[CONVERT_X_TO_Y_DEBUG]: convertXToY,
|
|
124
|
+
};
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 4. Add to convert menu — `lib/convert/index.js`
|
|
128
|
+
|
|
129
|
+
Import `CONVERT_X_TO_Y` and add it to the `chooseConvert()` dialog array.
|
|
130
|
+
|
|
131
|
+
### 5. Add to debug menu — `lib/debug.js`
|
|
132
|
+
|
|
133
|
+
Import `CONVERT_X_TO_Y_DEBUG` and add it to the `debug()` dialog array.
|
|
134
|
+
|
|
135
|
+
### 6. Add a test — `lib/convert/convert.spec.js`
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import {CONVERT_X_TO_Y} from '../menu.js';
|
|
139
|
+
|
|
140
|
+
test('redlint: convert: x to y', (t) => {
|
|
141
|
+
const filesystem = stringify([
|
|
142
|
+
'/hello/world/',
|
|
143
|
+
'/hello/world/file.x',
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
const converted = convert('file.x', CONVERT_X_TO_Y, filesystem, {
|
|
147
|
+
merge,
|
|
148
|
+
branch,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const result = parse(converted);
|
|
152
|
+
|
|
153
|
+
const expected = ['/hello/world/', [
|
|
154
|
+
'/hello/world/file.y',
|
|
155
|
+
'e30K',
|
|
156
|
+
]];
|
|
157
|
+
|
|
158
|
+
t.deepEqual(result, expected);
|
|
159
|
+
t.end();
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 🧪 Verify
|
|
164
|
+
|
|
165
|
+
```sh
|
|
166
|
+
redrun fix:lint # putout . --fix — must pass
|
|
167
|
+
redrun coverage # 100% required
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Import Map
|
|
171
|
+
|
|
172
|
+
The project uses Node.js [`imports`](package.json) for internal aliases:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"imports": {
|
|
177
|
+
"#edit": "./lib/edit/edit.js",
|
|
178
|
+
"#test": "./test/create-test.js"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Used in `bin/redlint.js`:
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
import {edit, editHelp} from '#edit';
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## File Tree
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
redlint/
|
|
193
|
+
├── bin/redlint.js # CLI entry point
|
|
194
|
+
├── lib/
|
|
195
|
+
│ ├── convert/ # convert json↔js, rc→flat
|
|
196
|
+
│ ├── edit/ # interactive filesystem editing
|
|
197
|
+
│ ├── extract/ # unpack filesystem.red
|
|
198
|
+
│ ├── help/ # --help output
|
|
199
|
+
│ ├── lint/ # scan & fix filesystem
|
|
200
|
+
│ ├── pack/ # pack to filesystem.red
|
|
201
|
+
│ ├── rename/ # rename js↔jsx
|
|
202
|
+
│ ├── test/ # test runner & plugins
|
|
203
|
+
│ ├── view/ # view file contents
|
|
204
|
+
│ ├── cli/ # version
|
|
205
|
+
│ ├── choose.js # interactive menu
|
|
206
|
+
│ ├── debug.js # debug menu
|
|
207
|
+
│ ├── dialog.js # ask for filename
|
|
208
|
+
│ ├── menu.js # menu constants & predicates
|
|
209
|
+
│ ├── redlint.js # buildTree
|
|
210
|
+
│ ├── run.js # worker runner
|
|
211
|
+
│ ├── simple.js # simple filesystem format
|
|
212
|
+
│ ├── slave.js # worker helper
|
|
213
|
+
│ └── spinner.js # CLI spinner
|
|
214
|
+
├── test/ # integration tests
|
|
215
|
+
├── .nycrc.json # coverage config (100% required)
|
|
216
|
+
├── .madrun.js # task runner scripts
|
|
217
|
+
├── .putout.json # putout rules
|
|
218
|
+
└── package.json
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Overrides Pattern
|
|
222
|
+
|
|
223
|
+
When a module calls external dependencies, accept them as optional overrides so tests can inject stubs:
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
// run-convert.js
|
|
227
|
+
export const runConvert = async (arg, filesystem, overrides = {}) => {
|
|
228
|
+
const {
|
|
229
|
+
askFilename: getFilename = askFilename,
|
|
230
|
+
convert = masterConvert,
|
|
231
|
+
isRCToFlat = isConvertRCToFlat,
|
|
232
|
+
} = overrides;
|
|
233
|
+
|
|
234
|
+
let filename = '.eslintrc.json';
|
|
235
|
+
|
|
236
|
+
if (!isRCToFlat(arg))
|
|
237
|
+
filename = await getFilename();
|
|
238
|
+
|
|
239
|
+
if (filename)
|
|
240
|
+
return await convert(filename, arg, filesystem);
|
|
241
|
+
};
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Test injects stubs to verify behavior without side effects:
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
// run-convert.spec.js
|
|
248
|
+
test('redlint: run-convert: json to js: called with filename', async (t) => {
|
|
249
|
+
const convert = stub();
|
|
250
|
+
const askFilename = stub().returns('package.json');
|
|
251
|
+
const filesystem = '[]';
|
|
252
|
+
|
|
253
|
+
await runConvert(CONVERT_JSON_TO_JS, filesystem, {
|
|
254
|
+
askFilename,
|
|
255
|
+
convert,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
t.calledWith(convert, ['package.json', CONVERT_JSON_TO_JS, filesystem]);
|
|
259
|
+
t.end();
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
This pattern keeps functions pure, easy to unit test, and doesn't require any mocking framework.
|
|
264
|
+
|
|
265
|
+
## Tools we use
|
|
266
|
+
|
|
267
|
+
| Tool | Purpose | Link |
|
|
268
|
+
|-------------------------------------------------------|------------------------------------------------------|----------------------|
|
|
269
|
+
| [redrun](https://github.com/coderaiser/redrun) | Fast task runner (replaces `npm run`) | `bun i redrun -g` |
|
|
270
|
+
| [madrun](https://github.com/coderaiser/madrun) | Define tasks in `.madrun.js` | `redrun` |
|
|
271
|
+
| [putout](https://github.com/coderaiser/putout) | JavaScript code transformer & linter | `redrun fix:lint` |
|
|
272
|
+
| [supertape](https://github.com/coderaiser/supertape) | Test framework with built-in `stub()` | `redrun test` |
|
|
273
|
+
| [superc8](https://github.com/coderaiser/superc8) | coverage tool, drop-in modern `c8` replacement | `redrun coverage` |
|
|
274
|
+
| [nodemon](https://github.com/remy/nodemon) | Watch mode for tests | `redrun watch:test` |
|
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2026.06.07, v6.7.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 32a0dfc redlint: isKnownCommand: add
|
|
5
|
+
- 68d1431 redlint: convert-json-to-yaml
|
|
6
|
+
|
|
7
|
+
2026.06.06, v6.6.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 842206b convert: move out
|
|
11
|
+
- eb2885e convert yaml to json: add
|
|
12
|
+
|
|
1
13
|
2026.06.05, v6.5.2
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -495,7 +507,7 @@ feature:
|
|
|
495
507
|
2024.02.02, v3.11.1
|
|
496
508
|
|
|
497
509
|
fix:
|
|
498
|
-
- 779bf51
|
|
510
|
+
- 779bf51 isConvertJSToJson
|
|
499
511
|
|
|
500
512
|
feature:
|
|
501
513
|
- 6edb2f7 redlint: @putout/plugin-filesystem v4.0.0
|
package/README.md
CHANGED
|
@@ -45,6 +45,7 @@ To scan your files use `redlint scan`:
|
|
|
45
45
|
- ✅ [`package-json/find-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-package-json#find-file);
|
|
46
46
|
- ✅ [`package-json/remove-exports-with-missing-files`](https://github.com/coderaiser/putout/tree/master/packages/plugin-package-json#remove-exports-with-missing-files);
|
|
47
47
|
- ✅ [`esm/resolve-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#resolve-imported-file);
|
|
48
|
+
- ✅ [`esm/resolve-imported-file-with-extension`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#resolve-imported-file-with-extension);
|
|
48
49
|
- ✅ [`esm/shorten-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#shorten-imported-file);
|
|
49
50
|
- ✅ [`esm/apply-name-to-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#apply-name-to-imported-file);
|
|
50
51
|
- ✅ [`esm/apply-namespace-to-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#apply-name-to-imported-file);
|
package/bin/redlint.js
CHANGED
|
@@ -57,6 +57,7 @@ import {
|
|
|
57
57
|
isBundleDebug,
|
|
58
58
|
isEdit,
|
|
59
59
|
isView,
|
|
60
|
+
isKnownCommand,
|
|
60
61
|
VIEW,
|
|
61
62
|
TEST,
|
|
62
63
|
isTest,
|
|
@@ -120,6 +121,11 @@ async function uiLoop(arg) {
|
|
|
120
121
|
if (!arg)
|
|
121
122
|
return;
|
|
122
123
|
|
|
124
|
+
if (!isKnownCommand(arg)) {
|
|
125
|
+
console.error(`'${arg}' is not a redlint command. See 'redlint --help'.`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
|
|
123
129
|
log('Running:');
|
|
124
130
|
const spinner = ora('index filesystem').start();
|
|
125
131
|
const CWD = process.cwd();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as pluginFilesystem from '@putout/plugin-filesystem';
|
|
2
|
+
|
|
3
|
+
const [, pluginConvertJsToJson] = pluginFilesystem.rules['convert-js-to-json'];
|
|
4
|
+
|
|
5
|
+
export const convertJSToJson = (filename) => ({
|
|
6
|
+
rules: {
|
|
7
|
+
'filesystem/convert-js-to-json': ['on', {
|
|
8
|
+
filename,
|
|
9
|
+
}],
|
|
10
|
+
},
|
|
11
|
+
plugins: [
|
|
12
|
+
['filesystem/convert-js-to-json', pluginConvertJsToJson],
|
|
13
|
+
],
|
|
14
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as pluginFilesystem from '@putout/plugin-filesystem';
|
|
2
|
+
|
|
3
|
+
const [, pluginConvertJsonToJs] = pluginFilesystem.rules['convert-json-to-js'];
|
|
4
|
+
|
|
5
|
+
export const convertJsonToJs = (filename) => ({
|
|
6
|
+
rules: {
|
|
7
|
+
'filesystem/convert-json-to-js': ['on', {
|
|
8
|
+
filename,
|
|
9
|
+
}],
|
|
10
|
+
},
|
|
11
|
+
plugins: [
|
|
12
|
+
['filesystem/convert-json-to-js', pluginConvertJsonToJs],
|
|
13
|
+
],
|
|
14
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as pluginFilesystem from '@putout/plugin-filesystem';
|
|
2
|
+
|
|
3
|
+
const [, pluginConvertJsonToYaml] = pluginFilesystem.rules['convert-json-to-yaml'];
|
|
4
|
+
|
|
5
|
+
export const convertJsonToYaml = (filename) => ({
|
|
6
|
+
rules: {
|
|
7
|
+
'filesystem/convert-json-to-yaml': ['on', {
|
|
8
|
+
filename,
|
|
9
|
+
}],
|
|
10
|
+
},
|
|
11
|
+
plugins: [
|
|
12
|
+
['filesystem/convert-json-to-yaml', pluginConvertJsonToYaml],
|
|
13
|
+
],
|
|
14
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as pluginESLint from '@putout/plugin-eslint';
|
|
2
|
+
|
|
3
|
+
const [, pluginConvertRCToFlat] = pluginESLint.rules['convert-rc-to-flat'];
|
|
4
|
+
|
|
5
|
+
export const convertRCToFlat = () => ({
|
|
6
|
+
rules: {
|
|
7
|
+
'eslint/convert-rc-to-flat': 'on',
|
|
8
|
+
},
|
|
9
|
+
plugins: [
|
|
10
|
+
['eslint/convert-rc-to-flat', pluginConvertRCToFlat],
|
|
11
|
+
],
|
|
12
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as pluginFilesystem from '@putout/plugin-filesystem';
|
|
2
|
+
|
|
3
|
+
const [, pluginConvertYamlToJson] = pluginFilesystem.rules['convert-yaml-to-json'];
|
|
4
|
+
|
|
5
|
+
export const convertYamlToJson = (filename) => ({
|
|
6
|
+
rules: {
|
|
7
|
+
'filesystem/convert-yaml-to-json': ['on', {
|
|
8
|
+
filename,
|
|
9
|
+
}],
|
|
10
|
+
},
|
|
11
|
+
plugins: [
|
|
12
|
+
['filesystem/convert-yaml-to-json', pluginConvertYamlToJson],
|
|
13
|
+
],
|
|
14
|
+
});
|
|
@@ -1,49 +1,37 @@
|
|
|
1
|
-
import * as pluginFilesystem from '@putout/plugin-filesystem';
|
|
2
|
-
import * as pluginESLint from '@putout/plugin-eslint';
|
|
3
1
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
CONVERT_JS_TO_JSON,
|
|
3
|
+
CONVERT_JSON_TO_JS,
|
|
4
|
+
CONVERT_JSON_TO_JS_DEBUG,
|
|
5
|
+
CONVERT_JS_TO_JSON_DEBUG,
|
|
6
|
+
CONVERT_YAML_TO_JSON,
|
|
7
|
+
CONVERT_YAML_TO_JSON_DEBUG,
|
|
8
|
+
CONVERT_JSON_TO_YAML,
|
|
9
|
+
CONVERT_JSON_TO_YAML_DEBUG,
|
|
10
|
+
CONVERT_RC_TO_FLAT,
|
|
7
11
|
} from '../menu.js';
|
|
12
|
+
import {convertYamlToJson} from './converters/convert-yaml-to-json.js';
|
|
13
|
+
import {convertJsonToYaml} from './converters/convert-json-to-yaml.js';
|
|
14
|
+
import {convertJsonToJs} from './converters/convert-json-to-js.js';
|
|
15
|
+
import {convertJSToJson} from './converters/convert-js-to-json.js';
|
|
16
|
+
import {convertRCToFlat} from './converters/convert-rc-to-flat.js';
|
|
8
17
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
const CONVERTERS = {
|
|
19
|
+
[CONVERT_JSON_TO_JS]: convertJsonToJs,
|
|
20
|
+
[CONVERT_JSON_TO_JS_DEBUG]: convertJsonToJs,
|
|
21
|
+
[CONVERT_JS_TO_JSON]: convertJSToJson,
|
|
22
|
+
[CONVERT_JS_TO_JSON_DEBUG]: convertJSToJson,
|
|
23
|
+
[CONVERT_YAML_TO_JSON]: convertYamlToJson,
|
|
24
|
+
[CONVERT_YAML_TO_JSON_DEBUG]: convertYamlToJson,
|
|
25
|
+
[CONVERT_JSON_TO_YAML]: convertJsonToYaml,
|
|
26
|
+
[CONVERT_JSON_TO_YAML_DEBUG]: convertJsonToYaml,
|
|
27
|
+
[CONVERT_RC_TO_FLAT]: convertRCToFlat,
|
|
28
|
+
};
|
|
12
29
|
|
|
13
30
|
export const createOptions = (filename, type) => {
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
rules: {
|
|
17
|
-
'filesystem/convert-json-to-js': ['on', {
|
|
18
|
-
filename,
|
|
19
|
-
}],
|
|
20
|
-
},
|
|
21
|
-
plugins: [
|
|
22
|
-
['filesystem/convert-json-to-js', pluginConvertJsonToJs],
|
|
23
|
-
],
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
if (isConvertToJson(type))
|
|
27
|
-
return {
|
|
28
|
-
rules: {
|
|
29
|
-
'filesystem/convert-js-to-json': ['on', {
|
|
30
|
-
filename,
|
|
31
|
-
}],
|
|
32
|
-
},
|
|
33
|
-
plugins: [
|
|
34
|
-
['filesystem/convert-js-to-json', pluginConvertJsToJson],
|
|
35
|
-
],
|
|
36
|
-
};
|
|
31
|
+
const converter = CONVERTERS[type];
|
|
37
32
|
|
|
38
|
-
if (
|
|
39
|
-
return {
|
|
40
|
-
rules: {
|
|
41
|
-
'eslint/convert-rc-to-flat': 'on',
|
|
42
|
-
},
|
|
43
|
-
plugins: [
|
|
44
|
-
['eslint/convert-rc-to-flat', convertRCToFlat],
|
|
45
|
-
],
|
|
46
|
-
};
|
|
33
|
+
if (!converter)
|
|
34
|
+
return {};
|
|
47
35
|
|
|
48
|
-
return
|
|
36
|
+
return converter(filename);
|
|
49
37
|
};
|
package/lib/convert/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
BACK,
|
|
6
6
|
EXIT,
|
|
7
7
|
CONVERT_RC_TO_FLAT,
|
|
8
|
+
CONVERT_YAML_TO_JSON,
|
|
9
|
+
CONVERT_JSON_TO_YAML,
|
|
8
10
|
} from '../menu.js';
|
|
9
11
|
|
|
10
12
|
export * from './convert.js';
|
|
@@ -12,6 +14,8 @@ export const chooseConvert = async () => {
|
|
|
12
14
|
const command = await chooseDialog('Convert:', [
|
|
13
15
|
CONVERT_JS_TO_JSON,
|
|
14
16
|
CONVERT_JSON_TO_JS,
|
|
17
|
+
CONVERT_YAML_TO_JSON,
|
|
18
|
+
CONVERT_JSON_TO_YAML,
|
|
15
19
|
CONVERT_RC_TO_FLAT,
|
|
16
20
|
BACK,
|
|
17
21
|
EXIT,
|
package/lib/debug.js
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
FIX_DEBUG,
|
|
7
7
|
CONVERT_JS_TO_JSON_DEBUG,
|
|
8
8
|
CONVERT_JSON_TO_JS_DEBUG,
|
|
9
|
+
CONVERT_YAML_TO_JSON_DEBUG,
|
|
10
|
+
CONVERT_JSON_TO_YAML_DEBUG,
|
|
9
11
|
RENAME_JS_TO_JSX_DEBUG,
|
|
10
12
|
BACK,
|
|
11
13
|
EXIT,
|
|
@@ -21,6 +23,8 @@ export const debug = async () => {
|
|
|
21
23
|
PACK_DEBUG,
|
|
22
24
|
CONVERT_JS_TO_JSON_DEBUG,
|
|
23
25
|
CONVERT_JSON_TO_JS_DEBUG,
|
|
26
|
+
CONVERT_YAML_TO_JSON_DEBUG,
|
|
27
|
+
CONVERT_JSON_TO_YAML_DEBUG,
|
|
24
28
|
RENAME_JS_TO_JSX_DEBUG,
|
|
25
29
|
RENAME_JS_TO_JSX_DEBUG,
|
|
26
30
|
BUNDLE_DEBUG,
|
package/lib/menu.js
CHANGED
|
@@ -26,6 +26,12 @@ export const CONVERT_JS_TO_JSON_DEBUG = '🦏 convert js to json: debug';
|
|
|
26
26
|
export const CONVERT_JSON_TO_JS = '🦏 convert json to js';
|
|
27
27
|
export const CONVERT_JSON_TO_JS_DEBUG = '🦏 convert json to js: debug';
|
|
28
28
|
|
|
29
|
+
export const CONVERT_YAML_TO_JSON = '🦏 convert yaml to json';
|
|
30
|
+
export const CONVERT_YAML_TO_JSON_DEBUG = '🦏 convert yaml to json: debug';
|
|
31
|
+
|
|
32
|
+
export const CONVERT_JSON_TO_YAML = '🦏 convert json to yaml';
|
|
33
|
+
export const CONVERT_JSON_TO_YAML_DEBUG = '🦏 convert json to yaml: debug';
|
|
34
|
+
|
|
29
35
|
export const RENAME_JS_TO_JSX = '🦏 rename js to jsx';
|
|
30
36
|
export const RENAME_JS_TO_JSX_DEBUG = '🦏 rename js to jsx: debug';
|
|
31
37
|
|
|
@@ -56,16 +62,51 @@ export const isConvertChosen = (a) => {
|
|
|
56
62
|
return [
|
|
57
63
|
CONVERT_JSON_TO_JS,
|
|
58
64
|
CONVERT_JS_TO_JSON,
|
|
65
|
+
CONVERT_YAML_TO_JSON,
|
|
66
|
+
CONVERT_JSON_TO_YAML,
|
|
59
67
|
CONVERT_RC_TO_FLAT,
|
|
60
68
|
].includes(a);
|
|
61
69
|
};
|
|
62
70
|
export const isRenameToJsxChosen = (a) => a === RENAME_JS_TO_JSX;
|
|
63
71
|
export const isRenameToJsChosen = (a) => a === RENAME_JSX_TO_JS;
|
|
64
|
-
export const isConvertChosenDebug = (a) =>
|
|
72
|
+
export const isConvertChosenDebug = (a) => [
|
|
73
|
+
CONVERT_JS_TO_JSON_DEBUG,
|
|
74
|
+
CONVERT_JSON_TO_JS_DEBUG,
|
|
75
|
+
CONVERT_YAML_TO_JSON_DEBUG,
|
|
76
|
+
CONVERT_JSON_TO_YAML_DEBUG,
|
|
77
|
+
].includes(a);
|
|
65
78
|
|
|
66
|
-
export const isConvertToJson = (a) => a === CONVERT_JS_TO_JSON || a === CONVERT_JS_TO_JSON_DEBUG;
|
|
67
|
-
export const isConvertToJs = (a) => a === CONVERT_JSON_TO_JS || a === CONVERT_JSON_TO_JS_DEBUG;
|
|
68
79
|
export const isConvertRCToFlat = (a) => a === CONVERT_RC_TO_FLAT;
|
|
69
80
|
|
|
70
81
|
export const isRenameToJs = (a) => a === RENAME_JS_TO_JSX || a === RENAME_JS_TO_JSX_DEBUG;
|
|
71
82
|
export const isRenameToJsx = (a) => a === RENAME_JSX_TO_JS || a === RENAME_JSX_TO_JS_DEBUG;
|
|
83
|
+
|
|
84
|
+
const callWith = (a) => (fn) => fn(a);
|
|
85
|
+
|
|
86
|
+
export const isKnownCommand = (a) => [
|
|
87
|
+
isScan,
|
|
88
|
+
isScanDebug,
|
|
89
|
+
isFix,
|
|
90
|
+
isFixDebug,
|
|
91
|
+
isPack,
|
|
92
|
+
isPackDebug,
|
|
93
|
+
isExtract,
|
|
94
|
+
isExtractDebug,
|
|
95
|
+
isGenerate,
|
|
96
|
+
isGenerateSimple,
|
|
97
|
+
isHelp,
|
|
98
|
+
isVersion,
|
|
99
|
+
isDebug,
|
|
100
|
+
isConvert,
|
|
101
|
+
isRename,
|
|
102
|
+
isBack,
|
|
103
|
+
isExit,
|
|
104
|
+
isEdit,
|
|
105
|
+
isView,
|
|
106
|
+
isTest,
|
|
107
|
+
isBundleDebug,
|
|
108
|
+
isConvertChosen,
|
|
109
|
+
isConvertChosenDebug,
|
|
110
|
+
isRenameToJsChosen,
|
|
111
|
+
isRenameToJsxChosen,
|
|
112
|
+
].some(callWith(a));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redlint",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Lint Filesystem with 🐊Putout",
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
"test:dts": "madrun test:dts",
|
|
28
28
|
"watch:test": "madrun watch:test",
|
|
29
29
|
"lint": "madrun lint",
|
|
30
|
+
"scan": "madrun scan",
|
|
31
|
+
"scan:fix": "madrun scan:fix",
|
|
30
32
|
"fresh:lint": "madrun fresh:lint",
|
|
31
33
|
"lint:fresh": "madrun lint:fresh",
|
|
32
34
|
"fix:lint": "madrun fix:lint",
|