@putout/plugin-variables 1.2.0 → 1.3.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.
@@ -0,0 +1,40 @@
1
+ import {operator} from 'putout';
2
+ import getVars from './get-vars/index.js';
3
+ import transform from './transform.js';
4
+ import getUnused from './get-unused.js';
5
+
6
+ const {
7
+ replaceWith,
8
+ compare,
9
+ remove,
10
+ } = operator;
11
+
12
+ export const report = ({name}) => `'${name}' is defined but never used`;
13
+
14
+ export const fix = ({path}) => {
15
+ if (compare(path, 'const __a = __b = __c'))
16
+ return replaceWith(path.parentPath, path.node.init);
17
+
18
+ if (isOneImport(path))
19
+ return remove(path.parentPath);
20
+
21
+ remove(path);
22
+ };
23
+
24
+ export const find = (ast, {traverse}) => {
25
+ const vars = getVars(ast, {
26
+ setPath: true,
27
+ traverse,
28
+ });
29
+
30
+ const transformed = transform(vars);
31
+
32
+ return getUnused(transformed);
33
+ };
34
+
35
+ function isOneImport({parentPath}) {
36
+ if (!parentPath.isImportDeclaration())
37
+ return false;
38
+
39
+ return parentPath.node.specifiers.length === 1;
40
+ }
@@ -0,0 +1,18 @@
1
+ export default (items) => {
2
+ const result = [];
3
+
4
+ for (const item of items) {
5
+ const entries = Object.entries(item);
6
+
7
+ for (const entry of entries) {
8
+ result.push(transform(entry));
9
+ }
10
+ }
11
+
12
+ return result;
13
+ };
14
+
15
+ const transform = ([name, value]) => ({
16
+ name,
17
+ ...value,
18
+ });
@@ -3,7 +3,7 @@ import {operator, types} from 'putout';
3
3
  const {remove, rename} = operator;
4
4
  const {isIdentifier} = types;
5
5
 
6
- export const report = ({idName}) => `Useless variable declaration with name "${idName}"`;
6
+ export const report = ({idName}) => `Avoid useless variable declaration with name '${idName}'`;
7
7
 
8
8
  export const fix = ({path, bindingPath, initName, idName}) => {
9
9
  rename(bindingPath, initName, idName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-variables",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to find and remove useless",
@@ -40,7 +40,8 @@
40
40
  "@putout/plugin-for-of": "*",
41
41
  "@putout/plugin-maybe": "*",
42
42
  "@putout/plugin-minify": "*",
43
- "@putout/plugin-remove-unused-variables": "*",
43
+ "@putout/plugin-nodejs": "*",
44
+ "@putout/plugin-putout": "*",
44
45
  "@putout/plugin-remove-useless-array-from": "*",
45
46
  "@putout/plugin-reuse-duplicate-init": "*",
46
47
  "@putout/test": "^14.0.0",
@@ -48,8 +49,11 @@
48
49
  "eslint": "v10.0.0-alpha.0",
49
50
  "eslint-plugin-n": "^17.0.0",
50
51
  "eslint-plugin-putout": "^29.0.0",
52
+ "just-camel-case": "^6.2.0",
51
53
  "madrun": "^11.0.0",
52
- "nodemon": "^3.0.1"
54
+ "nodemon": "^3.0.1",
55
+ "supertape": "^11.3.1",
56
+ "try-catch": "^3.0.1"
53
57
  },
54
58
  "peerDependencies": {
55
59
  "putout": ">=41"