tslint-to-eslint-config
tslint-to-eslint-config copied to clipboard
prefer-arrow/prefer-arrow-function: prefer arrow to allow top level named functions as default
🚀 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
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.
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.
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 🚀
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