@putout/plugin-putout 29.24.0 → 29.25.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/README.md CHANGED
@@ -27,6 +27,7 @@ npm i @putout/plugin-putout -D
27
27
  - ✅ [apply-async-formatter](#apply-async-formatter);
28
28
  - ✅ [apply-get-binding](#apply-get-binding);
29
29
  - ✅ [apply-create-test](#apply-create-test);
30
+ - ✅ [apply-string-to-property-key](#apply-string-to-property-key);
30
31
  - ✅ [apply-create-nested-directory](#apply-create-nested-directory);
31
32
  - ✅ [apply-declare](#apply-declare);
32
33
  - ✅ [apply-destructuring](#apply-destructuring);
@@ -117,9 +118,9 @@ npm i @putout/plugin-putout -D
117
118
  "putout/add-crawl-file": "on",
118
119
  "putout/add-track-file": "on",
119
120
  "putout/add-await-to-progress": "on",
121
+ "putout/apply-async-formatter": "on",
120
122
  "putout/apply-create-test": "on",
121
123
  "putout/apply-create-nested-directory": "on",
122
- "putout/apply-async-formatter": "on",
123
124
  "putout/apply-declare": "on",
124
125
  "putout/apply-destructuring": "on",
125
126
  "putout/apply-destructuring-to-options": "on",
@@ -134,6 +135,7 @@ npm i @putout/plugin-putout -D
134
135
  "putout/apply-rename": "on",
135
136
  "putout/apply-parens": "on",
136
137
  "putout/apply-remove": "on",
138
+ "putout/apply-string-to-property-key": "on",
137
139
  "putout/apply-transform-with-options": "on",
138
140
  "putout/apply-insert-before": "on",
139
141
  "putout/apply-traverser-to-ignore": "on",
@@ -260,6 +262,32 @@ t.report('a', 'Use b');
260
262
  t.noReport('a');
261
263
  ```
262
264
 
265
+ ## apply-string-to-property-key
266
+
267
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/46e3930cbdf32d316c0c6cb21eb59f5a/aecd754638d0bac8252048a4f4b3131c15ef6c6f).
268
+
269
+ ### ❌ Example of incorrect code
270
+
271
+ ```js
272
+ export const replace = {
273
+ [`section('@select', select(__args))`]: ({__args}, path) => {
274
+ __args.unshift(identifier('id'));
275
+ return path;
276
+ },
277
+ };
278
+ ```
279
+
280
+ ### ✅ Example of correct code
281
+
282
+ ```js
283
+ export const replace = {
284
+ 'section("@select", select(__args))"': ({__args}, path) => {
285
+ __args.unshift(identifier('id'));
286
+ return path;
287
+ },
288
+ };
289
+ ```
290
+
263
291
  ## apply-transform-with-options
264
292
 
265
293
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/92d40d40c75481816a5b5507e01d8315/bb54e932b4fff4bc0b453d723c72c7a9ed796b98).
@@ -88,7 +88,7 @@ const checkArgs = (names, push) => (path) => {
88
88
  name,
89
89
  });
90
90
  },
91
- [`__a(__args)`]: (path) => {
91
+ ['__a(__args)']: (path) => {
92
92
  const {callee} = path.node;
93
93
  const {name} = callee;
94
94
 
@@ -0,0 +1,34 @@
1
+ import {operator, types} from 'putout';
2
+
3
+ const {
4
+ isTemplateLiteral,
5
+ stringLiteral,
6
+ } = types;
7
+
8
+ const {replaceWith} = operator;
9
+
10
+ export const report = () => `Use 'string' instead of 'template' in property key`;
11
+
12
+ export const fix = (path) => {
13
+ const {quasis} = path.node;
14
+ const [first] = quasis;
15
+ const value = first.value.cooked.replaceAll(`'`, '"');
16
+
17
+ replaceWith(path, stringLiteral(value));
18
+ };
19
+
20
+ export const traverse = ({push}) => ({
21
+ ObjectProperty(path) {
22
+ const keyPath = path.get('key');
23
+
24
+ if (!isTemplateLiteral(keyPath))
25
+ return;
26
+
27
+ const {quasis} = keyPath.node;
28
+
29
+ if (quasis.length > 1)
30
+ return;
31
+
32
+ push(keyPath);
33
+ },
34
+ });
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as applyStringToPropertyKey from './apply-string-to-property-key/index.js';
1
2
  import * as convertTraverseToSuperTraverse from './convert-traverse-to-super-traverse/index.js';
2
3
  import * as applyDestructuringToOptions from './apply-destructuring-to-options/index.js';
3
4
  import * as applyGetBinding from './apply-get-binding/index.js';
@@ -174,4 +175,5 @@ export const rules = {
174
175
  'apply-get-binding': applyGetBinding,
175
176
  'apply-destructuring-to-options': applyDestructuringToOptions,
176
177
  'convert-traverse-to-super-traverse': convertTraverseToSuperTraverse,
178
+ 'apply-string-to-property-key': applyStringToPropertyKey,
177
179
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "29.24.0",
3
+ "version": "29.25.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",