Merge pull request #7315 from Carreau/codacy2

miscellaneous cleanup
This commit is contained in:
Min RK 2015-01-03 12:22:45 -08:00
commit ffaa09492a
18 changed files with 67 additions and 59 deletions

View File

@ -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) {
@ -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',
@ -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;

View File

@ -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;};
/**
*
@ -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();
}
@ -366,7 +366,7 @@ 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;
}
}
@ -374,7 +374,7 @@ define([
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();

View File

@ -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');

View File

@ -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});
@ -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;
}
}
@ -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();
@ -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);
}
@ -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);
}
}
@ -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;
}
}
@ -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;

View File

@ -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('');
}

View File

@ -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;};
@ -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');
@ -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();

View File

@ -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({
@ -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]);

View File

@ -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",
@ -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);

View File

@ -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) {
@ -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]);
@ -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.
@ -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++) {

View File

@ -7,6 +7,7 @@ define([
"base/js/utils",
"bootstrap",
], function(widget, $, utils){
"use strict";
var BoxView = widget.DOMWidgetView.extend({
initialize: function(){

View File

@ -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});

View File

@ -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')

View File

@ -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();
@ -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);
}
});

View File

@ -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),
@ -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);

View File

@ -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});
};
@ -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);

View File

@ -1,5 +1,6 @@
// Test widget bool class
casper.notebook_test(function () {
"use strict";
// Create a checkbox and togglebutton.
var bool_index = this.append_cell(
@ -57,7 +58,7 @@ casper.notebook_test(function () {
});
// Try changing the state of the widgets programatically.
index = this.append_cell(
var index = this.append_cell(
'bool_widgets[0].value = False\n' +
'bool_widgets[1].value = False\n' +
'print("Success")');
@ -88,4 +89,4 @@ casper.notebook_test(function () {
'Toggle button is toggled. (3)');
});
});
});

View File

@ -1,6 +1,7 @@
// Test image class
casper.notebook_test(function () {
index = this.append_cell(
"use strict";
var index = this.append_cell(
'from IPython.html import widgets\n' +
'from IPython.display import display, clear_output\n' +
'print("Success")');
@ -45,4 +46,4 @@ casper.notebook_test(function () {
var img_src = this.cell_element_function(image_index, img_selector, 'attr', ['src']);
this.test.assert(img_src.indexOf(test_jpg) > -1, 'Image src data exists.');
});
});
});

View File

@ -298,7 +298,7 @@ if 'setuptools' in sys.modules:
if 'bdist_wininst' in sys.argv:
if len(sys.argv) > 2 and \
('sdist' in sys.argv or 'bdist_rpm' in sys.argv):
print >> sys.stderr, "ERROR: bdist_wininst must be run alone. Exiting."
print("ERROR: bdist_wininst must be run alone. Exiting.", file=sys.stderr)
sys.exit(1)
setup_args['data_files'].append(
['Scripts', ('scripts/ipython.ico', 'scripts/ipython_nb.ico')])