Skip to content

Commit

Permalink
Merge pull request #7315 from Carreau/codacy2
Browse files Browse the repository at this point in the history
miscellaneous cleanup
  • Loading branch information
minrk committed Jan 3, 2015
2 parents 4b40dd4 + 7c74a0d commit 9603e51
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 82 deletions.
2 changes: 0 additions & 2 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ class InteractiveShell(SingletonConfigurable):
"""
)

banner = Unicode('')

banner1 = Unicode(default_banner, config=True,
help="""The part of the banner to be printed before the profile"""
)
Expand Down
52 changes: 28 additions & 24 deletions IPython/html/static/notebook/js/actions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.

define(['require'
], function(require) {
define(function(require){
"use strict";

var ActionHandler = function (env) {
Expand Down Expand Up @@ -36,7 +35,7 @@ define(['require'
* but is considered undefined behavior.
*
**/
var _action = {
var _actions = {
'run-select-next': {
icon: 'fa-play',
help : 'run cell, select below',
Expand Down Expand Up @@ -387,31 +386,36 @@ define(['require'
// Will actually generate/register all the IPython actions
var fun = function(){
var final_actions = {};
for(var k in _action){
// Js closure are function level not block level need to wrap in a IIFE
// and append ipython to event name these things do intercept event so are wrapped
// in a function that return false.
var handler = _prepare_handler(final_actions, k, _action);
(function(key, handler){
final_actions['ipython.'+key].handler = function(env, event){
handler(env);
if(event){
event.preventDefault();
}
return false;
};
})(k, handler);
var k;
for(k in _actions){
if(_actions.hasOwnProperty(k)){
// Js closure are function level not block level need to wrap in a IIFE
// and append ipython to event name these things do intercept event so are wrapped
// in a function that return false.
var handler = _prepare_handler(final_actions, k, _actions);
(function(key, handler){
final_actions['ipython.'+key].handler = function(env, event){
handler(env);
if(event){
event.preventDefault();
}
return false;
};
})(k, handler);
}
}

for(var k in custom_ignore){
for(k in custom_ignore){
// Js closure are function level not block level need to wrap in a IIFE
// same as above, but decide for themselves wether or not they intercept events.
var handler = _prepare_handler(final_actions, k, custom_ignore);
(function(key, handler){
final_actions['ipython.'+key].handler = function(env, event){
return handler(env, event);
};
})(k, handler);
if(custom_ignore.hasOwnProperty(k)){
var handler = _prepare_handler(final_actions, k, custom_ignore);
(function(key, handler){
final_actions['ipython.'+key].handler = function(env, event){
return handler(env, event);
};
})(k, handler);
}
}

return final_actions;
Expand Down
8 changes: 4 additions & 4 deletions IPython/html/static/notebook/js/codecell.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ define([
var Cell = cell.Cell;

/* local util for codemirror */
var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
var posEq = function(a, b) {return a.line === b.line && a.ch === b.ch;};

/**
*
Expand Down Expand Up @@ -332,7 +332,7 @@ define([
// whatever key is pressed, first, cancel the tooltip request before
// they are sent, and remove tooltip if any, except for tab again
var tooltip_closed = null;
if (event.type === 'keydown' && event.which != keycodes.tab ) {
if (event.type === 'keydown' && event.which !== keycodes.tab ) {
tooltip_closed = this.tooltip.remove_and_cancel_tooltip();
}

Expand Down Expand Up @@ -366,15 +366,15 @@ define([
if (editor.somethingSelected() || editor.getSelections().length !== 1){
var anchor = editor.getCursor("anchor");
var head = editor.getCursor("head");
if( anchor.line != head.line){
if( anchor.line !== head.line){
return false;
}
}
this.tooltip.request(that);
event.codemirrorIgnore = true;
event.preventDefault();
return true;
} else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
} else if (event.keyCode === keycodes.tab && event.type === 'keydown') {
// Tab completion.
this.tooltip.remove_and_cancel_tooltip();

Expand Down
1 change: 0 additions & 1 deletion IPython/html/static/notebook/js/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ define([
* Set the 'Download as foo' menu option for the relevant language.
*/
var el = this.element.find('#download_script');
var that = this;

// Set menu entry text to e.g. "Python (.py)"
var langname = (langinfo.name || 'Script');
Expand Down
14 changes: 7 additions & 7 deletions IPython/html/static/notebook/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ define([
if (value === undefined) {
value = true;
}
if (this.dirty == value) {
if (this.dirty === value) {
return;
}
this.events.trigger('set_dirty.Notebook', {value: value});
Expand Down Expand Up @@ -1792,7 +1792,7 @@ define([
cell_data = new_cells[i];
new_cell = this.insert_cell_at_index(cell_data.cell_type, i);
new_cell.fromJSON(cell_data);
if (new_cell.cell_type == 'code' && !new_cell.output_area.trusted) {
if (new_cell.cell_type === 'code' && !new_cell.output_area.trusted) {
trusted = false;
}
}
Expand All @@ -1818,7 +1818,7 @@ define([
var trusted = true;
for (var i=0; i<ncells; i++) {
var cell = cells[i];
if (cell.cell_type == 'code' && !cell.output_area.trusted) {
if (cell.cell_type === 'code' && !cell.output_area.trusted) {
trusted = false;
}
cell_array[i] = cell.toJSON();
Expand All @@ -1829,7 +1829,7 @@ define([
nbformat: this.nbformat,
nbformat_minor: this.nbformat_minor
};
if (trusted != this.trusted) {
if (trusted !== this.trusted) {
this.trusted = trusted;
this.events.trigger("trust_changed.Notebook", trusted);
}
Expand Down Expand Up @@ -1957,7 +1957,7 @@ define([
// round to 10 seconds, otherwise we will be setting a new interval too often
interval = 10000 * Math.round(interval / 10000);
// set new interval, if it's changed
if (interval != this.autosave_interval) {
if (interval !== this.autosave_interval) {
this.set_autosave_interval(interval);
}
}
Expand Down Expand Up @@ -1997,7 +1997,7 @@ define([
var cells = nb.get_cells();
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
if (cell.cell_type == 'code') {
if (cell.cell_type === 'code') {
cell.output_area.trusted = true;
}
}
Expand Down Expand Up @@ -2264,7 +2264,7 @@ define([
var found = false;
for (var i = 0; i < this.checkpoints.length; i++) {
var existing = this.checkpoints[i];
if (existing.id == checkpoint.id) {
if (existing.id === checkpoint.id) {
found = true;
this.checkpoints[i] = checkpoint;
break;
Expand Down
1 change: 0 additions & 1 deletion IPython/html/static/notebook/js/textcell.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ define([
var cont = Cell.prototype.unrender.apply(this);
if (cont) {
var text_cell = this.element;
var output = text_cell.find("div.text_cell_render");
if (this.get_text() === this.placeholder) {
this.set_text('');
}
Expand Down
7 changes: 4 additions & 3 deletions IPython/html/static/terminal/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require([
page,
terminado
){
"use strict";
page = new page.Page();
// Test size: 25x80
var termRowHeight = function(){ return 1.00 * $("#dummy-screen")[0].offsetHeight / 25;};
Expand All @@ -28,8 +29,8 @@ require([

var header = $("#header")[0]
function calculate_size() {
height = window.innerHeight - header.offsetHeight;
width = $('#terminado-container').width();
var height = window.innerHeight - header.offsetHeight;
var width = $('#terminado-container').width();
var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight())-1));
var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth())-1));
console.log("resize to :", rows , 'rows by ', cols, 'columns');
Expand All @@ -38,7 +39,7 @@ require([

page.show_header();

size = calculate_size();
var size = calculate_size();
var terminal = terminado.make_terminal($("#terminado-container")[0], size, ws_url);

page.show_site();
Expand Down
3 changes: 2 additions & 1 deletion IPython/html/static/terminal/js/terminado.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define ([], function() {
"use strict";
function make_terminal(element, size, ws_url) {
var ws = new WebSocket(ws_url);
var term = new Terminal({
Expand All @@ -21,7 +22,7 @@ define ([], function() {
term.open(element);

ws.onmessage = function(event) {
json_msg = JSON.parse(event.data);
var json_msg = JSON.parse(event.data);
switch(json_msg[0]) {
case "stdout":
term.write(json_msg[1]);
Expand Down
3 changes: 1 addition & 2 deletions IPython/html/static/tree/js/terminallist.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ define([
};

TerminalList.prototype.load_terminals = function() {
var that = this;
var url = utils.url_join_encode(this.base_url, 'api/terminals');
$.ajax(url, {
type: "GET",
Expand All @@ -78,7 +77,7 @@ define([
TerminalList.prototype.terminals_loaded = function (data) {
this.terminals = data;
this.clear_list();
var item, path_name, term;
var item, term;
for (var i=0; i < this.terminals.length; i++) {
term = this.terminals[i];
item = this.new_item(-1);
Expand Down
6 changes: 3 additions & 3 deletions IPython/html/static/widgets/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ define(["widgets/js/manager",
"base/js/utils",
"base/js/namespace",
], function(widgetmanager, _, Backbone, $, utils, IPython){
"use strict";

var WidgetModel = Backbone.Model.extend({
constructor: function (widget_manager, model_id, comm) {
Expand Down Expand Up @@ -175,7 +176,7 @@ define(["widgets/js/manager",

get_state: function() {
// Get the serializable state of the model.
state = this.toJSON();
var state = this.toJSON();
for (var key in state) {
if (state.hasOwnProperty(key)) {
state[key] = this._pack_models(state[key]);
Expand Down Expand Up @@ -587,7 +588,6 @@ define(["widgets/js/manager",
/**
* Update the css styling of this view.
*/
var e = this.$el;
if (css === undefined) {return;}
for (var i = 0; i < css.length; i++) {
// Apply the css traits to all elements that match the selector.
Expand Down Expand Up @@ -705,7 +705,7 @@ define(["widgets/js/manager",
*/
var remove = remove_view || this._remove_view;
var create = create_view || this._create_view;
var context = context || this._handler_context;
context = context || this._handler_context;
var i = 0;
// first, skip past the beginning of the lists if they are identical
for (; i < new_models.length; i++) {
Expand Down
1 change: 1 addition & 0 deletions IPython/html/static/widgets/js/widget_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define([
"base/js/utils",
"bootstrap",
], function(widget, $, utils){
"use strict";

var BoxView = widget.DOMWidgetView.extend({
initialize: function(){
Expand Down
5 changes: 3 additions & 2 deletions IPython/html/static/widgets/js/widget_int.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,12 @@ define([
* Calling model.set will trigger all of the other views of the
* model to update.
*/
var actual_value;
if (this.model.get("_range")) {
var actual_value = ui.values.map(this._validate_slide_value);
actual_value = ui.values.map(this._validate_slide_value);
this.$readout.text(actual_value.join("-"));
} else {
var actual_value = this._validate_slide_value(ui.value);
actual_value = this._validate_slide_value(ui.value);
this.$readout.text(actual_value);
}
this.model.set('value', actual_value, {updated_view: this});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ define([
* Called when view is rendered.
*/
var uuid = 'tabs'+utils.uuid();
var that = this;
this.$tabs = $('<div />', {id: uuid})
.addClass('nav')
.addClass('nav-tabs')
Expand Down
3 changes: 2 additions & 1 deletion IPython/html/tests/notebook/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Test that a Markdown cell is rendered to HTML.
//
casper.notebook_test(function () {
"use strict";
// Test JavaScript models.
var output = this.evaluate(function () {
IPython.notebook.to_markdown();
Expand Down Expand Up @@ -56,7 +57,7 @@ casper.notebook_test(function () {
for (var idx=0; idx < levels.length; idx++) {
var level = levels[idx];
level_text = set_level(level);
hashes = new Array(level + 1).join('#');
var hashes = new Array(level + 1).join('#');
this.test.assertEquals(level_text, hashes + ' ' + text, 'markdown set_heading_level ' + level);
}
});
4 changes: 2 additions & 2 deletions IPython/html/tests/notebook/roundtrip.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var svg = "\"<svg width='1cm' height='1cm' viewBox='0 0 1000 500'><defs><style>r
// represetnation, while the original in-memory cell retains its long mimetype
// name, and that fromJSON also gets its long mimetype name
function assert_has(short_name, json, result, result2) {
long_name = mime[short_name];
var long_name = mime[short_name];
this.test.assertFalse(json[0].data.hasOwnProperty(short_name),
"toJSON() representation doesn't use " + short_name);
this.test.assertTrue(json[0].data.hasOwnProperty(long_name),
Expand All @@ -40,7 +40,7 @@ function assert_has(short_name, json, result, result2) {
// 'png', etc) are not used.
function check_output_area(output_type, keys) {
this.wait_for_output(0);
json = this.evaluate(function() {
var json = this.evaluate(function() {
var json = IPython.notebook.get_cell(0).output_area.toJSON();
// appended cell will initially be empty, let's add some output
IPython.notebook.get_cell(1).output_area.fromJSON(json);
Expand Down
5 changes: 3 additions & 2 deletions IPython/html/tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,9 @@ casper.click_cell_editor = function(index) {
// region of codemirror that the user can focus.
this.evaluate(function (i) {
var cm = IPython.notebook.get_cell(i).code_mirror;
if (cm.options.readOnly != "nocursor" && (document.activeElement != cm.display.input))
if (cm.options.readOnly != "nocursor" && (document.activeElement != cm.display.input)){
cm.display.input.focus();
}
}, {i: index});
};

Expand Down Expand Up @@ -591,7 +592,7 @@ casper.assert_colors_equal = function (hex_color, local_color, msg) {

// If the local color is rgb, clean it up and replace
if (local_color.substr(0,3).toLowerCase() == 'rgb') {
components = local_color.substr(3).split(',');
var components = local_color.substr(3).split(',');
local_color = '';
for (var i = 0; i < components.length; i++) {
var part = parseInt(components[i]).toString(16);
Expand Down

0 comments on commit 9603e51

Please sign in to comment.