redlint 6.6.0 → 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 +96 -3
- package/ChangeLog +6 -0
- package/bin/redlint.js +6 -0
- package/lib/convert/converters/convert-json-to-yaml.js +14 -0
- package/lib/convert/create-options.js +5 -0
- package/lib/convert/index.js +2 -0
- package/lib/debug.js +2 -0
- package/lib/menu.js +35 -0
- package/package.json +3 -1
package/CONTRIBUTING.md
CHANGED
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
- **No `t.pass('everything ok')` in tests** — every assertion must test something meaningful.
|
|
7
7
|
- **100% coverage required** — checked via [`.nycrc.json`](.nycrc.json). Run `redrun coverage` to verify.
|
|
8
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
|
|
10
|
-
- **Run `redrun fix:lint
|
|
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
11
|
|
|
12
12
|
## Table of Contents
|
|
13
13
|
|
|
14
14
|
- [Do / Don't](#do--dont)
|
|
15
15
|
- [Workflow](#workflow)
|
|
16
16
|
- [Architecture](#architecture)
|
|
17
|
+
- [How to add a new converter](#how-to-add-a-new-converter)
|
|
17
18
|
- [Import Map](#import-map)
|
|
18
19
|
- [File Tree](#file-tree)
|
|
19
20
|
- [Overrides Pattern](#overrides-pattern)
|
|
@@ -74,6 +75,98 @@ The debug mode is an escape hatch when workers misbehave.
|
|
|
74
75
|
- Mocking: `stub()` from supertape (no external mocking library)
|
|
75
76
|
- Fixtures: plain `.js` files in `fixture/` directories
|
|
76
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
|
+
|
|
77
170
|
## Import Map
|
|
78
171
|
|
|
79
172
|
The project uses Node.js [`imports`](package.json) for internal aliases:
|
|
@@ -177,5 +270,5 @@ This pattern keeps functions pure, easy to unit test, and doesn't require any mo
|
|
|
177
270
|
| [madrun](https://github.com/coderaiser/madrun) | Define tasks in `.madrun.js` | `redrun` |
|
|
178
271
|
| [putout](https://github.com/coderaiser/putout) | JavaScript code transformer & linter | `redrun fix:lint` |
|
|
179
272
|
| [supertape](https://github.com/coderaiser/supertape) | Test framework with built-in `stub()` | `redrun test` |
|
|
180
|
-
| [superc8](https://github.com/coderaiser/superc8) |
|
|
273
|
+
| [superc8](https://github.com/coderaiser/superc8) | coverage tool, drop-in modern `c8` replacement | `redrun coverage` |
|
|
181
274
|
| [nodemon](https://github.com/remy/nodemon) | Watch mode for tests | `redrun watch:test` |
|
package/ChangeLog
CHANGED
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 [, 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
|
+
});
|
|
@@ -5,9 +5,12 @@ import {
|
|
|
5
5
|
CONVERT_JS_TO_JSON_DEBUG,
|
|
6
6
|
CONVERT_YAML_TO_JSON,
|
|
7
7
|
CONVERT_YAML_TO_JSON_DEBUG,
|
|
8
|
+
CONVERT_JSON_TO_YAML,
|
|
9
|
+
CONVERT_JSON_TO_YAML_DEBUG,
|
|
8
10
|
CONVERT_RC_TO_FLAT,
|
|
9
11
|
} from '../menu.js';
|
|
10
12
|
import {convertYamlToJson} from './converters/convert-yaml-to-json.js';
|
|
13
|
+
import {convertJsonToYaml} from './converters/convert-json-to-yaml.js';
|
|
11
14
|
import {convertJsonToJs} from './converters/convert-json-to-js.js';
|
|
12
15
|
import {convertJSToJson} from './converters/convert-js-to-json.js';
|
|
13
16
|
import {convertRCToFlat} from './converters/convert-rc-to-flat.js';
|
|
@@ -19,6 +22,8 @@ const CONVERTERS = {
|
|
|
19
22
|
[CONVERT_JS_TO_JSON_DEBUG]: convertJSToJson,
|
|
20
23
|
[CONVERT_YAML_TO_JSON]: convertYamlToJson,
|
|
21
24
|
[CONVERT_YAML_TO_JSON_DEBUG]: convertYamlToJson,
|
|
25
|
+
[CONVERT_JSON_TO_YAML]: convertJsonToYaml,
|
|
26
|
+
[CONVERT_JSON_TO_YAML_DEBUG]: convertJsonToYaml,
|
|
22
27
|
[CONVERT_RC_TO_FLAT]: convertRCToFlat,
|
|
23
28
|
};
|
|
24
29
|
|
package/lib/convert/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
EXIT,
|
|
7
7
|
CONVERT_RC_TO_FLAT,
|
|
8
8
|
CONVERT_YAML_TO_JSON,
|
|
9
|
+
CONVERT_JSON_TO_YAML,
|
|
9
10
|
} from '../menu.js';
|
|
10
11
|
|
|
11
12
|
export * from './convert.js';
|
|
@@ -14,6 +15,7 @@ export const chooseConvert = async () => {
|
|
|
14
15
|
CONVERT_JS_TO_JSON,
|
|
15
16
|
CONVERT_JSON_TO_JS,
|
|
16
17
|
CONVERT_YAML_TO_JSON,
|
|
18
|
+
CONVERT_JSON_TO_YAML,
|
|
17
19
|
CONVERT_RC_TO_FLAT,
|
|
18
20
|
BACK,
|
|
19
21
|
EXIT,
|
package/lib/debug.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CONVERT_JS_TO_JSON_DEBUG,
|
|
8
8
|
CONVERT_JSON_TO_JS_DEBUG,
|
|
9
9
|
CONVERT_YAML_TO_JSON_DEBUG,
|
|
10
|
+
CONVERT_JSON_TO_YAML_DEBUG,
|
|
10
11
|
RENAME_JS_TO_JSX_DEBUG,
|
|
11
12
|
BACK,
|
|
12
13
|
EXIT,
|
|
@@ -23,6 +24,7 @@ export const debug = async () => {
|
|
|
23
24
|
CONVERT_JS_TO_JSON_DEBUG,
|
|
24
25
|
CONVERT_JSON_TO_JS_DEBUG,
|
|
25
26
|
CONVERT_YAML_TO_JSON_DEBUG,
|
|
27
|
+
CONVERT_JSON_TO_YAML_DEBUG,
|
|
26
28
|
RENAME_JS_TO_JSX_DEBUG,
|
|
27
29
|
RENAME_JS_TO_JSX_DEBUG,
|
|
28
30
|
BUNDLE_DEBUG,
|
package/lib/menu.js
CHANGED
|
@@ -29,6 +29,9 @@ export const CONVERT_JSON_TO_JS_DEBUG = '🦏 convert json to js: debug';
|
|
|
29
29
|
export const CONVERT_YAML_TO_JSON = '🦏 convert yaml to json';
|
|
30
30
|
export const CONVERT_YAML_TO_JSON_DEBUG = '🦏 convert yaml to json: debug';
|
|
31
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
|
+
|
|
32
35
|
export const RENAME_JS_TO_JSX = '🦏 rename js to jsx';
|
|
33
36
|
export const RENAME_JS_TO_JSX_DEBUG = '🦏 rename js to jsx: debug';
|
|
34
37
|
|
|
@@ -60,6 +63,7 @@ export const isConvertChosen = (a) => {
|
|
|
60
63
|
CONVERT_JSON_TO_JS,
|
|
61
64
|
CONVERT_JS_TO_JSON,
|
|
62
65
|
CONVERT_YAML_TO_JSON,
|
|
66
|
+
CONVERT_JSON_TO_YAML,
|
|
63
67
|
CONVERT_RC_TO_FLAT,
|
|
64
68
|
].includes(a);
|
|
65
69
|
};
|
|
@@ -69,9 +73,40 @@ export const isConvertChosenDebug = (a) => [
|
|
|
69
73
|
CONVERT_JS_TO_JSON_DEBUG,
|
|
70
74
|
CONVERT_JSON_TO_JS_DEBUG,
|
|
71
75
|
CONVERT_YAML_TO_JSON_DEBUG,
|
|
76
|
+
CONVERT_JSON_TO_YAML_DEBUG,
|
|
72
77
|
].includes(a);
|
|
73
78
|
|
|
74
79
|
export const isConvertRCToFlat = (a) => a === CONVERT_RC_TO_FLAT;
|
|
75
80
|
|
|
76
81
|
export const isRenameToJs = (a) => a === RENAME_JS_TO_JSX || a === RENAME_JS_TO_JSX_DEBUG;
|
|
77
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",
|