Replaced jsHint with eslint. Fixes #4.

This commit is contained in:
n1474335 2016-12-14 16:39:17 +00:00
parent e2e68dd876
commit af4644c9eb
48 changed files with 1741 additions and 1685 deletions

View file

@ -35,33 +35,33 @@ Chef.prototype.bake = function(input_text, recipe_config, options, progress, ste
recipe = new Recipe(recipe_config),
contains_fc = recipe.contains_flow_control(),
error = false;
// Reset attempt_highlight flag
if (options.hasOwnProperty("attempt_highlight")) {
options.attempt_highlight = true;
}
if (contains_fc) options.attempt_highlight = false;
// Clean up progress
if (progress >= recipe_config.length) {
progress = 0;
}
if (step) {
// Unset breakpoint on this step
recipe.set_breakpoint(progress, false);
// Set breakpoint on next step
recipe.set_breakpoint(progress + 1, true);
}
// If stepping with flow control, we have to start from the beginning
// but still want to skip all previous breakpoints
if (progress > 0 && contains_fc) {
recipe.remove_breaks_up_to(progress);
progress = 0;
}
// If starting from scratch, load data
if (progress === 0) {
this.dish.set(input_text, Dish.STRING);
@ -70,22 +70,22 @@ Chef.prototype.bake = function(input_text, recipe_config, options, progress, ste
try {
progress = recipe.execute(this.dish, progress);
} catch (err) {
// We can't throw the error from here as we will return in the finally block and ignore it
// so we return the error in the result instead.
// Return the error in the result so that everything else gets correctly updated
// rather than throwing it here and losing state info.
error = err;
progress = err.progress;
} finally {
return {
result: this.dish.type == Dish.HTML ?
this.dish.get(Dish.HTML) :
this.dish.get(Dish.STRING),
type: Dish.enum_lookup(this.dish.type),
progress: progress,
options: options,
duration: new Date().getTime() - start_time,
error: error
};
}
return {
result: this.dish.type === Dish.HTML ?
this.dish.get(Dish.HTML) :
this.dish.get(Dish.STRING),
type: Dish.enum_lookup(this.dish.type),
progress: progress,
options: options,
duration: new Date().getTime() - start_time,
error: error
};
};
@ -94,12 +94,12 @@ Chef.prototype.bake = function(input_text, recipe_config, options, progress, ste
* it swaps out the memory for that tab. If the CyberChef tab has been unfocused for more than a
* minute, we run a silent bake which will force the browser to load and cache all the relevant
* JavaScript code needed to do a real bake.
*
*
* This will stop baking taking a long time when the CyberChef browser tab has been unfocused for a
* long time and the browser has swapped out all its memory.
*
*
* The output will not be modified (hence "silent" bake).
*
*
* This will only actually execute the recipe if auto-bake is enabled, otherwise it will just load
* the recipe, ingredients and dish.
*
@ -110,7 +110,7 @@ Chef.prototype.silent_bake = function(recipe_config) {
var start_time = new Date().getTime(),
recipe = new Recipe(recipe_config),
dish = new Dish("", Dish.STRING);
try {
recipe.execute(dish);
} catch(err) {

View file

@ -115,7 +115,7 @@ Dish.prototype.set = function(value, type) {
* @returns {byte_array|string|number} The value of the output data.
*/
Dish.prototype.get = function(type) {
if (this.type != type) {
if (this.type !== type) {
this.translate(type);
}
return this.value;

View file

@ -7,7 +7,7 @@
*
* @namespace
*/
var FlowControl = {
const FlowControl = {
/**
* @constant
@ -46,7 +46,7 @@ var FlowControl = {
// Create sub_op_list for each tranche to operate on
// (all remaining operations unless we encounter a Merge)
for (var i = state.progress + 1; i < op_list.length; i++) {
if (op_list[i].name == "Merge" && !op_list[i].is_disabled()) {
if (op_list[i].name === "Merge" && !op_list[i].is_disabled()) {
break;
} else {
sub_op_list.push(op_list[i]);

View file

@ -67,12 +67,11 @@ Ingredient.prepare = function(data, type) {
return Utils.parse_escaped_chars(data);
case "byte_array":
if (typeof data == "string") {
data = data.replace(/\s+/g, '');
data = data.replace(/\s+/g, "");
return Utils.hex_to_byte_array(data);
} else {
return data;
}
break;
case "number":
var number = parseFloat(data);
if (isNaN(number)) {

View file

@ -203,7 +203,7 @@ var Utils = {
*/
parse_escaped_chars: function(str) {
return str.replace(/(\\)?\\([nrtbf]|x[\da-f]{2})/g, function(m, a, b) {
if (a == "\\") return "\\"+b;
if (a === "\\") return "\\"+b;
switch (b[0]) {
case "n":
return "\n";
@ -243,8 +243,8 @@ var Utils = {
for (var i = 0; i < alph_str.length; i++) {
if (i < alph_str.length - 2 &&
alph_str[i+1] == "-" &&
alph_str[i] != "\\") {
alph_str[i+1] === "-" &&
alph_str[i] !== "\\") {
var start = Utils.ord(alph_str[i]),
end = Utils.ord(alph_str[i+2]);
@ -253,8 +253,8 @@ var Utils = {
}
i += 2;
} else if (i < alph_str.length - 2 &&
alph_str[i] == "\\" &&
alph_str[i+1] == "-") {
alph_str[i] === "\\" &&
alph_str[i+1] === "-") {
alph_arr.push("-");
i++;
} else {
@ -278,7 +278,7 @@ var Utils = {
hex_to_byte_array: function(hex_str) {
// TODO: Handle errors i.e. input string is not hex
if (!hex_str) return [];
hex_str = hex_str.replace(/\s+/g, '');
hex_str = hex_str.replace(/\s+/g, "");
var byte_array = [];
for (var i = 0; i < hex_str.length; i += 2) {
byte_array.push(parseInt(hex_str.substr(i, 2), 16));
@ -351,7 +351,7 @@ var Utils = {
var word_array = CryptoJS.enc.Utf8.parse(str),
byte_array = Utils.word_array_to_byte_array(word_array);
if (str.length != word_array.sigBytes)
if (str.length !== word_array.sigBytes)
window.app.options.attempt_highlight = false;
return byte_array;
},
@ -403,7 +403,7 @@ var Utils = {
var word_array = new CryptoJS.lib.WordArray.init(words, byte_array.length),
str = CryptoJS.enc.Utf8.stringify(word_array);
if (str.length != word_array.sigBytes)
if (str.length !== word_array.sigBytes)
window.app.options.attempt_highlight = false;
return str;
} catch (err) {
@ -553,7 +553,7 @@ var Utils = {
res.push(String.fromCharCode(Utils.UNIC_WIN1251_MAP[ord]));
}
return res.join('');
return res.join("");
},
@ -577,7 +577,7 @@ var Utils = {
res.push(String.fromCharCode(Utils.WIN1251_UNIC_MAP[ord]));
}
return res.join('');
return res.join("");
},
@ -653,7 +653,7 @@ var Utils = {
return_type = return_type || "string";
if (!data) {
return return_type == "string" ? "" : [];
return return_type === "string" ? "" : [];
}
alphabet = alphabet ?
@ -678,9 +678,9 @@ var Utils = {
enc3 = alphabet.indexOf(data.charAt(i++) || "=");
enc4 = alphabet.indexOf(data.charAt(i++) || "=");
enc2 = enc2 == -1 ? 64 : enc2;
enc3 = enc3 == -1 ? 64 : enc3;
enc4 = enc4 == -1 ? 64 : enc4;
enc2 = enc2 === -1 ? 64 : enc2;
enc3 = enc3 === -1 ? 64 : enc3;
enc4 = enc4 === -1 ? 64 : enc4;
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
@ -688,15 +688,15 @@ var Utils = {
output.push(chr1);
if (enc3 != 64) {
if (enc3 !== 64) {
output.push(chr2);
}
if (enc4 != 64) {
if (enc4 !== 64) {
output.push(chr3);
}
}
return return_type == "string" ? Utils.byte_array_to_utf8(output) : output;
return return_type === "string" ? Utils.byte_array_to_utf8(output) : output;
},
@ -727,8 +727,8 @@ var Utils = {
}
// Add \x or 0x to beginning
if (delim == "0x") output = "0x" + output;
if (delim == "\\x") output = "\\x" + output;
if (delim === "0x") output = "0x" + output;
if (delim === "\\x") output = "\\x" + output;
if (delim.length)
return output.slice(0, -delim.length);
@ -779,9 +779,9 @@ var Utils = {
from_hex: function(data, delim, byte_len) {
delim = delim || (data.indexOf(" ") >= 0 ? "Space" : "None");
byte_len = byte_len || 2;
if (delim != "None") {
if (delim !== "None") {
var delim_regex = Utils.regex_rep[delim];
data = data.replace(delim_regex, '');
data = data.replace(delim_regex, "");
}
var output = [];
@ -816,17 +816,17 @@ var Utils = {
if (ignore_next) {
cell += b;
ignore_next = false;
} else if (b == "\\") {
} else if (b === "\\") {
cell += b;
ignore_next = true;
} else if (b == "\"" && !in_string) {
} else if (b === "\"" && !in_string) {
in_string = true;
} else if (b == "\"" && in_string) {
} else if (b === "\"" && in_string) {
in_string = false;
} else if (b == "," && !in_string) {
} else if (b === "," && !in_string) {
line.push(cell);
cell = "";
} else if ((b == "\n" || b == "\r") && !in_string) {
} else if ((b === "\n" || b === "\r") && !in_string) {
line.push(cell);
cell = "";
lines.push(line);
@ -877,7 +877,7 @@ var Utils = {
escape_html: function(str) {
return str.replace(/</g, "&lt;")
.replace(/'/g, "&apos;")
.replace(/"/g, '&quot;')
.replace(/"/g, "&quot;")
.replace(/&/g, "&amp;");
},
@ -1002,8 +1002,8 @@ $.fn.selectRange = function(start, end) {
} else if (this.createTextRange) {
var range = this.createTextRange();
range.collapse(true);
range.moveEnd('character', end);
range.moveStart('character', start);
range.moveEnd("character", end);
range.moveStart("character", start);
range.select();
}
});
@ -1095,7 +1095,7 @@ Array.prototype.sum = function() {
Array.prototype.equals = function(other) {
if (!other) return false;
var i = this.length;
if (i != other.length) return false;
if (i !== other.length) return false;
while (i--) {
if (this[i] !== other[i]) return false;
}