espree icon indicating copy to clipboard operation
espree copied to clipboard

Future of ecmaFeatures.globalReturn

Open nzakas opened this issue 2 years ago • 7 comments

Problem: globalReturn can't be used with sourceType:module, and right now in ESLint we will detect this combination and set globalReturn to false. Arguably, this behavior is undesirable because ESLint is silently fixing a problem rather than letting the user know that it happened.

We recently just implemented sourceType: commonjs, which effectively makes ecmaFeatures.globalReturn obsolete, so there are several options we could pursue going forward:

  1. We could remove ecmaFeatures.globalReturn altogether. I think this is the cleanest solution now that we have sourceType: commonjs, however, we would probably want to throw an error if ecmaFeatures.globalReturn is specified to let people know that it has been removed.
  2. We could keep ecmaFeatures.globalReturn but throw an error if it is used with sourceType: module. This error would bubble up to ESLint and to the user, allowing them to fix their configuration.

In either case, we could remove the logic from ESLint completely.

Thoughts?

nzakas avatar Nov 29 '21 21:11 nzakas

Option 1 seems cleanest to me as well. We'd be able to give a very clear and actionable error message: ecmaFeatures.globalReturn is gone, so you should set sourceType: "commonjs" instead.

btmills avatar Dec 31 '21 21:12 btmills

If we are not aware of any use cases for globalReturn = true other than commonjs modules, then option 1 seems best to me.

mdjermanovic avatar Jan 27 '22 12:01 mdjermanovic

Marking as accepted.

nzakas avatar Jan 28 '22 01:01 nzakas

I would like to work on this. Is this ready to implement?

Just to confirm my understanding is correct the changes are

  1. Need to remove gloablReturn completely from espree
  2. Throw an error when ecmaFeatures: { globalReturn: true/false } specified in the options

amareshsm avatar May 21 '22 17:05 amareshsm

We aren’t quite ready to implement this yet. We will need to wait for the new config system to roll out and give advance notice before we remove any existing functionality.

nzakas avatar Jun 01 '22 00:06 nzakas

Is it good to go now?

amareshsm avatar Dec 28 '23 18:12 amareshsm

Not yet. This will need to happen in the v10.0.0 timeframe, once the old config system has been removed.

nzakas avatar Dec 28 '23 19:12 nzakas