Skip to content

Commit 1079cdc

Browse files
committed
feature: @putout/plugin-remove-useless-arguments: unused: add
1 parent e11a045 commit 1079cdc

File tree

26 files changed

+375
-16
lines changed

26 files changed

+375
-16
lines changed

packages/operator-match-files/lib/match-files.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ module.exports.matchFiles = (options) => {
4343
};
4444
};
4545

46-
function fix(inputFile, {dirPath, mainPath, matchInputFilename, outputFilename, matchedJS, matchedAST, options}) {
46+
function fix(inputFile, {dirPath, matchInputFilename, outputFilename, matchedJS, matchedAST, options}) {
4747
transform(matchedAST, matchedJS, options);
4848

4949
const matchedJSON = magicPrint(outputFilename, matchedAST);
50-
const outputFile = getOutputFile(mainPath, {
50+
const outputFile = getOutputFile({
5151
dirPath,
5252
matchInputFilename,
5353
outputFilename,
@@ -80,7 +80,6 @@ const createScan = ({files, exclude}) => (mainPath, {push, progress, options}) =
8080
continue;
8181

8282
allFiles.push({
83-
mainPath,
8483
dirPath,
8584
matchInputFilename,
8685
rawOptions,
@@ -101,7 +100,6 @@ const createScan = ({files, exclude}) => (mainPath, {push, progress, options}) =
101100
inputFilename,
102101
outputFilename,
103102
rawOptions,
104-
mainPath,
105103
} = current;
106104

107105
progress({
@@ -122,7 +120,6 @@ const createScan = ({files, exclude}) => (mainPath, {push, progress, options}) =
122120

123121
push(inputFile, {
124122
dirPath,
125-
mainPath,
126123
matchInputFilename,
127124

128125
outputFilename,
@@ -171,7 +168,7 @@ function check(files) {
171168
}
172169
}
173170

174-
function getOutputFile(path, {dirPath, matchInputFilename, outputFilename, inputFile}) {
171+
function getOutputFile({dirPath, matchInputFilename, outputFilename, inputFile}) {
175172
if (matchInputFilename === outputFilename)
176173
return inputFile;
177174

packages/plugin-cloudcmd/lib/convert-load-dir-to-change-dir/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports.replace = () => ({
1313
'CloudCmd.loadDir({path})': 'CloudCmd.changeDir(path)',
1414
'CloudCmd.loadDir({path: __a})': 'CloudCmd.changeDir(__a)',
1515
'CloudCmd.loadDir(__object)': (vars, path) => {
16-
convert(vars, path);
16+
convert(path);
1717
path.node.callee.property.name = 'changeDir';
1818

1919
return path;
@@ -27,21 +27,21 @@ module.exports.replace = () => ({
2727
return 'changeDir(path)';
2828
},
2929
'loadDir(__object)': (vars, path) => {
30-
convert(vars, path);
30+
convert(path);
3131
renameAll(path);
3232

3333
return path;
3434
},
3535
'changeDir({path: __a})': 'changeDir(__a)',
3636
'changeDir({path})': 'changeDir(path)',
3737
'changeDir(__object)': (vars, path) => {
38-
convert(vars, path);
38+
convert(path);
3939

4040
return path;
4141
},
4242
});
4343

44-
function convert(vars, path) {
44+
function convert(path) {
4545
const args = path.node.arguments;
4646
const [obj] = path.get('arguments');
4747
const properties = obj.get('properties');

packages/plugin-optional-chaining/lib/get-logical.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports.getLogical = (path, {assign} = {}) => {
1111
const logical = [member];
1212

1313
while (++i < n) {
14-
member += compute(member, list[i]);
14+
member += compute(list[i]);
1515
logical.push(member);
1616
}
1717

@@ -23,7 +23,7 @@ module.exports.getLogical = (path, {assign} = {}) => {
2323
return `${fullLogical} && (${logical.at(-1)} = __a)`;
2424
};
2525

26-
function compute(member, current) {
26+
function compute(current) {
2727
if (current[0] === '(')
2828
return current;
2929

packages/plugin-remove-useless-arguments/README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@
1111
npm i @putout/plugin-remove-useless-arguments
1212
```
1313

14-
## Rule
14+
## Rules
15+
16+
-[arguments](#arguments);
17+
-[destructuring](#destructring);
18+
-[method](#method);
19+
-[unused](#unused);
20+
21+
## Config
1522

1623
```json
1724
{
1825
"rules": {
1926
"remove-useless-arguments/arguments": "on",
2027
"remove-useless-arguments/destructuring": "on",
21-
"remove-useless-arguments/method": "on"
28+
"remove-useless-arguments/method": "on",
29+
"remove-useless-arguments/unused": "on"
2230
}
2331
}
2432
```
@@ -92,6 +100,30 @@ class Parser {
92100
}
93101
```
94102

103+
### unused
104+
105+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f6bf5e069cfb1328fe7418c501e265cc/388ab2266babe84f77c1f82687f5ed44873e8651).
106+
107+
### ❌ Example of incorrect code
108+
109+
```js
110+
member += compute(member, list[i]);
111+
112+
function compute(member, current) {
113+
return String(current);
114+
}
115+
```
116+
117+
### ✅ Example of correct code
118+
119+
```js
120+
member += compute(list[i]);
121+
122+
function compute(current) {
123+
return String(current);
124+
}
125+
```
126+
95127
## License
96128

97129
MIT

packages/plugin-remove-useless-arguments/lib/remove-useless-arguments.js renamed to packages/plugin-remove-useless-arguments/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
const argumentsRule = require('./arguments');
44
const destructuring = require('./destructuring');
55
const method = require('./method');
6+
const unused = require('./unused');
67

78
module.exports.rules = {
89
arguments: argumentsRule,
910
destructuring,
1011
method,
12+
unused,
1113
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const outputFile = getOutputFile({
2+
dirPath,
3+
outputFilename,
4+
});
5+
6+
const outputFile2 = getOutputFile({
7+
dirPath,
8+
matchInputFilename,
9+
});
10+
11+
const getOutputFile = function({dirPath, outputFile}) {
12+
return createFile(dirPath);
13+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const outputFile = getOutputFile(mainPath, {
2+
dirPath,
3+
outputFilename,
4+
});
5+
6+
const outputFile2 = getOutputFile(mainPath, {
7+
dirPath,
8+
matchInputFilename,
9+
});
10+
11+
const getOutputFile = function(path, {dirPath, outputFile}) {
12+
return createFile(dirPath);
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const outputFile = getOutputFile({
2+
dirPath,
3+
matchInputFilename,
4+
outputFilename,
5+
inputFile,
6+
});
7+
8+
const getOutputFile = ({dirPath, matchInputFilename, outputFilename, inputFile}) => {
9+
return createFile(dirPath, outputFilename);
10+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const outputFile = getOutputFile(mainPath, {
2+
dirPath,
3+
matchInputFilename,
4+
outputFilename,
5+
inputFile,
6+
});
7+
8+
const getOutputFile = (path, {dirPath, matchInputFilename, outputFilename, inputFile}) => {
9+
return createFile(dirPath, outputFilename);
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const outputFile = getOutputFile({
2+
dirPath,
3+
outputFilename,
4+
});
5+
6+
const outputFile2 = getOutputFile({
7+
dirPath,
8+
matchInputFilename,
9+
});
10+
11+
const getOutputFile = ({dirPath, outputFile}) => {
12+
return createFile(dirPath);
13+
};

0 commit comments

Comments
 (0)