Lint: Go-go-gadget jshint! Passing entire JS code base (again).
authorTimo Tijhof <ttijhof@wikimedia.org>
Wed, 26 Sep 2012 07:14:52 +0000 (09:14 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Sat, 10 Nov 2012 11:23:43 +0000 (12:23 +0100)
commit8d306686cf733f3cc424a41959d284827593d540
tree2047572a413ba0c8b4a61ded712ca2f9ecea9518
parent4c8816746ffc9d8baa647d8cbbf4295b40140f75
Lint: Go-go-gadget jshint! Passing entire JS code base (again).

There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.

Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..

Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).

Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.

A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):

* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.

Other fixes:
* Add closures fix implied global errors ($, mw and more),
  and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
  prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
  enforce single quotes (no magic quotes in javascript, as much
  as we might think "\n" and '/n' are really exactly the same).
  Chose single quotes over double quotes since that's what most
  code already had and what conventions seemed to prefer
  (both the old generic ones and the new per-lang ones since
  2011/2012).
* Enforce camelCase variable names with jshint per code
  conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
  (No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
  afterwards is just as possible (significantly faster in
  jQuery due to mostly avoiding the Sizzle engine and going
  native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
  Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.

Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
  (hasn't been in a while!) removed per jshint warning.

* mediawiki.special.recentchanges.js: Was a mess, only a few
  lines of code, rewritten.

Pfew, let's hope it's the last one before we lint from Jenkins!

Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
68 files changed:
.gitignore
.jshintignore
.jshintrc
resources/jquery/jquery.checkboxShiftClick.js
resources/jquery/jquery.client.js
resources/jquery/jquery.collapsibleTabs.js
resources/jquery/jquery.colorUtil.js
resources/jquery/jquery.expandableField.js
resources/jquery/jquery.hidpi.js
resources/jquery/jquery.highlightText.js
resources/jquery/jquery.mw-jump.js
resources/jquery/jquery.mwExtension.js
resources/jquery/jquery.qunit.completenessTest.js
resources/jquery/jquery.suggestions.js
resources/jquery/jquery.textSelection.js
resources/mediawiki.action/mediawiki.action.edit.js
resources/mediawiki.language/mediawiki.cldr.js
resources/mediawiki.language/mediawiki.language.init.js
resources/mediawiki.language/mediawiki.language.js
resources/mediawiki.page/mediawiki.page.ready.js
resources/mediawiki.page/mediawiki.page.watch.ajax.js
resources/mediawiki.special/mediawiki.special.block.js
resources/mediawiki.special/mediawiki.special.javaScriptTest.js
resources/mediawiki.special/mediawiki.special.js
resources/mediawiki.special/mediawiki.special.movePage.js
resources/mediawiki.special/mediawiki.special.preferences.js
resources/mediawiki.special/mediawiki.special.recentchanges.js
resources/mediawiki.special/mediawiki.special.search.js
resources/mediawiki.special/mediawiki.special.undelete.js
resources/mediawiki.special/mediawiki.special.upload.js
resources/mediawiki/mediawiki.Title.js
resources/mediawiki/mediawiki.feedback.js
resources/mediawiki/mediawiki.hidpi.js
resources/mediawiki/mediawiki.htmlform.js
resources/mediawiki/mediawiki.jqueryMsg.js
resources/mediawiki/mediawiki.js
resources/mediawiki/mediawiki.notification.js
resources/mediawiki/mediawiki.util.js
resources/startup.js
tests/qunit/data/callMwLoaderTestCallback.js
tests/qunit/data/generateJqueryMsgData.php
tests/qunit/data/mediawiki.jqueryMsg.data.js
tests/qunit/data/testrunner.js
tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js
tests/qunit/suites/resources/jquery/jquery.byteLength.test.js
tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
tests/qunit/suites/resources/jquery/jquery.client.test.js
tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js
tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js
tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js
tests/qunit/suites/resources/jquery/jquery.hidpi.test.js
tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
tests/qunit/suites/resources/jquery/jquery.localize.test.js
tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js
tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js
tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js
tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.cldr.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js