@putout/plugin-putout 8.3.0 → 8.6.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
@@ -31,6 +31,7 @@ npm i @putout/plugin-putout -D
31
31
  "putout/convert-process-to-find": "on",
32
32
  "putout/convert-method-to-property": "on",
33
33
  "putout/convert-add-argument-to-add-args": "on",
34
+ "putout/convert-dirname-to-url": "on",
34
35
  "putout/shorten-imports": "on",
35
36
  "putout/check-replace-code": "on",
36
37
  "putout/declare": "on",
@@ -396,6 +397,30 @@ module.exports = addArgs({
396
397
  });
397
398
  ```
398
399
 
400
+ ## convert-dirname-to-url
401
+
402
+ ```js
403
+ import {createTest} from '@putout/test';
404
+ import plugin from '@putout/plugin-debugger';
405
+ import {createSimport} from 'simport';
406
+ const {__dirname} = createSimport(import.meta.url);
407
+
408
+ const test = createTest(__dirname, {
409
+ 'remove-debugger': plugin,
410
+ });
411
+ ```
412
+
413
+ ### ✅ Correct code Example
414
+
415
+ ```js
416
+ import {createTest} from '@putout/test';
417
+ import plugin from '@putout/plugin-debugger';
418
+
419
+ const test = createTest(import.meta.url, {
420
+ 'remove-debugger': plugin,
421
+ });
422
+ ```
423
+
399
424
  ## move-require-on-top-level
400
425
 
401
426
  ### ❌ Incorrect code example
@@ -10,6 +10,7 @@ const {operator} = putout;
10
10
  const {
11
11
  compare,
12
12
  extract,
13
+ compute,
13
14
  } = operator;
14
15
 
15
16
  const name = '__putout_plugin_check_replace_code';
@@ -28,7 +29,7 @@ module.exports.report = ({path, code, error}) => {
28
29
  if (error)
29
30
  return error.message;
30
31
 
31
- const key = extract(path.node.key);
32
+ const [, key] = parseKey(path);
32
33
  const value = extract(path.node.value);
33
34
 
34
35
  return `transform mismatch: "${key}" -> "${value}" !== "${code}"`;
@@ -48,11 +49,17 @@ module.exports.traverse = ({push}) => ({
48
49
  continue;
49
50
 
50
51
  const {node} = propertyPath;
52
+ const [parseError, key] = parseKey(propertyPath);
51
53
 
52
- if (node.computed)
53
- return false;
54
+ if (parseError) {
55
+ push({
56
+ error: parseError,
57
+ mainPath: path,
58
+ path: propertyPath,
59
+ });
60
+ return;
61
+ }
54
62
 
55
- const key = extract(node.key);
56
63
  const template = extract(node.value);
57
64
  const [generateError, keyCode] = generateCode(path, key);
58
65
 
@@ -100,3 +107,13 @@ module.exports.traverse = ({push}) => ({
100
107
  },
101
108
  });
102
109
 
110
+ function parseKey(propertyPath) {
111
+ const keyPath = propertyPath.get('key');
112
+ const [isComputed, key] = compute(keyPath);
113
+
114
+ if (!isComputed)
115
+ return [Error(`Replace key cannot be computed: '${keyPath.toString()}'`)];
116
+
117
+ return [null, key];
118
+ }
119
+
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+ const {isESM} = operator;
5
+
6
+ module.exports.report = () => `Use 'createTest(import.meta.url)' instead of 'createTest(__dirname)'`;
7
+
8
+ module.exports.match = () => ({
9
+ 'createTest(__dirname, __a)': (vars, path) => {
10
+ return isESM(path);
11
+ },
12
+ });
13
+
14
+ module.exports.replace = () => ({
15
+ 'createTest(__dirname, __a)': 'createTest(import.meta.url, __a)',
16
+ });
17
+
package/lib/index.js CHANGED
@@ -20,6 +20,7 @@ module.exports.rules = {
20
20
  ...getRule('convert-process-to-find'),
21
21
  ...getRule('convert-method-to-property'),
22
22
  ...getRule('convert-add-argument-to-add-args'),
23
+ ...getRule('convert-dirname-to-url'),
23
24
  ...getRule('rename-operate-to-operator'),
24
25
  ...getRule('replace-operate-with-operator'),
25
26
  ...getRule('shorten-imports'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "8.3.0",
3
+ "version": "8.6.0",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "putout plugin helps with plugins development",
6
6
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-putout",