Page MenuHomePhabricator

API-powered linting for JavaScript using Peast
Open, Needs TriagePublic

Description

This task is about the JavaScript portion of T394965: Provide API-powered linting of supported languages in CodeMirror. See parent task for details applicable to all modes/languages we plan to support.

The Peast PHP package is what is used to validate on-wiki JS. It looks like in order to make it available to client, we'll need to create our own API module for it and call Peast::ES2017() directly.

Testing needs to be done to see if this is quick enough to query continuously in the background, like we are doing for T407153. If it's too slow, linting can be provided by a call-to-action (keyboard shortcut, or a button in the WikiEditor toolbar).

Event Timeline

Please note Wikifunction's implementation code editor uses ES2023 instead of ES2017.

Change #1219938 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/CodeMirror@master] Add API module for server-side content validation

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

Change #1219938 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Add API module for server-side content validation

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

@SD0001 Thank you for creating the new API modules!

Do you know how we can determine whether a JavaScript page should pass Peast (so that we should use the Peast API for linting)?

The list of pages that need to pass can be obtained by going through every WikiModule in the module registry and calling getPages() on them. This isn't exposed client-side, but it can be done within the API implementation. Not sure how we want to expose it:

  • Validate to ES2017 for pages needing to pass Peast, and ES2024 for other pages? (The API caller won't be able to tell what standard was used for validation.)
  • Send error code syntax-error for issues on pages that need to be compliant, and syntax-warning for other pages?

The other way is to just do some pattern-matching: MediaWiki:Gadget-*.js, MediaWiki:(common|<skin>).js, MediaWiki:Group-<group>.js, User:<username>/(common|<skin>).js. But this would miss WikiModules registered by other extensions (eg. MediaWiki:WikiLove.js, MediaWiki:Kartographer.js, User:<username>/global.js) unless we do a lot of special cases and checking of installed extensions.

  • Validate to ES2017 for pages needing to pass Peast, and ES2024 for other pages?
  • Send error code syntax-error for issues on pages that need to be compliant, and syntax-warning for other pages?

I think we can just skip pages that will not be processed by ResourceLoader.

Change #1226290 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/CodeMirror@master] api: return Peast errors only for pages that need to pass validation

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