Skip to content

Commit

Permalink
Merge branch 'graingert-no-var-rule'
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed May 2, 2017
2 parents c7611fb + 463b06f commit 7e4e1f1
Show file tree
Hide file tree
Showing 65 changed files with 780 additions and 756 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/core/lib/**
3 changes: 2 additions & 1 deletion src/.eslintrc.json → .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
}],
"no-whitespace-before-property": "error",
"operator-linebreak": ["error", "after"],
"space-in-parens": "error"
"space-in-parens": "error",
"no-var": "error"
},
"globals": {
"$": false,
Expand Down
31 changes: 16 additions & 15 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var webpack = require("webpack"),
ExtractTextPlugin = require("extract-text-webpack-plugin"),
HtmlWebpackPlugin = require("html-webpack-plugin"),
Inliner = require("web-resource-inliner");
const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const Inliner = require("web-resource-inliner");

module.exports = function (grunt) {
grunt.file.defaultEncoding = "utf8";
Expand Down Expand Up @@ -54,7 +54,7 @@ module.exports = function (grunt) {


// Project configuration
var compileTime = grunt.template.today("dd/mm/yyyy HH:MM:ss") + " UTC",
const compileTime = grunt.template.today("dd/mm/yyyy HH:MM:ss") + " UTC",
banner = "/**\n" +
"* CyberChef - The Cyber Swiss Army Knife\n" +
"*\n" +
Expand All @@ -80,7 +80,7 @@ module.exports = function (grunt) {
* Compiles a production build of CyberChef into a single, portable web page.
*/
function runInliner() {
var inlinerError = false;
const done = this.async();
Inliner.html({
relativeTo: "build/prod/",
fileContent: grunt.file.read("build/prod/cyberchef.htm"),
Expand All @@ -91,14 +91,16 @@ module.exports = function (grunt) {
strict: true
}, function(error, result) {
if (error) {
console.log(error);
inlinerError = true;
return false;
if (error instanceof Error) {
done(error);
} else {
done(new Error(error));
}
} else {
grunt.file.write("build/prod/cyberchef.htm", result);
done(true);
}
grunt.file.write("build/prod/cyberchef.htm", result);
});

return !inlinerError;
}

grunt.initConfig({
Expand All @@ -111,7 +113,7 @@ module.exports = function (grunt) {
},
eslint: {
options: {
configFile: "src/.eslintrc.json"
configFile: "./.eslintrc.json"
},
configs: ["Gruntfile.js"],
core: ["src/core/**/*.js", "!src/core/lib/**/*"],
Expand Down Expand Up @@ -301,7 +303,7 @@ module.exports = function (grunt) {
copy: {
ghPages: {
options: {
process: function (content, srcpath) {
process: function (content) {
// Add Google Analytics code to index.html
content = content.replace("</body></html>",
grunt.file.read("src/web/static/ga.html") + "</body></html>");
Expand Down Expand Up @@ -342,5 +344,4 @@ module.exports = function (grunt) {
test: "build/test/index.js"
},
});

};
6 changes: 3 additions & 3 deletions src/core/Chef.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Recipe from "./Recipe.js";
*
* @class
*/
var Chef = function() {
const Chef = function() {
this.dish = new Dish();
};

Expand All @@ -35,7 +35,7 @@ var Chef = function() {
* @returns {number} response.error - The error object thrown by a failed operation (false if no error)
*/
Chef.prototype.bake = function(inputText, recipeConfig, options, progress, step) {
var startTime = new Date().getTime(),
let startTime = new Date().getTime(),
recipe = new Recipe(recipeConfig),
containsFc = recipe.containsFlowControl(),
error = false;
Expand Down Expand Up @@ -111,7 +111,7 @@ Chef.prototype.bake = function(inputText, recipeConfig, options, progress, step)
* @returns {number} The time it took to run the silent bake in milliseconds.
*/
Chef.prototype.silentBake = function(recipeConfig) {
var startTime = new Date().getTime(),
let startTime = new Date().getTime(),
recipe = new Recipe(recipeConfig),
dish = new Dish("", Dish.STRING);

Expand Down
7 changes: 3 additions & 4 deletions src/core/Dish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Utils from "./Utils.js";


/**
* The data being operated on by each operation.
*
Expand All @@ -12,7 +11,7 @@ import Utils from "./Utils.js";
* @param {byteArray|string|number} value - The value of the input data.
* @param {number} type - The data type of value, see Dish enums.
*/
var Dish = function(value, type) {
const Dish = function(value, type) {
this.value = value || typeof value == "string" ? value : null;
this.type = type || Dish.BYTE_ARRAY;
};
Expand Down Expand Up @@ -105,7 +104,7 @@ Dish.prototype.set = function(value, type) {
this.type = type;

if (!this.valid()) {
var sample = Utils.truncate(JSON.stringify(this.value), 13);
const sample = Utils.truncate(JSON.stringify(this.value), 13);
throw "Data is not a valid " + Dish.enumLookup(type) + ": " + sample;
}
};
Expand Down Expand Up @@ -180,7 +179,7 @@ Dish.prototype.valid = function() {
}

// Check that every value is a number between 0 - 255
for (var i = 0; i < this.value.length; i++) {
for (let i = 0; i < this.value.length; i++) {
if (typeof this.value[i] != "number" ||
this.value[i] < 0 ||
this.value[i] > 255) {
Expand Down
15 changes: 8 additions & 7 deletions src/core/FlowControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const FlowControl = {
* @returns {Object} The updated state of the recipe.
*/
runFork: function(state) {
var opList = state.opList,
let opList = state.opList,
inputType = opList[state.progress].inputType,
outputType = opList[state.progress].outputType,
input = state.dish.get(inputType),
Expand All @@ -48,30 +48,31 @@ const FlowControl = {
mergeDelim = ings[1],
ignoreErrors = ings[2],
subOpList = [],
inputs = [];
inputs = [],
i;

if (input)
inputs = input.split(splitDelim);

// Create subOpList for each tranche to operate on
// (all remaining operations unless we encounter a Merge)
for (var i = state.progress + 1; i < opList.length; i++) {
for (i = state.progress + 1; i < opList.length; i++) {
if (opList[i].name === "Merge" && !opList[i].isDisabled()) {
break;
} else {
subOpList.push(opList[i]);
}
}

var recipe = new Recipe(),
let recipe = new Recipe(),
output = "",
progress = 0;

recipe.addOperations(subOpList);

// Run recipe over each tranche
for (i = 0; i < inputs.length; i++) {
var dish = new Dish(inputs[i], inputType);
const dish = new Dish(inputs[i], inputType);
try {
progress = recipe.execute(dish, 0);
} catch (err) {
Expand Down Expand Up @@ -127,7 +128,7 @@ const FlowControl = {
* @returns {Object} The updated state of the recipe.
*/
runJump: function(state) {
var ings = state.opList[state.progress].getIngValues(),
let ings = state.opList[state.progress].getIngValues(),
jumpNum = ings[0],
maxJumps = ings[1];

Expand Down Expand Up @@ -156,7 +157,7 @@ const FlowControl = {
* @returns {Object} The updated state of the recipe.
*/
runCondJump: function(state) {
var ings = state.opList[state.progress].getIngValues(),
let ings = state.opList[state.progress].getIngValues(),
dish = state.dish,
regexStr = ings[0],
jumpNum = ings[1],
Expand Down
8 changes: 5 additions & 3 deletions src/core/Ingredient.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Utils from "./Utils.js";
* @class
* @param {Object} ingredientConfig
*/
var Ingredient = function(ingredientConfig) {
const Ingredient = function(ingredientConfig) {
this.name = "";
this.type = "";
this.value = null;
Expand Down Expand Up @@ -63,6 +63,8 @@ Ingredient.prototype.setValue = function(value) {
* @param {string} type - The name of the data type.
*/
Ingredient.prepare = function(data, type) {
let number;

switch (type) {
case "binaryString":
case "binaryShortString":
Expand All @@ -76,9 +78,9 @@ Ingredient.prepare = function(data, type) {
return data;
}
case "number":
var number = parseFloat(data);
number = parseFloat(data);
if (isNaN(number)) {
var sample = Utils.truncate(data.toString(), 10);
const sample = Utils.truncate(data.toString(), 10);
throw "Invalid ingredient value. Not a number: " + sample;
}
return number;
Expand Down
20 changes: 10 additions & 10 deletions src/core/Operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Ingredient from "./Ingredient.js";
* @param {string} operationName
* @param {Object} operationConfig
*/
var Operation = function(operationName, operationConfig) {
const Operation = function(operationName, operationConfig) {
this.name = operationName;
this.description = "";
this.inputType = -1;
Expand Down Expand Up @@ -46,9 +46,9 @@ Operation.prototype._parseConfig = function(operationConfig) {
this.highlightReverse = operationConfig.highlightReverse;
this.flowControl = operationConfig.flowControl;

for (var a = 0; a < operationConfig.args.length; a++) {
var ingredientConfig = operationConfig.args[a];
var ingredient = new Ingredient(ingredientConfig);
for (let a = 0; a < operationConfig.args.length; a++) {
const ingredientConfig = operationConfig.args[a];
const ingredient = new Ingredient(ingredientConfig);
this.addIngredient(ingredient);
}
};
Expand All @@ -60,13 +60,13 @@ Operation.prototype._parseConfig = function(operationConfig) {
* @returns {Object}
*/
Operation.prototype.getConfig = function() {
var ingredientConfig = [];
const ingredientConfig = [];

for (var o = 0; o < this.ingList.length; o++) {
for (let o = 0; o < this.ingList.length; o++) {
ingredientConfig.push(this.ingList[o].getConfig());
}

var operationConfig = {
const operationConfig = {
"op": this.name,
"args": ingredientConfig
};
Expand All @@ -91,7 +91,7 @@ Operation.prototype.addIngredient = function(ingredient) {
* @param {Object[]} ingValues
*/
Operation.prototype.setIngValues = function(ingValues) {
for (var i = 0; i < ingValues.length; i++) {
for (let i = 0; i < ingValues.length; i++) {
this.ingList[i].setValue(ingValues[i]);
}
};
Expand All @@ -103,8 +103,8 @@ Operation.prototype.setIngValues = function(ingValues) {
* @returns {Object[]}
*/
Operation.prototype.getIngValues = function() {
var ingValues = [];
for (var i = 0; i < this.ingList.length; i++) {
const ingValues = [];
for (let i = 0; i < this.ingList.length; i++) {
ingValues.push(this.ingList[i].value);
}
return ingValues;
Expand Down
Loading

0 comments on commit 7e4e1f1

Please sign in to comment.