twinkle icon indicating copy to clipboard operation
twinkle copied to clipboard

Linter set to ES5

Open NovemLinguae opened this issue 2 years ago • 14 comments

I notice our linter is set to enforce ES5 and reject any JavaScript features newer than that. This is a little inconvenient to the developer, who has to avoid newer language features such as match, let, class, await, startsWith, endsWith, includes, regex s flag, etc.

Was just wondering what the idea behind keeping the linter on ES5 is. I know Twinkle has 45,000 users or so. I guess the assumption is that a small subset of these folks are using very old browsers that don't support ES6+?

Is it worth the tradeoff? Should we plan to allow ES6 sometime in the future?

NovemLinguae avatar Feb 18 '22 06:02 NovemLinguae

The reason is just that MW gadgets don't yet support ES6. We need https://phabricator.wikimedia.org/T75714 to be resolved first one way or another. It is quite hard to resolve satisfactorily - as it requires introducing a ES6-capable validator. I have a rather hacky patch filed as an interim solution.

siddharthvp avatar Feb 20 '22 14:02 siddharthvp

This patch was +2'd today, opening the door for gadgets to start using ES6. Next Thursday when this deploys, do we want to switch Twinkle over to ES6?

If so, here is our todo list:

  • [ ] Make a post at the interface administrator's noticeboard requesting this change
  • [ ] Reconfigure our linter to allow ES6

NovemLinguae avatar Oct 20 '22 23:10 NovemLinguae

I am on board with this. If @MusikAnimal is also in agreement, @NovemLinguae can you please file the patch for updating the linter reconfiguration, gadget definition file and the README? On-wiki gadget definition change can be handled as part of deployment and IMO doesn't need an IANB post.

siddharthvp avatar Oct 21 '22 15:10 siddharthvp

100% in support! We may kill IE support in doing this, but nowadays that's the intention: https://www.mediawiki.org/wiki/Compatibility/IE11

I'm happy to do the deployment when the time comes. Just ping me.

MusikAnimal avatar Oct 21 '22 18:10 MusikAnimal

I see a bunch of JavaScript versions here. Are these all safe for Twinkle/gadget use now? Or do we need to look into having the linter continue enforcing a block of some of the newer ones?

image

NovemLinguae avatar Oct 21 '22 23:10 NovemLinguae

We're still limited by what the minifier supports, which is ES6 == ES2015 (see https://phabricator.wikimedia.org/T277675). However, we're still able to use Array.includes(), Object.values(), etc which are merely new methods rather than new syntax.

siddharthvp avatar Oct 22 '22 04:10 siddharthvp

On Thursday, I think we want to change https://en.wikipedia.org/wiki/MediaWiki:Gadgets-definition

Twinkle[ResourceLoader|dependencies=ext.gadget.morebits,ext.gadget.select2,mediawiki.api,mediawiki.language|rights=autoconfirmed|type=general|peers=Twinkle-pagestyles]|Twinkle.js|Twinkle.css|twinklearv.js|twinklewarn.js|twinkleblock.js|friendlywelcome.js|friendlyshared.js|friendlytalkback.js|twinklespeedy.js|twinkleprod.js|twinklexfd.js|twinkleimage.js|twinkleprotect.js|friendlytag.js|twinklediff.js|twinkleunlink.js|twinklefluff.js|twinkledeprod.js|twinklebatchdelete.js|twinklebatchprotect.js|twinklebatchundelete.js|twinkleconfig.js

to

Twinkle[ResourceLoader|dependencies=ext.gadget.morebits,ext.gadget.select2,mediawiki.api,mediawiki.language|rights=autoconfirmed|type=general|peers=Twinkle-pagestyles|requiresES6]|Twinkle.js|Twinkle.css|twinklearv.js|twinklewarn.js|twinkleblock.js|friendlywelcome.js|friendlyshared.js|friendlytalkback.js|twinklespeedy.js|twinkleprod.js|twinklexfd.js|twinkleimage.js|twinkleprotect.js|friendlytag.js|twinklediff.js|twinkleunlink.js|twinklefluff.js|twinkledeprod.js|twinklebatchdelete.js|twinklebatchprotect.js|twinklebatchundelete.js|twinkleconfig.js

Right? The change is adding |requiresES6

Can make the change once group2 goes to wmf.7 - https://versions.toolforge.org/

NovemLinguae avatar Oct 26 '22 08:10 NovemLinguae

Yes

siddharthvp avatar Oct 26 '22 10:10 siddharthvp

Done!

MusikAnimal avatar Oct 27 '22 13:10 MusikAnimal

@MusikAnimal. Thank you my friend. Can you also set |requiresES6 for Morebits.js? I think we decided to do that in the pull request.

NovemLinguae avatar Oct 27 '22 22:10 NovemLinguae

Can you also set |requiresES6 for Morebits.js? I think we decided to do that in the pull request.

Is that going to break any other scripts that use Morebits? As in, after we deploy any ES6-only code? I know this isn't MediaWiki proper, but libraries shouldn't normally use ES6 (for now). Maybe we should have a Babel build step for Morebits

MusikAnimal avatar Oct 29 '22 15:10 MusikAnimal

The issue would be that we would need a separate lint config for morebits, and I don't think eslint supports file-specific override for ecmaVersion (though I suppose we could put morebits in a subdir and put another .eslintrc in there).

Morebits isn't much used outside Twinkle. I think the biggest use is DYK-helper with 340 users (which is written by myself - and I'm fine with not having IE11 support for that), the next biggest use is arb.js with 70 users, which is dependent on Twinkle so won't work on IE11 anyway with Twinkle requiring ES6. So I think there's little point in retaining IE11 support in morebits and the costs are not justified.

siddharthvp avatar Oct 29 '22 19:10 siddharthvp

There's a few more I found with Global Search (only enwiki listed below, but there are other results, assuming the ES6 migration will eventually carry over cross-wiki):

  • https://en.wikipedia.org/wiki/User:CAPTAIN%20MEDUSA/Redirect%20Helper.js
  • https://en.wikipedia.org/wiki/User:Abelmoschus%20Esculentus/rater.js
  • https://en.wikipedia.org/wiki/User:Ethanbas/scripts/AFCRHS.js
  • https://en.wikipedia.org/wiki/User:Lee%20Vilenski/FAC-helper.js
  • https://en.wikipedia.org/wiki/User:Jutyaar/common.js
  • https://en.wikipedia.org/wiki/User:This,%20that%20and%20the%20other/ratemath.js
  • https://en.wikipedia.org/wiki/User:ST47/common.js

Some of these seem to be custom extensions to Twinkle/Morebits, which may mean they were fragile or prone to breakage to begin with. I didn't thoroughly review these scripts so it's also possible they won't actually break (maybe only gadgets would?). At any rate, I've no issue with making Morebits ES6-only, but I don't think we should cause breakage, even for personal JS, without some sort of heads up.

In short, if you all are confident, I am too :)

MusikAnimal avatar Oct 29 '22 20:10 MusikAnimal

The issue would be that we would need a separate lint config for morebits, and I don't think eslint supports file-specific override for ecmaVersion (though I suppose we could put morebits in a subdir and put another .eslintrc in there).

Frankly, I've always wondered why Morebits wasn't set up that way. It seems odd to have the source files for a project of this size in the parent directory. A lib/ directory or something might be more appropriate, given the intention of Morebits. I'm not involved or particularly interested in maintaining Morebits as a standalone library, but if others wish it to be that way, it might even make sense as a separate repository. Overall I think the long-term future of Twinkle should look to OOUI and Codex, but I digress.

MusikAnimal avatar Oct 29 '22 20:10 MusikAnimal