@putout/plugin-arguments
v1.4.0
Published
๐Putout plugin adds ability to find and remove useless arguments
Maintainers
Readme
@putout/plugin-arguments 
๐Putout plugin adds ability to find and remove useless arguments.
Install
npm i @putout/plugin-argumentsRules
- โ apply-json-parse;
- โ apply-rest;
- โ convert-expressiont-to-arguments;
- โ remove-duplicate;
- โ remove-useless;
- โ remove-useless-from-method;
- โ remove-unused;
- โ remove-empty;
Config
{
"rules": {
"arguments/apply-json-parse": "on",
"arguments/apply-rest": "on",
"arguments/convert-expressiont-to-arguments": "on",
"arguments/remove-duplicate": "on",
"arguments/remove-useless": "on",
"arguments/remove-useless-from-method": "on",
"arguments/remove-unused": "on",
"arguments/remove-empty": "on"
}
}apply-json-parse
The
JSON.parse()static method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.(c) MDN
Check it out in ๐Putout Editor.
โ Example of incorrect code
import {operator} from 'putout';
const {fromJS} = operator;
JSON.parse(fromJS(print(ast)), null, 4);โ Example of correct code
import {operator} from 'putout';
const {fromJS} = operator;
JSON.parse(fromJS(print(ast)));apply-rest
The rest parameter syntax allows a function to accept an indefinite number of arguments as an
array, providing a way to represent variadic functions in JavaScript.(c) MDN
โ Example of incorrect code
function hello() {
console.log(arguments);
}โ Example of correct code
function hello(...args) {
console.log(args);
}convert-expression-to-arguments
Uncaught SyntaxError: Malformed arrow function parameter listoccurs when your function declaration is missing valid parameters.(c) MDN
๐Putout plugin adds ability to fix SyntaxError: missing formal parameter .
Checkout in ๐Putout Editor.
โ Example of incorrect code
(a(hello, world)) => (b + a);
(a + b) => (b + a);
(a || b) => (b + a);โ Example of correct code
(a, hello, world) => a;
(a, b) => b + a;
(a, b) => b + a;remove-duplicate
The JavaScript exception
duplicate formal argument xorduplicate argument names not allowed in this contextoccurs when a function creates two or more parameter bindings with the same name, and the function is not a non-strict function with only simple parameters.(c) MDN
Checkout in ๐Putout Editor.
-const sum = (a, a) => {}
+const sum = (a) => {}Comparison
Linter | Rule | Fix
----------------|-------|------------|
๐ Putout | arguments/remove-duplicate | โ
โฃ ESLint | no-dupe-args | โ
๐ฆ Deno | no-dupe-args | โ
remove-useless
โ Example of incorrect code
const sum = (a, b) => {};
sum(a, b, c);โ Example of correct code
const sum = (a, b) => {};
sum(a, b);remove-useless-from-method
Check it out in ๐Putout Editor.
โ Example of incorrect code
class Parser {
parseStatement(context, topLevel, exports) {
this.parseGuard(a, b);
}
parseGuard() {}
}โ Example of correct code
class Parser {
parseStatement(context, topLevel, exports) {
this.parseGuard();
}
parseGuard() {}
}remove-unused
Check it out in ๐Putout Editor.
โ Example of incorrect code
member += compute(member, list[i]);
function compute(member, current) {
return String(current);
}โ Example of correct code
member += compute(list[i]);
function compute(current) {
return String(current);
}remove-empty
Uncaught SyntaxError: Unexpected token ','(c) MDN
Check it out in ๐Putout Editor.
-renameFileWithLog('hello', ,'world');
+renameFileWithLog('hello', 'world');License
MIT
