Socket
Socket
Sign inDemoInstall

eslint-plugin-prefer-arrow

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-prefer-arrow - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

6

lib/rules/prefer-arrow-functions.js

@@ -72,2 +72,4 @@ /**

if (typeof node !== 'object' || node === null) return false;
if (node.type === 'FunctionDeclaration') return false;
if (node.type === 'FunctionExpression') return false;
if (node.type === 'ThisExpression') return true;

@@ -127,3 +129,3 @@ return Object.keys(node).some(field => {

if(isConstructor(node)) return;
if(containsThis(node) && !isClassMethod(node)) return;
if(!isClassMethod(node) && (containsThis(node.params) || containsThis(node.body))) return;
if(isGeneratorFunction(node)) return;

@@ -296,2 +298,2 @@ if(isGetterOrSetter(node)) return;

return replaceTokens(orig, tokens, swap).replace(/ $/, '') + (parens && !semicolon ? ');' : ';');
}
}
{
"name": "eslint-plugin-prefer-arrow",
"version": "1.2.2",
"version": "1.2.3",
"description": "Prefer arrow functions in most cases",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -24,12 +24,12 @@ # eslint-plugin-prefer-arrow

],
"rules": [
"rules": {
"prefer-arrow/prefer-arrow-functions": [
"warn",
{
"disallowPrototype": true,
"singleReturnOnly": false,
"classPropertiesAllowed": false
}
]
]
"warn",
{
"disallowPrototype": true,
"singleReturnOnly": false,
"classPropertiesAllowed": false
}
]
}
```

@@ -36,0 +36,0 @@ # Configuration

@@ -37,2 +37,8 @@ /**

'class foo { bar() { return "test" } }',
'function foo() { return () => this; }',
'function foo() { return (bar = this) => bar; }',
'function foo(bar = this) { return bar; }',
'const foo = function () { return () => this; }',
'const foo = function () { return (bar = this) => bar; }',
'const foo = function (bar = this) { return bar; }',
...[

@@ -97,2 +103,6 @@ 'var foo = (bar) => {return bar();}',

{code: 'function foo() { return arguments; }', errors: ['Use const or class constructors instead of named functions']},
{code: 'function foo() { return function () { return this; }; }', errors: ['Use const or class constructors instead of named functions']},
{code: 'function foo() { return function (bar = this) { return bar; }; }', errors: ['Use const or class constructors instead of named functions']},
{code: 'const foo = function () { return function (bar = this) { return bar; }; }', errors: ['Prefer using arrow functions over plain functions']},
{code: 'const foo = function () { return function () { return this; }; }', errors: ['Prefer using arrow functions over plain functions']},
{code: 'var foo = function() { return "World"; }', errors: ['Prefer using arrow functions over plain functions']},

@@ -99,0 +109,0 @@ {code: '["Hello", "World"].reduce(function(a, b) { return a + " " + b; })', errors: ['Prefer using arrow functions over plain functions']},

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc