Commit graph

35 commits

Author SHA1 Message Date
Ed Sanders
9e234e6a37 eslint: Only apply client rules to client files
Change-Id: I757b9616ce69b6020e9f0e556e006d39de59eb01
2022-02-09 02:40:11 +00:00
Ed Sanders
4a1d5c8cd3 eslint: Remove no-shadow setting, already set upstream
Change-Id: I278117d3b1e4bccf7d083b2757972fb73a458e0e
2021-06-05 14:50:18 +01:00
libraryupgrader
c08a03ee4f build: Updating npm dependencies
* ini: 1.3.5 → 1.3.8
  * https://npmjs.com/advisories/1589

Additional changes:
* Removed useless -p option to phpcbf in "composer fix" command.
* Set `root: true` in .eslintrc.json (T206485).

Change-Id: I0116578751fd73e43b07c2830adc629f4b85c784
2021-01-03 15:27:57 -08:00
James D. Forrester
64ba8d6ea5 eslint: Move mediawiki/valid-package-file-require disables inline
Change-Id: I5af1fcb5b77106671fbb684158027870211b8186
2020-08-26 19:54:52 +01:00
Ed Sanders
0414e3b764 eslint: Enforce no-shadow for variable shadowing
Change-Id: I1ffff6d103f7a4ca56afee3a910d9b3fee6eb72f
2020-06-24 13:28:46 +01:00
Ed Sanders
ceb2cd2fe8 build: Update eslint-config-wikimedia to 0.16.2
Use jsduck config.

Change-Id: I3a1a0c8f0ca535c9661b3774498866fdb98a4255
2020-06-18 19:12:10 +00:00
Ed Sanders
ceb93b4d3b Replace @context with @this
@context is a jsduck custom tag used in very few places.
Rename to @this to make migrating to JSDoc easier.

Change-Id: I10394e85354b7002d96e0fa1af1cb7ae7534db8d
2020-06-15 21:49:06 +01:00
Ed Sanders
fb6c6f779b eslint: Remove duplicate OO global, now upstream
Change-Id: I6e99919e6c6d3ff76c081a77c57f0d6915cd9031
2020-06-08 23:25:40 +01:00
Ed Sanders
8b720e9bd6 eslint: Update to eslint-config-wikimedia 0.16.0
* valid-jsdoc replaced with jsdoc plugin
* New /selenium config

Change-Id: I471eebac0312cb25c539c3f6a3ecfc7cfd4ed8d6
2020-06-02 21:32:56 +01:00
Ed Sanders
765a4559bf eslint: Remove quote-props override, already set upstream
This rule is the same as it is set in eslit-config-wikimedia.

Change-Id: Ie275444481ace90e06398b0ad8bf1bc295899061
2020-04-16 20:24:01 +00:00
Ed Sanders
c28c56212d build: Fix mediawiki/class-doc errors and enable
Change-Id: I39003ea454be3ca449dd0795adf4b98a07faee54
2020-04-15 19:27:56 -07:00
Roan Kattouw
bed84e3281 build: Provide linting for .vue files from upstream
Was first attempted in f1eaa06d5e,
and reverted in 0b3fe4fe8c. Now this
is done in eslint-config-wikimedia for all repos.

Change-Id: I9ee735eef40085b6373b565838d67e186e438657
2020-04-15 17:40:31 -07:00
Catrope
0b3fe4fe8c Revert "build: Linting for .vue files"
This reverts commit f1eaa06d5e.

Reason for revert: accidentally allowed ES6 syntax.
Looking for a way to redo this that doesn't break our linting as badly.

Change-Id: I78974b97001bdbea9aff5717c69d71b8a2582ade
2020-03-30 18:08:22 -07:00
Roan Kattouw
f1eaa06d5e build: Linting for .vue files
Install eslint-plugin-vue, which lints JS inside <script> blocks in
.vue files, and also lints Vue templates. Configure eslint and stylelint
to run on .vue files. stylelint automatically picks up on CSS in <style>
tags.

You may have to change a setting in your text editor or IDE to make it
run eslint and stylelint in .vue files. For eslint, see
https://eslint.vuejs.org/user-guide/#editor-integrations ; for
stylelint, I had to install the linter-stylelint-plus Atom plugin then
add source.css.embedded.html to the "Base Scopes" setting for that
plugin.

Change-Id: I7e6a13317792fc25c29106739b0c24864fd8d301
2020-02-05 18:51:39 -08:00
Ed Sanders
3c2cea4559 build: Update linters and fix errors
Change-Id: Ieb1eff174f5168bf6c9e9aaeb58ec1a1bcd33538
2019-10-23 11:22:41 +01:00
Ed Sanders
7b9bb6f7d6 Use plugin to ensure all message keys are documented
Bug: T235502
Change-Id: If77ddf2caf667504bd0f7e0150649745ae31c4e2
2019-10-21 17:05:40 +01:00
Ed Sanders
9097f95ecc build: Update eslint-config-wikimedia to 0.11.0
Change-Id: Iee025a518962e68c5ec2c07d952f402cd2a7f69b
2019-02-20 23:36:03 +00:00
Ed Sanders
b3e490bba6 build: Update eslint-config-wikimedia to 0.10.0
Change-Id: I2930bcabeeb7b7b2eb36063e77b26e664a691b43
2019-01-08 17:40:11 +00:00
Ed Sanders
7ed0113e3f eslint: Drop 'dot-notation' rule
Bug: T210552
Change-Id: I07620ed2e3a1acfd3193e411c8369722ae751ffa
2018-11-27 22:36:25 +00:00
Ed Sanders
3e4e0a5774 build: Use eslint-config-wikimedia v0.9.0 and make pass
Change-Id: I7b5d228a3de4b3006751a427dec907a5bebf2f51
2018-11-23 14:20:24 +00:00
Bartosz Dziewoński
6ad73362f3 eslintrc: Disallow calling String/Array/Object methods introduced in ES6 or later
This aims to disallow using the methods listed below, which are
supported by Chromium 69 but not supported by Internet Explorer 11.
Most of them were introduced in ECMAScript 6, but some are more recent
or experimental.

We keep breaking IE 11 support by using them. Recent examples include:
* mediawiki/core:
  Ic85063dfbbcf26a99d343845c9fb801f1888d750
* mediawiki/extensions/MultimediaViewer:
  I0954c42a37668b0eb46c3e864a2e13152a6dc68a
* mediawiki/extensions/UploadWizard:
  I70d37a8f0abcc96b5e39fa71a93cda6f3421c87c
* VisualEditor/VisualEditor:
  Ic1971549da37091c41a847229d18e95aff5c9952

This will unfortunately almost certainly cause false positives, but
hopefully not too many of them. Common false positives can be
disallowed more precisely using 'no-restricted-syntax' rather than
'no-restricted-properties'.

Disallowed methods:
    String.prototype:
        codePointAt
        endsWith
        includes
        normalize
        padEnd                    (ES 2017)
        padStart                  (ES 2017)
        repeat
        startsWith
        trimEnd                   (experimental/proposed)
        trimLeft                  (experimental/proposed)
        trimRight                 (experimental/proposed)
        trimStart                 (experimental/proposed)
    Array.prototype:
        copyWithin
        entries
        fill
        find
        findIndex
        flat                      (experimental/proposed)
        flatMap                   (experimental/proposed)
        includes                  (ES 2016)
        keys
        values
    String:
        fromCodePoint
        raw
    Array:
        from
        of
    Object:
        assign
        entries                   (ES 2017)
        getOwnPropertyDescriptors (ES 2017)
        getOwnPropertySymbols
        is
        values                    (ES 2017)

I compiled the list based on running the following code in each
browser's console, since there doesn't seem to be an authoritative
list anywhere on the Internet:

    console.log( Object.getOwnPropertyNames( String.prototype ) )
    console.log( Object.getOwnPropertyNames( Array.prototype ) )
    console.log( Object.getOwnPropertyNames( Object.prototype ) )
    console.log( Object.getOwnPropertyNames( String ) )
    console.log( Object.getOwnPropertyNames( Array ) )
    console.log( Object.getOwnPropertyNames( Object ) )

Change-Id: Ic44c79834f99c52863fbc544ad657787f70fb9bb
2018-11-07 07:32:40 -08:00
Timo Tijhof
add9bd191f resources: Strip '$' and 'mw' from file closures
Follows-up Id6d13bbea6:
- '$': mw.loader.implement does this already.
- 'mw': Use the canonical name directly.

This replaces the following patterns:

File closures (common):
- `( function ( $, mw ) {`     => `( function () {`
- `( function ( $ ) {`         => `( function () {`
- `( function ( mw ) {`        => `( function () {`
- `( function ( mw, $ ) {`     => `( function () {`

File closures (rare):
- `( function ( mw, $, OO ) {`    => `( function () {`
- `( function ( mw, OO, $ ) {`    => `( function () {`
- `( function ( mw, document ) {` => `( function () {`

Combined dom-ready and file closure (rare):
- `jQuery( function ( $ ) {` => `$( function () {
- `jQuery( function () {` => `$( function () {

Remaining references in files without a closure, as found by
the new ESLint setting (rare):
- `jQuery`    => `$`
- `mediaWiki` => `mw`

Change-Id: I7cf2426cde597259e8c6f3f6f615a1a81a0ca82b
2018-09-14 00:59:27 +01:00
jdlrobson
1ded08465b Hygiene: Discourage use of $.each
Even though Array.prototype.forEach only works on arrays, and
$.each is more generic, I think it makes sense to begin discouraging
the usage of $.each now. This can be overriden by ignore lines or
by Array.prototype.forEach compatible lines. This doesn't seem too
much of an ask of engineers and helps future migrations

Bug: T200877
Change-Id: I339cff311a830699c8e32f07cec338a39870c53f
2018-09-05 17:21:29 -07:00
Fomafix
ebc8598918 Replace $.proxy by Function.prototype.bind
Also prevent further usage by an eslint rule.

jQuery.proxy is deprecated:
* https://github.com/jquery/jquery/issues/2958

Bug: T200877
Change-Id: I3a4977f9b90c2104db320d2d939a1cbaa1819de0
2018-09-05 20:50:11 +00:00
jenkins-bot
13e8478a63 Merge "resourceloader: Remove obsolete aliases from closure" 2018-09-04 12:54:21 +00:00
petarpetkovic
f7c7b84589 Remove jQuery.inArray usages
Replace jQuery.inArray with Array.prototype.indexOf.

Also enforce this via eslint rule.

Bug: T200877
Change-Id: Idbd06e6a1681300c4ab9142c7b57e4376f474041
2018-09-03 13:19:14 +02:00
Timo Tijhof
91f950d6b0 resourceloader: Remove obsolete aliases from closure
== jQuery

ResourceLoader wraps and executes all modules in the system via
a closure that explicitly binds '$', 'jQuery'. This means there is
no point in aliasing jQuery to $ in every single file.
ResourceLoader already does this.

This is a very very old habit that was introduced in 2009 when we
didn't have ResourceLoader and were concerned with wikis loading
their own copy of jQuery that could redefine the global 'jQuery'
and '$' variables. We simply hoped that "our module" initialised
before "that module" cache the reference we got in the file closure.

Then in 2010, when building ResourceLoader, we found this didn't
always work. And we also sometimes forgot to add the closure.
Which is why in 2010 (before ResourceLoader went to prod, in 2011)
we fixed the above issue in ResourceLoader itself by "magically"
providing a private binding to '$' and 'jQuery' in every
mw.loader.implement() closure. (r79246, bd93eeb85).

So, these in-file closure references are redundant.
And have been since 2010.

== jQuery, again.

While redundant, they remained in most files. Harmless, right?

However, that same problem of duplicate jQuery copys on a page
came up again in 2013. Why did our magic binding not work?

It was *because* the file also did its own binding:

1. ResourceLoader stores reference to proper jQuery.
2. ResourceLoader provides private reference to it as '$'.
3. .. time passes ..
4. Module executes, and is given the proper jQuery via the
  private '$' reference. The module file ignores this because
  it instead looks up current jQuery, and caches that.

So, we expande the magic binding to also bind the name 'jQuery'.
(2013-2014; 5742c1f385).

== mediaWiki

We export the binding as 'mw' and 'mediaWiki'. We internally
mostly use 'mw' (in HTML, and documentation, and the canonical
name in the JSDuck index). But, rather than using the shorter name,
we use the longer name and alias it in every single file.

There was never a concern about this global being redefined
as far as I know. However, if that happens one day, we should..
provide a magic binding for it.

Change-Id: Id6d13bbea6927a4c7354ca1edd98f13f0fae30c1
2018-08-30 16:21:04 +00:00
jdlrobson
160fc196fe Fix eslint warnings and switch to error code
Follow up to I4552191f639b1022cb085ef5eb4abda835c2d91c

* Add eslint-ignores to various files
* Correct various uses of isFunction, trim, map, grep
where easy fix is available
* Switch from eslint warning to error

Bug: T200877
Change-Id: I8420db21e548772332e51769aa8ec92d5958715f
2018-08-14 16:13:44 -07:00
jdlrobson
93976b5c34 Warn against certain jQuery methods
For time being these messages will warn.

In a follow up, I plan to fix issues and
add eslint-ignore lines and make this
error rather than warn.

Bug: T200877
Change-Id: I4552191f639b1022cb085ef5eb4abda835c2d91c
2018-08-10 11:02:07 -07:00
James D. Forrester
70fe08d2df build: Enable and make pass no-prototype-builtins
Change-Id: I26a98be16c005c1c864ec592e1a41b44943f8f29
2018-07-05 17:36:01 -07:00
James D. Forrester
6450fc980b build: Upgrade eslint to 5.x
Add two exceptions for max-len and no-prototype-builtins.

Change-Id: I5d3f7a3e282a237fb5de9f0eb29b579a08c32652
2018-07-05 16:58:14 -07:00
Timo Tijhof
96f40f152a qunit: Make eslint config pass on qunit test files
Follows-up c0fb8a8836, I890e6e49b.

* Disable 'qunit' env in general source code. And re-declare
  locally in the few src files that use it properly.

* Create separate eslint config for tests/qunit with various
  rules disabled (e.g. valid-jsdoc and es3-keywords).

Change-Id: I37ccec2019de55edfee92697eb80478df7cb6220
2017-02-22 11:15:40 -08:00
Timo Tijhof
e7d3bce00f resourceloader: Use perf.now() for mediaWikiLoadStart in startup.js
Currently we're using 'new Date' which is less accurate for high accuracy
performance measures. On top of that, we are actually using performance.now()
in Navigation Timing to measure mediaWikiLoadEnd, and subsequently
relating it to mediaWikiLoadStart to produce mediaWikiLoadComplete.

Mixing Date and performance.now produces inaccurate results since the
two are usually not in sync. See T153819 for further details.

Solve this by moving the polyfil to startup.js instead.

Also add a basic unit test for mw.now().

Bug: T153819
Change-Id: Ib44538155aa9ba432ec4c58b09ead5333a3a942d
2017-02-09 22:03:14 +00:00
Ed Sanders
2231d4e859 eslint: Re-enable valid-jsdoc and make a pass
Change-Id: I5c3c942d5a9c51628619227c4bbaefd1d92a842d
2016-11-17 13:06:07 -08:00
Ed Sanders
c0fb8a8836 build: Replace jscs+jshint with eslint
Change-Id: Id0a23c03aabadfaf2ec705528ae4b3bd0908fa3e
2016-11-15 15:15:52 -08:00