diff --git a/eslint-plugin-expensify/CONST.js b/eslint-plugin-expensify/CONST.js index c3b8204..966d318 100644 --- a/eslint-plugin-expensify/CONST.js +++ b/eslint-plugin-expensify/CONST.js @@ -27,7 +27,6 @@ module.exports = { ONYX_ONE_PARAM: 'The withOnyx HOC must be passed at least one argument.', MUST_USE_VARIABLE_FOR_ASSIGNMENT: '{{key}} must be assigned as a variable instead of direct assignment.', NO_DEFAULT_PROPS: 'defaultProps should not be used in function components. Use default Arguments instead.', - AVOID_ANONYMOUS_FUNCTIONS: 'Prefer named functions.', USE_PERIODS_ERROR_MESSAGES: 'Use periods at the end of error messages.', }, }; diff --git a/eslint-plugin-expensify/avoid-anonymous-functions.js b/eslint-plugin-expensify/avoid-anonymous-functions.js deleted file mode 100644 index b3f9db7..0000000 --- a/eslint-plugin-expensify/avoid-anonymous-functions.js +++ /dev/null @@ -1,32 +0,0 @@ -const message = require('./CONST').MESSAGE.AVOID_ANONYMOUS_FUNCTIONS; - -module.exports = { - create(context) { - return { - "CallExpression > FunctionExpression": function (node) { - if (!node.id && !node.generator && !node.async) { - context.report({ - node, - message, - }); - } - }, - "CallExpression": function (node) { - if (node.arguments && node.arguments.some(arg => arg.type === "ArrowFunctionExpression" && !arg.id)) { - context.report({ - node, - message, - }); - } - }, - "ReturnStatement > FunctionExpression, ReturnStatement > ArrowFunctionExpression": function (node) { - if (!node.id) { - context.report({ - node, - message, - }); - } - } - }; - }, -}; diff --git a/eslint-plugin-expensify/tests/avoid-anonymous-functions.test.js b/eslint-plugin-expensify/tests/avoid-anonymous-functions.test.js deleted file mode 100644 index a2aaee9..0000000 --- a/eslint-plugin-expensify/tests/avoid-anonymous-functions.test.js +++ /dev/null @@ -1,226 +0,0 @@ -const RuleTester = require('eslint').RuleTester; -const rule = require('../avoid-anonymous-functions'); -const message = require('../CONST').MESSAGE.AVOID_ANONYMOUS_FUNCTIONS; - -const ruleTester = new RuleTester({ - parserOptions: { - ecmaVersion: 6, - sourceType: 'module', - }, -}); - -ruleTester.run('avoid-anonymous-functions', rule, { - valid: [ - { - code: ` - function test() { - function innerFunction(node) { - return node.isParent; - } - - const onlyParents = nodes.filter(innerFunction); - - return onlyParents; - }`, - }, - { - code: ` - function test() { - const onlyParents = nodes.filter(function innerFunction(node) { - return node.isParent; - }); - - return onlyParents; - }`, - }, - { - code: ` - function test() { - const node = {execute: function named() {}}; - useEffect(function innerFunction() { - node.execute(); - }, []); - return true; - }`, - }, - { - code: ` - function test() { - const node = {execute: () => {}}; - useEffect(function* () { - node.execute(); - }, []); - return true; - }`, - }, - { - code: ` - function test() { - const node = {execute: function named() {}}; - useEffect(node.execute, []); - return true; - } - ` - }, - { - code: ` - function test() { - const node = {execute: () => {}}; - useEffect(node.execute, []); - return true; - } - ` - }, - { - code: ` - function test() { - const node = () => {}; - useEffect(node, []); - return true; - } - ` - }, - { - code: ` - function test() { - const filteringById = () => {}; - parents.filter(filteringById); - return true; - } - ` - }, - { - code: ` - function test() { - function withName() { - return function innerName() {}; - } - withName(); - return true; - } - ` - }, - ], - invalid: [ - { - code: ` - function test() { - const onlyParents = nodes.filter((node) => node.isParent); - - return onlyParents; - } - `, - errors: [{ - message, - }], - }, - { - code: ` - function test() { - const onlyParents = nodes.filter((node) => { - return node.isParent; - }); - - return onlyParents; - } - `, - errors: [{ - message, - }], - }, - { - code: ` - function test() { - const node = {execute: function named() {}}; - useEffect(function () { - node.execute(); - }, []); - return true; - } - `, - errors: [{ - message, - }], - }, - { - code: ` - function test() { - const node = {execute: function named() {}}; - useEffect(() => node.execute(), []); - return true; - } - `, - errors: [{ - message, - }], - }, - { - code: ` - function test() { - const node = {execute: () => {}}; - useEffect(function () {node.execute();} , []); - return true; - } - `, - errors: [{ - message, - }], - }, - { - code: ` - function test() { - function rightNamed() { - return () => {}; - } - rightNamed(); - return true; - } - `, - errors: [{ - message, - }], - }, - { - code: ` - function test() { - function rightNamed() { - return function () {}; - } - rightNamed(); - return true; - } - `, - errors: [{ - message, - }], - }, - { - code: ` - function test() { - const rightNamed = () => { - return function () {}; - } - rightNamed(); - return true; - } - `, - errors: [{ - message, - }], - }, - { - code: ` - function test() { - const rightNamed = () => { - return () => {}; - } - rightNamed(); - return true; - } - `, - errors: [{ - message, - }], - }, - ], -}); diff --git a/rules/expensify.js b/rules/expensify.js index aa6b742..fb5fccd 100644 --- a/rules/expensify.js +++ b/rules/expensify.js @@ -15,7 +15,6 @@ module.exports = { 'rulesdir/no-call-actions-from-actions': 'error', 'rulesdir/no-api-side-effects-method': 'error', 'rulesdir/prefer-localization': 'error', - 'rulesdir/avoid-anonymous-functions': 'error', 'no-restricted-imports': ['error', { paths: [{ name: 'react-native',