From 722bf23518afad6fd90694c17484da33551e4cef Mon Sep 17 00:00:00 2001 From: Nik Nyby Date: Wed, 26 Aug 2015 00:24:55 -0400 Subject: [PATCH] Added linting for JavaScript tests. --- js_tests/admin/DateTimeShortcuts.test.js | 4 +++ js_tests/admin/RelatedObjectLookups.test.js | 5 +++ js_tests/admin/SelectBox.test.js | 6 +++- js_tests/admin/SelectFilter2.test.js | 4 +++ js_tests/admin/actions.test.js | 6 ++++ js_tests/admin/core.test.js | 4 +++ js_tests/admin/inlines.test.js | 4 +++ js_tests/admin/jsi18n-mocks.test.js | 34 +++++++++++++-------- js_tests/admin/timeparse.test.js | 4 +++ package.json | 2 +- 10 files changed, 58 insertions(+), 15 deletions(-) diff --git a/js_tests/admin/DateTimeShortcuts.test.js b/js_tests/admin/DateTimeShortcuts.test.js index fb5f15c5aa..2fc9d9a8c6 100644 --- a/js_tests/admin/DateTimeShortcuts.test.js +++ b/js_tests/admin/DateTimeShortcuts.test.js @@ -1,3 +1,7 @@ +/* global module, test, DateTimeShortcuts */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + module('admin.DateTimeShortcuts'); test('init', function(assert) { diff --git a/js_tests/admin/RelatedObjectLookups.test.js b/js_tests/admin/RelatedObjectLookups.test.js index b2e2e1841b..d2fd3194bb 100644 --- a/js_tests/admin/RelatedObjectLookups.test.js +++ b/js_tests/admin/RelatedObjectLookups.test.js @@ -1,3 +1,8 @@ +/* global module, test, html_unescape, id_to_windowname, + windowname_to_id */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + module('admin.RelatedObjectLookups'); test('html_unescape', function(assert) { diff --git a/js_tests/admin/SelectBox.test.js b/js_tests/admin/SelectBox.test.js index b2e36e0ab2..cb0259d12c 100644 --- a/js_tests/admin/SelectBox.test.js +++ b/js_tests/admin/SelectBox.test.js @@ -1,10 +1,14 @@ +/* global module, test, SelectBox */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + module('admin.SelectBox'); test('init: no options', function(assert) { var $ = django.jQuery; $('').appendTo('#qunit-fixture'); SelectBox.init('id'); - assert.equal(SelectBox.cache['id'].length, 0); + assert.equal(SelectBox.cache.id.length, 0); }); test('filter', function(assert) { diff --git a/js_tests/admin/SelectFilter2.test.js b/js_tests/admin/SelectFilter2.test.js index a06c3ab49c..1aa97958cb 100644 --- a/js_tests/admin/SelectFilter2.test.js +++ b/js_tests/admin/SelectFilter2.test.js @@ -1,3 +1,7 @@ +/* global module, test, SelectFilter */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + module('admin.SelectFilter2'); test('init', function(assert) { diff --git a/js_tests/admin/actions.test.js b/js_tests/admin/actions.test.js index 01e9267b94..d26d16328c 100644 --- a/js_tests/admin/actions.test.js +++ b/js_tests/admin/actions.test.js @@ -1,7 +1,13 @@ +/* global module, test */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + module('admin.actions', { beforeEach: function() { // Number of results shown on page + /* eslint-disable */ window._actions_icnt = '100'; + /* eslint-enable */ var $ = django.jQuery; $('#qunit-fixture').append($('#result-table').text()); diff --git a/js_tests/admin/core.test.js b/js_tests/admin/core.test.js index 044a1d5787..0d6a12d44c 100644 --- a/js_tests/admin/core.test.js +++ b/js_tests/admin/core.test.js @@ -1,3 +1,7 @@ +/* global module, test */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + module('admin.core'); test('Date.getTwelveHours', function(assert) { diff --git a/js_tests/admin/inlines.test.js b/js_tests/admin/inlines.test.js index 1edf2b511c..5fb63813f8 100644 --- a/js_tests/admin/inlines.test.js +++ b/js_tests/admin/inlines.test.js @@ -1,3 +1,7 @@ +/* global module, test */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + module('admin.inlines: tabular formsets', { beforeEach: function() { var $ = django.jQuery; diff --git a/js_tests/admin/jsi18n-mocks.test.js b/js_tests/admin/jsi18n-mocks.test.js index dcd7c67c3e..4858de6eb3 100644 --- a/js_tests/admin/jsi18n-mocks.test.js +++ b/js_tests/admin/jsi18n-mocks.test.js @@ -1,22 +1,30 @@ -(function (globals) { - +(function(globals) { + 'use strict'; var django = globals.django || (globals.django = {}); - django.pluralidx = function (count) { return (count == 1) ? 0 : 1; }; + django.pluralidx = function(count) { return (count === 1) ? 0 : 1; }; /* gettext identity library */ - django.gettext = function (msgid) { return msgid; }; - django.ngettext = function (singular, plural, count) { return (count == 1) ? singular : plural; }; - django.gettext_noop = function (msgid) { return msgid; }; - django.pgettext = function (context, msgid) { return msgid; }; - django.npgettext = function (context, singular, plural, count) { return (count == 1) ? singular : plural; }; + django.gettext = function(msgid) { return msgid; }; + django.ngettext = function(singular, plural, count) { + return (count === 1) ? singular : plural; + }; + django.gettext_noop = function(msgid) { return msgid; }; + django.pgettext = function(context, msgid) { return msgid; }; + django.npgettext = function(context, singular, plural, count) { + return (count === 1) ? singular : plural; + }; - django.interpolate = function (fmt, obj, named) { + django.interpolate = function(fmt, obj, named) { if (named) { - return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])}); + return fmt.replace(/%\(\w+\)s/g, function(match) { + return String(obj[match.slice(2, -2)]); + }); } else { - return fmt.replace(/%s/g, function(match){return String(obj.shift())}); + return fmt.replace(/%s/g, function(match) { + return String(obj.shift()); + }); } }; @@ -60,9 +68,9 @@ "YEAR_MONTH_FORMAT": "F Y" }; - django.get_format = function (format_type) { + django.get_format = function(format_type) { var value = django.formats[format_type]; - if (typeof(value) == 'undefined') { + if (typeof value === 'undefined') { return format_type; } else { return value; diff --git a/js_tests/admin/timeparse.test.js b/js_tests/admin/timeparse.test.js index 86479c4f3f..e5d1b2cf26 100644 --- a/js_tests/admin/timeparse.test.js +++ b/js_tests/admin/timeparse.test.js @@ -1,3 +1,7 @@ +/* global module, test, parseTimeString */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + module('admin.timeparse'); test('parseTimeString', function(assert) { diff --git a/package.json b/package.json index d926bdc5fa..6b8e035c38 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "Django", "private": true, "scripts": { - "pretest": "eslint django/", + "pretest": "eslint django/ js_tests/admin/", "test": "grunt test --verbose" }, "devDependencies": {