redput 2.0.1 β†’ 2.2.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,17 @@
1
+ 2024.01.09, v2.2.0
2
+
3
+ fix:
4
+ - 1453d1e redput: nested: writeNestedTests: nestedPluginName
5
+
6
+ feature:
7
+ - d4343b5 redput: c8 v9.0.0
8
+ - 3da8937 redput: add-rule: add support of ESM
9
+
10
+ 2023.12.19, v2.1.0
11
+
12
+ feature:
13
+ - 59c9e8e redput: add ability to convert to string tuple
14
+
1
15
  2023.12.13, v2.0.1
2
16
 
3
17
  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
 
@@ -1,4 +1,5 @@
1
1
  import {access} from 'node:fs/promises';
2
+ import tryToCatch from 'try-to-catch';
2
3
  import {
3
4
  updateNestedIndex,
4
5
  updateOverallNestedFixtures,
@@ -12,7 +13,6 @@ import {
12
13
  writeRule,
13
14
  writeTests,
14
15
  } from './simple.js';
15
- import tryToCatch from 'try-to-catch';
16
16
 
17
17
  export const writePlugin = async (name, {rule, fixture, report, options}) => {
18
18
  const [isNested] = await tryToCatch(access, './package.json');
@@ -1,11 +1,13 @@
1
1
  import putout from 'putout';
2
2
  import * as insertGetRulePlugin from './plugin-insert-get-rule/index.js';
3
3
  import pluginPutout from '@putout/plugin-putout';
4
+ import nodejs from '@putout/plugin-nodejs';
4
5
  import removeUnusedVariables from '@putout/plugin-remove-unused-variables';
5
6
 
6
7
  export const addRule = (name, source, ruleOptions) => {
7
8
  const {code} = putout(source, {
8
9
  rules: {
10
+ 'nodejs/convert-esm-to-commonjs': 'on',
9
11
  'add-rule': ['on', {
10
12
  name,
11
13
  ruleOptions,
@@ -15,6 +17,7 @@ export const addRule = (name, source, ruleOptions) => {
15
17
  }],
16
18
  },
17
19
  plugins: [
20
+ ['nodejs', nodejs],
18
21
  ['putout', pluginPutout],
19
22
  ['remove-unused-variables', removeUnusedVariables],
20
23
  ['add-rule', insertGetRulePlugin],
@@ -36,7 +36,7 @@ export const writeNestedFixtures = async (name, data) => {
36
36
  export const writeNestedTests = async (name, report) => {
37
37
  const templatePath = new URL('../../../templates/plugin.js', import.meta.url).pathname;
38
38
  const template = await readFile(templatePath, 'utf8');
39
- const nestedPluginName = basename(dirname(join(process.cwd(), '..')));
39
+ const nestedPluginName = basename(dirname(join(process.cwd())));
40
40
  const nested = nestedPluginName.replace('plugin-', '');
41
41
 
42
42
  await writeFile(`./${name}/index.spec.js`, rendy(template, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redput",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "CLI tool to convert source from 🐊Putout Editor to files",
5
5
  "main": "lib/redput.js",
6
6
  "bin": {
@@ -59,6 +59,7 @@
59
59
  "dependencies": {
60
60
  "@putout/plugin-convert-esm-to-commonjs": "^6.0.0",
61
61
  "@putout/plugin-declare": "^2.0.1",
62
+ "@putout/plugin-nodejs": "^10.3.0",
62
63
  "@putout/plugin-putout": "^18.0.0",
63
64
  "@putout/plugin-remove-unused-variables": "^8.0.0",
64
65
  "node-fetch": "^3.3.2",
@@ -70,7 +71,7 @@
70
71
  },
71
72
  "devDependencies": {
72
73
  "@putout/test": "^8.0.0",
73
- "c8": "^8.0.0",
74
+ "c8": "^9.0.0",
74
75
  "escover": "^4.0.1",
75
76
  "eslint": "^8.0.0",
76
77
  "eslint-plugin-n": "^16.0.1",
@@ -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
- }