redput 2.0.1 β†’ 2.1.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,8 @@
1
+ 2023.12.19, v2.1.0
2
+
3
+ feature:
4
+ - 59c9e8e redput: add ability to convert to string tuple
5
+
1
6
  2023.12.13, v2.0.1
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -28,6 +28,22 @@ GITHUB_TOKEN=github-token redput [putout-editor-url]
28
28
  - if it finds `index.js` - creates rule inside nested plugin;
29
29
  - creates directory with a plugin name and fills directories `lib`, `test` and `fixture`;
30
30
 
31
+ example of input:
32
+
33
+ ```js
34
+ // ["off", "write-all-files"]
35
+ export const report = () => `Write all files`;
36
+
37
+ export const fix = (file) => {
38
+ const content = readFileContent(file);
39
+ writeFileContent(file, content);
40
+ };
41
+
42
+ export const scan = (root, {push}) => {
43
+ findFile(root, ['*']).map(push);
44
+ };
45
+ ```
46
+
31
47
  ## License
32
48
 
33
49
  MIT
@@ -0,0 +1,42 @@
1
+ # @putout/plugin-apply-strings-tuple [![NPM version][NPMIMGURL]][NPMURL]
2
+
3
+ [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-apply-strings-tuple.svg?style=flat&longCache=true
4
+ [NPMURL]: https://npmjs.org/package/@putout/plugin-apply-strings-tuple "npm"
5
+
6
+ 🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds abilit to apply strings tuple. Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/34ea476503a1ffd981abd85882383ba5/67774fba230669fd88cf6b1d870743e051706f8b).
7
+
8
+ ## Install
9
+
10
+ ```
11
+ npm i @putout/plugin-apply-strings-tuple
12
+ ```
13
+
14
+ ## Rule
15
+
16
+ ```json
17
+ {
18
+ "rules": {
19
+ "apply-strings-tuple": "on"
20
+ }
21
+ }
22
+ ```
23
+
24
+ ## ❌ Example of incorrect code
25
+
26
+ ```
27
+ [off, remove-useless];
28
+ ['off', remove-useless];
29
+ ['off', 'remove-useless'];
30
+ ```
31
+
32
+ ## βœ… Example of correct code
33
+
34
+ ```
35
+ ['off', 'remove-useless'];
36
+ ['off', 'remove-useless'];
37
+ ['off', 'remove-useless'];
38
+ ```
39
+
40
+ ## License
41
+
42
+ MIT
@@ -0,0 +1,17 @@
1
+ import {types} from 'putout';
2
+
3
+ const {isStringLiteral} = types;
4
+
5
+ export const report = () => `Apply strings tuple`;
6
+
7
+ export const replace = () => ({
8
+ '[__a, __b]': ({__a, __b}, path) => {
9
+ const [__aPath, __bPath] = path.get('elements');
10
+ const status = isStringLiteral(__a) ? __a.value : __aPath.toString();
11
+ const name = isStringLiteral(__b) ? __b.value : __bPath
12
+ .toString()
13
+ .replace(/\s/g, '') + '';
14
+
15
+ return `["${status}", "${name}"]`;
16
+ },
17
+ });
@@ -0,0 +1,59 @@
1
+ import tryCatch from 'try-catch';
2
+ import {
3
+ parse,
4
+ transform,
5
+ print,
6
+ } from 'putout';
7
+ import * as applyStringsTuple from './apply-strings-tuple/index.js';
8
+
9
+ export const parsePlugin = (raw) => {
10
+ const [comment, ...lines] = raw.split('\n');
11
+ const [options, name] = parseComment(comment);
12
+
13
+ return {
14
+ name,
15
+ lines,
16
+ options,
17
+ };
18
+ };
19
+
20
+ function parseComment(comment) {
21
+ const raw = comment
22
+ .replace('//', '')
23
+ .trimStart();
24
+
25
+ const [error, data] = tryCatch(JSON.parse, raw);
26
+
27
+ if (!error)
28
+ return data;
29
+
30
+ const [parseError, ast] = tryCatch(parse, raw);
31
+
32
+ if (parseError)
33
+ return ['', raw];
34
+
35
+ transform(ast, raw, {
36
+ plugins: [
37
+ ['apply-strings-tuple', applyStringsTuple],
38
+ ],
39
+ });
40
+
41
+ const json = print(ast, {
42
+ printer: ['putout', {
43
+ format: {
44
+ quote: '"',
45
+ },
46
+ semantics: {
47
+ encodeDoubleQuote: false,
48
+ trailingComma: false,
49
+ },
50
+ }],
51
+ }).slice(0, -2);
52
+
53
+ const [secondError, result] = tryCatch(JSON.parse, json);
54
+
55
+ if (secondError)
56
+ return ['', raw];
57
+
58
+ return result;
59
+ }
package/lib/redput.js CHANGED
@@ -3,7 +3,7 @@ import {getReport} from './get-report/get-report.js';
3
3
  import {readGist} from './read-gist/read-gist.js';
4
4
  import {writePlugin} from './write/index.js';
5
5
  import {parseLink} from './parse-link.js';
6
- import {parsePlugin} from './parse-plugin.js';
6
+ import {parsePlugin} from './parse-plugin/parse-plugin.js';
7
7
 
8
8
  const SUCCESS = [null, 'Done'];
9
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redput",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "CLI tool to convert source from 🐊Putout Editor to files",
5
5
  "main": "lib/redput.js",
6
6
  "bin": {
@@ -1,30 +0,0 @@
1
- import tryCatch from 'try-catch';
2
-
3
- const {parse} = JSON;
4
-
5
- export const parsePlugin = (raw) => {
6
- const [comment, ...lines] = raw.split('\n');
7
- const [options, name] = parseComment(comment);
8
-
9
- return {
10
- name,
11
- lines,
12
- options,
13
- };
14
- };
15
-
16
- function parseComment(comment) {
17
- const raw = comment
18
- .replace('//', '')
19
- .trimStart();
20
-
21
- const [error, data] = tryCatch(parse, raw);
22
-
23
- if (error)
24
- return ['', raw];
25
-
26
- return [
27
- data[0],
28
- data[1],
29
- ];
30
- }