tslint-to-eslint-config icon indicating copy to clipboard operation
tslint-to-eslint-config copied to clipboard

prefer-arrow/prefer-arrow-function: prefer arrow to allow top level named functions as default

Open kbrilla opened this issue 3 years ago • 3 comments

🚀 Feature Request

Currently migration will just output notice that top level named functions are disallowed by the plugin, but default tslint behaviour is to allow them. I think default migration should enable allowStandaloneDeclarations configuration parameter of the prefer-arrow/prefer-arrow-functions rule to match tslint rule behaviour.

Existing Behavior

top level function declarations allowed as default

Change Proposal

  "prefer-arrow/prefer-arrow-functions": [
          "error",
          {
            "allowStandaloneDeclarations": true
          }
        ]

as default migration

kbrilla avatar Nov 21 '20 17:11 kbrilla

Did I miss something? AFAIK, the TSLint rule states:

Disallows traditional (non-arrow) function expressions.

And provides an option to allow named functions (allow-named-functions), which I believe is for top-level named functions.

KingDarBoja avatar Nov 21 '20 18:11 KingDarBoja

I'm pretty sure the TsLint rule didn't report such functions, as I had no errors like this while linting. After conversion EsLint is reporting them so they have to be a difference in their behaviors.

kbrilla avatar Nov 21 '20 18:11 kbrilla

i am still not 100% sure about the correct behaviour, tried to understand the differences following this issue at the plugin repository but based on this one, it seems you are right, so feel free to go ahead and make a PR 🚀

KingDarBoja avatar Dec 05 '20 15:12 KingDarBoja

Just following up, I tried out npx tslint index.ts with:

// tslint.json
{
  "rules": {
    "only-arrow-functions": true
  }
}
// index.ts
function myFunc() {

const myFunc = function () {}

...and TSLint did complain by default:

$ npx tslint index.ts
index.ts:1:1
ERROR: 1:1   only-arrow-functions  non-arrow functions are forbidden
ERROR: 3:16  only-arrow-functions  non-arrow functions are forbidden

JoshuaKGoldberg avatar Aug 03 '23 14:08 JoshuaKGoldberg