Skip to content

Commit fcde821

Browse files
committed
add lint rules and fix errors
1 parent 0e1112f commit fcde821

File tree

14 files changed

+222
-216
lines changed

14 files changed

+222
-216
lines changed

.eslintrc

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44
"$": true
55
},
66
"rules": {
7-
"array-callback-return": "off",
7+
"array-callback-return": "warn",
88
"brace-style": "off",
99
"camelcase": "off",
1010
"comma-dangle": "off",
1111
"consistent-return": "off",
1212
"dot-notation": "off",
13-
"eqeqeq": "off",
13+
"eqeqeq": "error",
1414
"func-names": "off",
15-
"guard-for-in": "off",
15+
"guard-for-in": "warn",
1616
"indent": "off",
1717
"keyword-spacing": "off",
1818
"no-console": "off",
19-
"no-inner-declarations": "off",
20-
"no-loop-func": "off",
21-
"no-mixed-operators": "off",
19+
"no-inner-declarations": "warn",
20+
"no-loop-func": "warn",
21+
"no-mixed-operators": "warn",
2222
"no-multi-assign": "off",
2323
"no-param-reassign": "off",
2424
"no-redeclare": "off",
2525
"no-restricted-syntax": "off",
2626
"no-shadow": "off",
27-
"no-undef": "off",
27+
"no-undef": "warn",
2828
"no-underscore-dangle": "off",
2929
"no-unused-vars": "off",
30-
"no-use-before-define": "off",
30+
"no-use-before-define": "error",
3131
"object-curly-spacing": "off",
32-
"one-var": "off",
32+
"one-var": "error",
3333
"padded-blocks": "off",
3434
"quote-props": "off",
3535
"quotes": "off",

readthedocs/builds/static-src/builds/js/detail.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Build detail view
22

3-
var ko = require('knockout'),
4-
$ = require('jquery');
3+
var ko = require('knockout');
4+
var $ = require('jquery');
55

66

77
function BuildCommand (data) {
@@ -10,7 +10,7 @@ function BuildCommand (data) {
1010
self.command = ko.observable(data.command);
1111
self.output = ko.observable(data.output);
1212
self.exit_code = ko.observable(data.exit_code || 0);
13-
self.successful = ko.observable(self.exit_code() == 0);
13+
self.successful = ko.observable(self.exit_code() === 0);
1414
self.run_time = ko.observable(data.run_time);
1515
self.is_showing = ko.observable(!self.successful());
1616

@@ -26,23 +26,24 @@ function BuildCommand (data) {
2626
}
2727

2828
function BuildDetailView (instance) {
29-
var self = this,
30-
instance = instance || {};
29+
var self = this;
30+
var instance = instance || {};
3131

3232
/* Instance variables */
3333
self.state = ko.observable(instance.state);
3434
self.state_display = ko.observable(instance.state_display);
3535
self.finished = ko.computed(function () {
36-
return self.state() == 'finished';
36+
return self.state() === 'finished';
3737
});
3838
self.date = ko.observable(instance.date);
3939
self.success = ko.observable(instance.success);
4040
self.error = ko.observable(instance.error);
4141
self.length = ko.observable(instance.length);
4242
self.commands = ko.observableArray(instance.commands);
4343
self.display_commands = ko.computed(function () {
44-
var commands_display = [],
45-
commands_raw = self.commands();
44+
var commands_display = [];
45+
var commands_raw = self.commands();
46+
var n;
4647
for (n in commands_raw) {
4748
var command = new BuildCommand(commands_raw[n]);
4849
commands_display.push(command)
@@ -69,12 +70,13 @@ function BuildDetailView (instance) {
6970
self.error(data.error);
7071
self.length(data.length);
7172
self.commit(data.commit);
73+
var n;
7274
for (n in data.commands) {
7375
var command = data.commands[n];
7476
var match = ko.utils.arrayFirst(
7577
self.commands(),
7678
function(command_cmp) {
77-
return (command_cmp.id == command.id);
79+
return (command_cmp.id === command.id);
7880
}
7981
);
8082
if (!match) {
@@ -90,8 +92,8 @@ function BuildDetailView (instance) {
9092
}
9193

9294
BuildDetailView.init = function (instance, domobj) {
93-
var view = new BuildDetailView(instance),
94-
domobj = domobj || $('#build-detail')[0];
95+
var view = new BuildDetailView(instance);
96+
var domobj = domobj || $('#build-detail')[0];
9597
ko.applyBindings(view, domobj);
9698
return view;
9799
};

readthedocs/core/static-src/core/js/autocomplete.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var $ = require('jquery'),
2-
jqueryui = require('jquery-ui');
1+
var $ = require('jquery');
2+
var jqueryui = require('jquery-ui');
33

44
module.exports = function (selector, url) {
55
$(selector).autocomplete({
66
source: url,
77
minLength: 2,
88
open: function(event, ui) {
9-
ac_top = $('.ui-autocomplete').css('top');
9+
var ac_top = $('.ui-autocomplete').css('top');
1010
$('.ui-autocomplete').css({'width': '233px', 'top': ac_top + 10 });
1111
}
1212
});
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,57 @@
1-
var rtddata = require('./rtd-data'),
2-
versionCompare = require('./version-compare'),
3-
sponsorship = require('../sponsorship');
1+
var rtddata = require('./rtd-data');
2+
var versionCompare = require('./version-compare');
3+
var sponsorship = require('../sponsorship');
4+
5+
6+
function injectFooter(data) {
7+
var config = rtddata.get();
8+
9+
// If the theme looks like ours, update the existing badge
10+
// otherwise throw a a full one into the page.
11+
if (config.is_rtd_theme()) {
12+
$("div.rst-other-versions").html(data['html']);
13+
} else {
14+
$("body").append(data['html']);
15+
}
16+
17+
if (!data['version_active']) {
18+
$('.rst-current-version').addClass('rst-out-of-date');
19+
} else if (!data['version_supported']) {
20+
//$('.rst-current-version').addClass('rst-active-old-version')
21+
}
22+
23+
// Show promo selectively
24+
if (data.promo && config.show_promo()) {
25+
var promo = new sponsorship.Promo(
26+
data.promo_data.id,
27+
data.promo_data.text,
28+
data.promo_data.link,
29+
data.promo_data.image,
30+
config.theme,
31+
data.promo_data.display_type,
32+
data.promo_data.pixel
33+
)
34+
if (promo) {
35+
promo.display();
36+
}
37+
}
38+
}
39+
40+
41+
function setupBookmarkCSRFToken() {
42+
function csrfSafeMethod(method) {
43+
// these HTTP methods do not require CSRF protection
44+
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
45+
}
46+
47+
$.ajaxSetup({
48+
beforeSend: function(xhr, settings) {
49+
if (!csrfSafeMethod(settings.type)) {
50+
xhr.setRequestHeader("X-CSRFToken", $('a.bookmark[token]').attr('token'));
51+
}
52+
}
53+
});
54+
}
455

556

657
function init() {
@@ -58,57 +109,6 @@ function init() {
58109
}
59110

60111

61-
function injectFooter(data) {
62-
var config = rtddata.get();
63-
64-
// If the theme looks like ours, update the existing badge
65-
// otherwise throw a a full one into the page.
66-
if (config.is_rtd_theme()) {
67-
$("div.rst-other-versions").html(data['html']);
68-
} else {
69-
$("body").append(data['html']);
70-
}
71-
72-
if (!data['version_active']) {
73-
$('.rst-current-version').addClass('rst-out-of-date');
74-
} else if (!data['version_supported']) {
75-
//$('.rst-current-version').addClass('rst-active-old-version')
76-
}
77-
78-
// Show promo selectively
79-
if (data.promo && config.show_promo()) {
80-
var promo = new sponsorship.Promo(
81-
data.promo_data.id,
82-
data.promo_data.text,
83-
data.promo_data.link,
84-
data.promo_data.image,
85-
config.theme,
86-
data.promo_data.display_type,
87-
data.promo_data.pixel
88-
)
89-
if (promo) {
90-
promo.display();
91-
}
92-
}
93-
}
94-
95-
96-
function setupBookmarkCSRFToken() {
97-
function csrfSafeMethod(method) {
98-
// these HTTP methods do not require CSRF protection
99-
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
100-
}
101-
102-
$.ajaxSetup({
103-
beforeSend: function(xhr, settings) {
104-
if (!csrfSafeMethod(settings.type)) {
105-
xhr.setRequestHeader("X-CSRFToken", $('a.bookmark[token]').attr('token'));
106-
}
107-
}
108-
});
109-
}
110-
111-
112112
module.exports = {
113113
init: init
114114
};

readthedocs/core/static-src/core/js/doc-embed/mkdocs.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function init() {
1010
var rtd = rtddata.get();
1111

1212
// Override MkDocs styles
13-
if ("builder" in rtd && rtd["builder"] == "mkdocs") {
13+
if ("builder" in rtd && rtd["builder"] === "mkdocs") {
1414
$('<input>').attr({
1515
type: 'hidden',
1616
name: 'project',
@@ -30,10 +30,10 @@ function init() {
3030
$("#rtd-search-form").prop("action", rtd.api_host + "/search/");
3131

3232
// Apply stickynav to mkdocs builds
33-
var nav_bar = $('nav.wy-nav-side:first'),
34-
win = $(window),
35-
sticky_nav_class = 'stickynav',
36-
apply_stickynav = function () {
33+
var nav_bar = $('nav.wy-nav-side:first');
34+
var win = $(window);
35+
var sticky_nav_class = 'stickynav';
36+
var apply_stickynav = function () {
3737
if (nav_bar.height() <= win.height()) {
3838
nav_bar.addClass(sticky_nav_class);
3939
} else {

readthedocs/core/static-src/core/js/doc-embed/rtd-data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var configMethods = {
1616
},
1717

1818
is_sphinx_builder: function () {
19-
return (!('builder' in this) || this.builder != 'mkdocs');
19+
return (!('builder' in this) || this.builder !== 'mkdocs');
2020
},
2121

2222
get_theme_name: function () {

readthedocs/core/static-src/core/js/doc-embed/search.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
* Sphinx search overrides
33
*/
44

5-
var rtddata = require('./rtd-data'),
6-
xss = require('xss/lib/index');
7-
8-
9-
function init() {
10-
var data = rtddata.get();
11-
attach_elastic_search_query(data);
12-
}
5+
var rtddata = require('./rtd-data');
6+
var xss = require('xss/lib/index');
137

148

159
/*
@@ -18,14 +12,14 @@ function init() {
1812
* failure,
1913
*/
2014
function attach_elastic_search_query(data) {
21-
var project = data.project,
22-
version = data.version,
23-
language = data.language || 'en',
24-
api_host = data.api_host;
15+
var project = data.project;
16+
var version = data.version;
17+
var language = data.language || 'en';
18+
var api_host = data.api_host;
2519

2620
var query_override = function (query) {
27-
var search_def = $.Deferred(),
28-
search_url = document.createElement('a');
21+
var search_def = $.Deferred();
22+
var search_url = document.createElement('a');
2923

3024
search_url.href = api_host;
3125
search_url.pathname = '/api/v2/docsearch/';
@@ -34,16 +28,16 @@ function attach_elastic_search_query(data) {
3428

3529
search_def
3630
.then(function (results) {
37-
var hits = results.hits || {},
38-
hit_list = hits.hits || [];
31+
var hits = results.hits || {};
32+
var hit_list = hits.hits || [];
3933

4034
if (hit_list.length) {
4135
for (var n in hit_list) {
42-
var hit = hit_list[n],
43-
fields = hit.fields || {},
44-
list_item = $('<li style="display: none;"></li>'),
45-
item_url = document.createElement('a'),
46-
highlight = hit.highlight;
36+
var hit = hit_list[n];
37+
var fields = hit.fields || {};
38+
var list_item = $('<li style="display: none;"></li>');
39+
var item_url = document.createElement('a');
40+
var highlight = hit.highlight;
4741

4842
item_url.href += fields.link +
4943
DOCUMENTATION_OPTIONS.FILE_SUFFIX;
@@ -55,7 +49,7 @@ function attach_elastic_search_query(data) {
5549
.attr('href', item_url)
5650
.html(fields.title)
5751
);
58-
if (fields.project != project) {
52+
if (fields.project !== project) {
5953
list_item.append(
6054
$('<span>')
6155
.text(" (from project " + fields.project + ")")
@@ -101,8 +95,8 @@ function attach_elastic_search_query(data) {
10195
withCredentials: true,
10296
},
10397
complete: function(resp, status_code) {
104-
if (typeof(resp.responseJSON) == 'undefined' ||
105-
typeof(resp.responseJSON.results) == 'undefined') {
98+
if (typeof(resp.responseJSON) === 'undefined' ||
99+
typeof(resp.responseJSON.results) === 'undefined') {
106100
return search_def.reject();
107101
}
108102
return search_def.resolve(resp.responseJSON.results);
@@ -125,6 +119,12 @@ function attach_elastic_search_query(data) {
125119
});
126120
}
127121

122+
123+
function init() {
124+
var data = rtddata.get();
125+
attach_elastic_search_query(data);
126+
}
127+
128128
module.exports = {
129129
init: init
130130
};

0 commit comments

Comments
 (0)