Skip to content

Latest commit

 

History

History

README.md

@putout/plugin-arguments NPM version

🐊Putout plugin adds ability to find and remove useless arguments.

Install

npm i @putout/plugin-arguments

Rules

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 list occurs 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 x or duplicate argument names not allowed in this context occurs 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