eslint / espree

An Esprima-compatible JavaScript parser
BSD 2-Clause "Simplified" License
2.26k stars 189 forks source link

Future of ecmaFeatures.globalReturn #525

Open nzakas opened 2 years ago

nzakas commented 2 years ago

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?

btmills commented 2 years ago

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.

mdjermanovic commented 2 years ago

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

nzakas commented 2 years ago

Marking as accepted.

amareshsm commented 2 years ago

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
nzakas commented 2 years ago

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.

amareshsm commented 6 months ago

Is it good to go now?

nzakas commented 6 months ago

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