Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eslint rules and fix errors #3726

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
"$": true
},
"rules": {
"array-callback-return": "off",
"array-callback-return": "warn",
"brace-style": "off",
"camelcase": "off",
"comma-dangle": "off",
"consistent-return": "off",
"dot-notation": "off",
"eqeqeq": "off",
"eqeqeq": "error",
"func-names": "off",
"guard-for-in": "off",
"guard-for-in": "warn",
"indent": "off",
"keyword-spacing": "off",
"no-console": "off",
"no-inner-declarations": "off",
"no-loop-func": "off",
"no-mixed-operators": "off",
"no-inner-declarations": "warn",
"no-loop-func": "warn",
"no-mixed-operators": "warn",
"no-multi-assign": "off",
"no-param-reassign": "off",
"no-redeclare": "off",
"no-restricted-syntax": "off",
"no-shadow": "off",
"no-undef": "off",
"no-undef": "warn",
"no-underscore-dangle": "off",
"no-unused-vars": "off",
"no-use-before-define": "off",
"no-use-before-define": "error",
"object-curly-spacing": "off",
"one-var": "off",
"one-var": "error",
"padded-blocks": "off",
"quote-props": "off",
"quotes": "off",
Expand Down
24 changes: 13 additions & 11 deletions readthedocs/builds/static-src/builds/js/detail.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Build detail view

var ko = require('knockout'),
$ = require('jquery');
var ko = require('knockout');
var $ = require('jquery');


function BuildCommand (data) {
Expand All @@ -10,7 +10,7 @@ function BuildCommand (data) {
self.command = ko.observable(data.command);
self.output = ko.observable(data.output);
self.exit_code = ko.observable(data.exit_code || 0);
self.successful = ko.observable(self.exit_code() == 0);
self.successful = ko.observable(self.exit_code() === 0);
self.run_time = ko.observable(data.run_time);
self.is_showing = ko.observable(!self.successful());

Expand All @@ -26,23 +26,24 @@ function BuildCommand (data) {
}

function BuildDetailView (instance) {
var self = this,
instance = instance || {};
var self = this;
var instance = instance || {};

/* Instance variables */
self.state = ko.observable(instance.state);
self.state_display = ko.observable(instance.state_display);
self.finished = ko.computed(function () {
return self.state() == 'finished';
return self.state() === 'finished';
});
self.date = ko.observable(instance.date);
self.success = ko.observable(instance.success);
self.error = ko.observable(instance.error);
self.length = ko.observable(instance.length);
self.commands = ko.observableArray(instance.commands);
self.display_commands = ko.computed(function () {
var commands_display = [],
commands_raw = self.commands();
var commands_display = [];
var commands_raw = self.commands();
var n;
for (n in commands_raw) {
var command = new BuildCommand(commands_raw[n]);
commands_display.push(command)
Expand All @@ -69,12 +70,13 @@ function BuildDetailView (instance) {
self.error(data.error);
self.length(data.length);
self.commit(data.commit);
var n;
for (n in data.commands) {
var command = data.commands[n];
var match = ko.utils.arrayFirst(
self.commands(),
function(command_cmp) {
return (command_cmp.id == command.id);
return (command_cmp.id === command.id);
}
);
if (!match) {
Expand All @@ -90,8 +92,8 @@ function BuildDetailView (instance) {
}

BuildDetailView.init = function (instance, domobj) {
var view = new BuildDetailView(instance),
domobj = domobj || $('#build-detail')[0];
var view = new BuildDetailView(instance);
var domobj = domobj || $('#build-detail')[0];
ko.applyBindings(view, domobj);
return view;
};
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/core/static-src/core/js/autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var $ = require('jquery'),
jqueryui = require('jquery-ui');
var $ = require('jquery');
var jqueryui = require('jquery-ui');

module.exports = function (selector, url) {
$(selector).autocomplete({
source: url,
minLength: 2,
open: function(event, ui) {
ac_top = $('.ui-autocomplete').css('top');
var ac_top = $('.ui-autocomplete').css('top');
$('.ui-autocomplete').css({'width': '233px', 'top': ac_top + 10 });
}
});
Expand Down
108 changes: 54 additions & 54 deletions readthedocs/core/static-src/core/js/doc-embed/footer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
var rtddata = require('./rtd-data'),
versionCompare = require('./version-compare'),
sponsorship = require('../sponsorship');
var rtddata = require('./rtd-data');
var versionCompare = require('./version-compare');
var sponsorship = require('../sponsorship');


function injectFooter(data) {
var config = rtddata.get();

// If the theme looks like ours, update the existing badge
// otherwise throw a a full one into the page.
if (config.is_rtd_theme()) {
$("div.rst-other-versions").html(data['html']);
} else {
$("body").append(data['html']);
}

if (!data['version_active']) {
$('.rst-current-version').addClass('rst-out-of-date');
} else if (!data['version_supported']) {
//$('.rst-current-version').addClass('rst-active-old-version')
}

// Show promo selectively
if (data.promo && config.show_promo()) {
var promo = new sponsorship.Promo(
data.promo_data.id,
data.promo_data.text,
data.promo_data.link,
data.promo_data.image,
config.theme,
data.promo_data.display_type,
data.promo_data.pixel
)
if (promo) {
promo.display();
}
}
}


function setupBookmarkCSRFToken() {
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", $('a.bookmark[token]').attr('token'));
}
}
});
}


function init() {
Expand Down Expand Up @@ -58,57 +109,6 @@ function init() {
}


function injectFooter(data) {
var config = rtddata.get();

// If the theme looks like ours, update the existing badge
// otherwise throw a a full one into the page.
if (config.is_rtd_theme()) {
$("div.rst-other-versions").html(data['html']);
} else {
$("body").append(data['html']);
}

if (!data['version_active']) {
$('.rst-current-version').addClass('rst-out-of-date');
} else if (!data['version_supported']) {
//$('.rst-current-version').addClass('rst-active-old-version')
}

// Show promo selectively
if (data.promo && config.show_promo()) {
var promo = new sponsorship.Promo(
data.promo_data.id,
data.promo_data.text,
data.promo_data.link,
data.promo_data.image,
config.theme,
data.promo_data.display_type,
data.promo_data.pixel
)
if (promo) {
promo.display();
}
}
}


function setupBookmarkCSRFToken() {
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", $('a.bookmark[token]').attr('token'));
}
}
});
}


module.exports = {
init: init
};
10 changes: 5 additions & 5 deletions readthedocs/core/static-src/core/js/doc-embed/mkdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function init() {
var rtd = rtddata.get();

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

// Apply stickynav to mkdocs builds
var nav_bar = $('nav.wy-nav-side:first'),
win = $(window),
sticky_nav_class = 'stickynav',
apply_stickynav = function () {
var nav_bar = $('nav.wy-nav-side:first');
var win = $(window);
var sticky_nav_class = 'stickynav';
var apply_stickynav = function () {
if (nav_bar.height() <= win.height()) {
nav_bar.addClass(sticky_nav_class);
} else {
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/static-src/core/js/doc-embed/rtd-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var configMethods = {
},

is_sphinx_builder: function () {
return (!('builder' in this) || this.builder != 'mkdocs');
return (!('builder' in this) || this.builder !== 'mkdocs');
},

get_theme_name: function () {
Expand Down
48 changes: 24 additions & 24 deletions readthedocs/core/static-src/core/js/doc-embed/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
* Sphinx search overrides
*/

var rtddata = require('./rtd-data'),
xss = require('xss/lib/index');


function init() {
var data = rtddata.get();
attach_elastic_search_query(data);
}
var rtddata = require('./rtd-data');
var xss = require('xss/lib/index');


/*
Expand All @@ -18,14 +12,14 @@ function init() {
* failure,
*/
function attach_elastic_search_query(data) {
var project = data.project,
version = data.version,
language = data.language || 'en',
api_host = data.api_host;
var project = data.project;
var version = data.version;
var language = data.language || 'en';
var api_host = data.api_host;

var query_override = function (query) {
var search_def = $.Deferred(),
search_url = document.createElement('a');
var search_def = $.Deferred();
var search_url = document.createElement('a');

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

search_def
.then(function (results) {
var hits = results.hits || {},
hit_list = hits.hits || [];
var hits = results.hits || {};
var hit_list = hits.hits || [];

if (hit_list.length) {
for (var n in hit_list) {
var hit = hit_list[n],
fields = hit.fields || {},
list_item = $('<li style="display: none;"></li>'),
item_url = document.createElement('a'),
highlight = hit.highlight;
var hit = hit_list[n];
var fields = hit.fields || {};
var list_item = $('<li style="display: none;"></li>');
var item_url = document.createElement('a');
var highlight = hit.highlight;

item_url.href += fields.link +
DOCUMENTATION_OPTIONS.FILE_SUFFIX;
Expand All @@ -55,7 +49,7 @@ function attach_elastic_search_query(data) {
.attr('href', item_url)
.html(fields.title)
);
if (fields.project != project) {
if (fields.project !== project) {
list_item.append(
$('<span>')
.text(" (from project " + fields.project + ")")
Expand Down Expand Up @@ -101,8 +95,8 @@ function attach_elastic_search_query(data) {
withCredentials: true,
},
complete: function(resp, status_code) {
if (typeof(resp.responseJSON) == 'undefined' ||
typeof(resp.responseJSON.results) == 'undefined') {
if (typeof(resp.responseJSON) === 'undefined' ||
typeof(resp.responseJSON.results) === 'undefined') {
return search_def.reject();
}
return search_def.resolve(resp.responseJSON.results);
Expand All @@ -125,6 +119,12 @@ function attach_elastic_search_query(data) {
});
}


function init() {
var data = rtddata.get();
attach_elastic_search_query(data);
}

module.exports = {
init: init
};
Loading