Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
eslint-plugin-prefer-arrow-functions
Advanced tools
An ESLint Plugin to Lint and auto-fix plain Functions into Arrow Functions, in all cases where conversion would result in the same behaviour (Arrow Functions do not support
this
,arguments
, ornew.target
for example).
npm install --save-dev eslint eslint-plugin-prefer-arrow-functions
Try it yourself at ASTExplorer.net by pasting code snippets in the top left panel, the results will appear in the bottom right panel.
Add the plugin to the plugins
section and the rule to the rules
section in your .eslintrc. The default values for options are listed in this example.
{
"plugins": ["prefer-arrow-functions"],
"rules": {
"prefer-arrow-functions/prefer-arrow-functions": [
"warn",
{
"allowNamedFunctions": false,
"classPropertiesAllowed": false,
"disallowPrototype": false,
"returnStyle": "unchanged",
"singleReturnOnly": false
}
]
}
}
allowNamedFunctions
If set to true, the rule won't report named functions such as function foo() {}
. Anonymous function such as const foo = function() {}
will still be reported.
classPropertiesAllowed
When true
, functions defined as class instance fields will be converted to arrow functions when doing so would not alter or break their behaviour.
disallowPrototype
When true
, functions assigned to a prototype
will be converted to arrow functions when doing so would not alter or break their behaviour.
returnStyle
"implicit"
, arrow functions such as x => { return x; }
will be converted to x => x
."explicit"
, arrow functions such as x => x
will be converted to x => { return x; }
."unchanged"
or not set, arrow functions will be left as they were.singleReturnOnly
When true
, only function
declarations which only contain a return statement will be converted. Functions containing block statements will be ignored.
This option works well in conjunction with ESLint's built-in arrow-body-style set to
as-needed
.
This project is a fork of https://github.com/TristonJ/eslint-plugin-prefer-arrow by Triston Jones.
Get help with issues by creating a Bug Report or discuss ideas by opening a Feature Request.
If you find my Open Source projects useful, please share them ❤️
I'm Jamie Mason from Leeds in England, I began Web Design and Development in 1999 and have been Contracting and offering Consultancy as Fold Left Ltd since 2012. Who I've worked with includes Sky Sports, Sky Bet, Sky Poker, The Premier League, William Hill, Shell, Betfair, and Football Clubs including Leeds United, Spurs, West Ham, Arsenal, and more.
FAQs
Convert functions to arrow functions
We found that eslint-plugin-prefer-arrow-functions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.