Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofix for array-func/from-map results in undesirable behavior #348

Open
maxpatiiuk opened this issue Jan 7, 2023 · 2 comments
Open

Autofix for array-func/from-map results in undesirable behavior #348

maxpatiiuk opened this issue Jan 7, 2023 · 2 comments

Comments

@maxpatiiuk
Copy link

maxpatiiuk commented Jan 7, 2023

Version: 3.1.8
ESLint: 8.31.0
Node.js: 19.3.0

For the following code:

export const uniqueMappingPaths = (
  mappingPaths: RA<MappingPath | undefined>
): RA<MappingPath> =>
  Array.from(
    new Set(filterArray(mappingPaths).map(mappingPathToString)),
    splitJoinedMappingPath
  ).map((path) => (path.length === 1 && path[0] === '' ? [] : path));

ESLint reports:

ESLint: use mapFn callback of Array.from instead of map() (array-func/from-map)

for the Array.from( line.

The autofix turns the above into:

export const uniqueMappingPaths = (
  mappingPaths: RA<MappingPath | undefined>
): RA<MappingPath> =>
  Array.from(
    new Set(filterArray(mappingPaths).map(mappingPathToString)),
    (item, index) => ((path) => (path.length === 1 && path[0] === '' ? [] : path))((splitJoinedMappingPath).call(this, item, index), index)
  );

Which is very much undesired (turns code into an unreadable mess, with an IIFE and this.).
Can't speak of possible performance improvements, but not worth the readability sacrifice.
If this is indeed desired behavior, I would just disable the rule. If not, posting it here to notify you of this behavior.

@maxpatiiuk maxpatiiuk changed the title Autofix for array-func/from-map results in undesirable behavior. Autofix for array-func/from-map results in undesirable behavior Jan 7, 2023
@freaktechnik
Copy link
Owner

That is how the rule is set up to auto fix. This is mostly to make it universally able to combine the two map functions.

@maxpatiiuk
Copy link
Author

I see. Would it be better to disable auto-fix in cases where the auto-fix produces unreadable code?
Just for reference, the autofixed code also creates typescript errors:

Screenshot 2023-01-07 at 07 37 38

Along with several ESLint errors:
Screenshot 2023-01-07 at 07 38 05
Screenshot 2023-01-07 at 07 38 25
Screenshot 2023-01-07 at 07 38 47

Or at least, could you make this behavior an option that can be turned off?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants