@putout/plugin-remove-useless-functions
putout plugin adds ability to find and remove useless functions
Last updated 4 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/plugin-remove-useless-functions 
SYNC missed versions from official npm registry.

@putout/plugin-remove-useless-functions NPM version

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

Install

npm i @putout/plugin-remove-useless-functions -D

Rule

{
    "rules": {
        "remove-useless-functions": "on"
    }
}

❌ Example of incorrect code

const y = (...a) => {
    alert(...a);
};

[].filter((a) => a);

✅ Example of correct code

const y = alert;
[].filter(Boolean);

Open Questions

Why there is no transform for such case:

const f = (a) => alert(a);

Isn't is the same as:

const f = alert;

Actually it is the same, and this example can be converted without an issue, but there is also cases like:

const one = (f) => (a) => f(a);

[
    1,
    2,
    3,
    4,
].map(one(console.log));

// output
1;
2;
3;

And if it will be simplified:

const one = (f) => f;

[
    1,
    2,
    3,
    4,
].map(one(console.log));

// output
'1 0 [1, 2, 3]';
'2 1 [1, 2, 3]';
'3 2 [1, 2, 3]';

So behaviour is totally different. The same result for:

[
    1,
    2,
    3,
    4,
].map(console.log);

Because map calls a function with 3 arguments, and console.log receives any count of arguments, to cut redundant args there is a need to use something like:

const one = (f) => (a) => f(a);

There is a lot such cases in the wild. While we have no syntax to set the count of arguments we are going to receive, and a way to avoid returning result we don't want function to return, there is no need in such a dengerous transform.

License

MIT

Current Tags

  • 3.0.0                                ...           latest (a year ago)

9 Versions

  • 3.0.0                                ...           a year ago
  • 2.0.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (10)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE