Page MenuHomePhabricator

Review and update MediaWiki extensions to use most recent ESLint pattern
Closed, DuplicatePublic

Description

Run through MW extensions and check those not using recent ESLint pattern and update them. Example patch, see here: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/MassMessage/+/457451.

Maybe we should have a checklist of them below?

  • extensions/MassMessage
  • extensions/TextExtract
  • extensions/GeoData
  • extensions/GuidedTour
  • extensions/Thanks
  • extensions/SendGrid
  • extensions/WikiEditor
  • extensions/Wikibase
  • extensions/UniversalLanguageSelector
NOTE: Some directories are to be ignored for linting and these should be ignored seen in Gruntfile.js and transferred to package.json.

Event Timeline

D3r1ck01 created this task.Sep 6 2018, 11:08 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 6 2018, 11:08 AM
D3r1ck01 updated the task description. (Show Details)Sep 6 2018, 11:09 AM
D3r1ck01 updated the task description. (Show Details)

Change 458479 had a related patch set uploaded (by D3r1ck01; owner: Alangi Derick):
[mediawiki/extensions/Wikibase@master] Add recent pattern for ESLinting to repo

https://gerrit.wikimedia.org/r/458479

D3r1ck01 updated the task description. (Show Details)Sep 6 2018, 11:10 AM
D3r1ck01 added subscribers: Legoktm, Krinkle.

Change 458474 had a related patch set uploaded (by D3r1ck01; owner: Alangi Derick):
[mediawiki/extensions/WikiEditor@master] Add recent pattern for ESLinting to repo

https://gerrit.wikimedia.org/r/458474

D3r1ck01 moved this task from Doing [WIP] to Backlog on the User-D3r1ck01 board.Sep 6 2018, 11:18 AM

Change 458486 had a related patch set uploaded (by D3r1ck01; owner: Alangi Derick):
[mediawiki/extensions/UniversalLanguageSelector@master] Add recent pattern for ESLinting to repo

https://gerrit.wikimedia.org/r/458486

D3r1ck01 updated the task description. (Show Details)Sep 6 2018, 11:35 AM

This is really ugly. I think we should do the reverse; linting file configuration should be as much as possible in Gruntfile.js, and linting rule configuration in specific files (.eslintrc.json, .stylelintrc.json, …).

Change 458486 merged by jenkins-bot:
[mediawiki/extensions/UniversalLanguageSelector@master] Add recent pattern for ESLinting to repo

https://gerrit.wikimedia.org/r/458486

@Jdforrester-WMF I don't think the file patterns belong in Gruntfile. It's non-standard from the tools perspective in that IDE plugins and the linter's cli tools do not support it. For phpunit we configure the files in a format phpunit understands, for phpcs we use phpcs.xml, for JSHint we used jshintignore. So it makes sense that for ESLint we also use a way that ESLint itself can configure so that if I run eslint . on the project it Just Works.

That leaves us with three options:

  • Specify the patterns to package.json which eslint looks for, just like how it looks for eslintrc.
  • Specify the patterns to a new file, .eslintignore, which eslint also looks for.
  • Specify the patterns on the command line to eslint using --ignore-pattern, and call eslint from npm test script in package.json as eslint . && grunt test, and remove it from Gruntfile entirely.

So far, we've done the first option in a number of repositories. The other options I only discovered later. It seemed to me like a net improvement:

  • No longer hardcoded in Gruntfile, meant it became known to ESLint by standard means for running eslint --fix . and other command line tools and IDE plugins.
  • It made the traversal more efficient by happening inside ESLint lazily instead of ahead of time inside Grunt.
  • It made it impossible to forget to include a new directory by being opt-out instead of opt-in. Although most repos now use **/*.js, during this conversion I also found a few that were opting-in instead of all-in and then exclude. By specifying the excludes separately one is nudged away from that anti-pattern.

Having said that, I'd also be fine with picking one of the other two options, or another method entirely that addresses the above.

I don't think hacking around poor support in IDEs is a good motive for this kind of change, but I grok the desire for eslint . to work for those people who have eslint installed globally (which is a versioning/rules compatibility risk, but that problem is on them). The least-terrible option would be an .eslintignore file, I think.

Change 458479 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Add recent pattern for ESLinting to repo

https://gerrit.wikimedia.org/r/458479

D3r1ck01 updated the task description. (Show Details)Sep 7 2018, 3:19 PM
D3r1ck01 updated the task description. (Show Details)

Change 458474 abandoned by D3r1ck01:
Add recent pattern for ESLinting to repo

Reason:
Thanks @JForrester. Abandoning as discussion is happening here: T204176.

https://gerrit.wikimedia.org/r/458474