Closed astorije closed 4 years ago
@astorije Thank you for the detailed issue! I've just created a new commit (https://github.com/TristonJ/eslint-plugin-prefer-arrow/commit/2d631d97dff1bce5d671b505f1f11f761985e703) and
published a new minor version to npm adding a allowStandaloneDeclarations
option.
The option allows function declarations at the top level, but still warns about declarations inside other "inner" scope. For example, with allowStandaloneDeclarations
set to true, this would be valid:
function hello() {
return "world";
}
but the following would throw a warning
function hello() {
// Would warn about the following function
return function() {
return "world";
}
}
Please let me know if this addresses your issue, thanks!
I am going to go ahead and close this issue. If there are bugs or additional requests / thoughts, please open a new issue.
This plugin is an excellent replacement for TSLint's
only-arrow-functions
, as even recommended by thetypescript-eslint
project.However,
only-arrow-functions
has theallow-declarations
option which allows for standalone declarations. In our codebase, we use non-arrow on every top-level function so using this plugin triggers hundreds of violations.I would love to be able to use this rule to disallow the format above, without having to reformat our codebase. What do you think of an additional
allowDeclarations
option?In fact, we were/are using the
recommended
preset oftslint-microsoft-contrib
, which uses this option, so it would make transitioning from TSLint to ESLint even easier :)