Skip to content

Commit 7e4e1f1

Browse files
committed
Merge branch 'graingert-no-var-rule'
2 parents c7611fb + 463b06f commit 7e4e1f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+780
-756
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/core/lib/**

src/.eslintrc.json renamed to .eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
}],
8585
"no-whitespace-before-property": "error",
8686
"operator-linebreak": ["error", "after"],
87-
"space-in-parens": "error"
87+
"space-in-parens": "error",
88+
"no-var": "error"
8889
},
8990
"globals": {
9091
"$": false,

Gruntfile.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var webpack = require("webpack"),
2-
ExtractTextPlugin = require("extract-text-webpack-plugin"),
3-
HtmlWebpackPlugin = require("html-webpack-plugin"),
4-
Inliner = require("web-resource-inliner");
1+
const webpack = require("webpack");
2+
const ExtractTextPlugin = require("extract-text-webpack-plugin");
3+
const HtmlWebpackPlugin = require("html-webpack-plugin");
4+
const Inliner = require("web-resource-inliner");
55

66
module.exports = function (grunt) {
77
grunt.file.defaultEncoding = "utf8";
@@ -54,7 +54,7 @@ module.exports = function (grunt) {
5454

5555

5656
// Project configuration
57-
var compileTime = grunt.template.today("dd/mm/yyyy HH:MM:ss") + " UTC",
57+
const compileTime = grunt.template.today("dd/mm/yyyy HH:MM:ss") + " UTC",
5858
banner = "/**\n" +
5959
"* CyberChef - The Cyber Swiss Army Knife\n" +
6060
"*\n" +
@@ -80,7 +80,7 @@ module.exports = function (grunt) {
8080
* Compiles a production build of CyberChef into a single, portable web page.
8181
*/
8282
function runInliner() {
83-
var inlinerError = false;
83+
const done = this.async();
8484
Inliner.html({
8585
relativeTo: "build/prod/",
8686
fileContent: grunt.file.read("build/prod/cyberchef.htm"),
@@ -91,14 +91,16 @@ module.exports = function (grunt) {
9191
strict: true
9292
}, function(error, result) {
9393
if (error) {
94-
console.log(error);
95-
inlinerError = true;
96-
return false;
94+
if (error instanceof Error) {
95+
done(error);
96+
} else {
97+
done(new Error(error));
98+
}
99+
} else {
100+
grunt.file.write("build/prod/cyberchef.htm", result);
101+
done(true);
97102
}
98-
grunt.file.write("build/prod/cyberchef.htm", result);
99103
});
100-
101-
return !inlinerError;
102104
}
103105

104106
grunt.initConfig({
@@ -111,7 +113,7 @@ module.exports = function (grunt) {
111113
},
112114
eslint: {
113115
options: {
114-
configFile: "src/.eslintrc.json"
116+
configFile: "./.eslintrc.json"
115117
},
116118
configs: ["Gruntfile.js"],
117119
core: ["src/core/**/*.js", "!src/core/lib/**/*"],
@@ -301,7 +303,7 @@ module.exports = function (grunt) {
301303
copy: {
302304
ghPages: {
303305
options: {
304-
process: function (content, srcpath) {
306+
process: function (content) {
305307
// Add Google Analytics code to index.html
306308
content = content.replace("</body></html>",
307309
grunt.file.read("src/web/static/ga.html") + "</body></html>");
@@ -342,5 +344,4 @@ module.exports = function (grunt) {
342344
test: "build/test/index.js"
343345
},
344346
});
345-
346347
};

src/core/Chef.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Recipe from "./Recipe.js";
1111
*
1212
* @class
1313
*/
14-
var Chef = function() {
14+
const Chef = function() {
1515
this.dish = new Dish();
1616
};
1717

@@ -35,7 +35,7 @@ var Chef = function() {
3535
* @returns {number} response.error - The error object thrown by a failed operation (false if no error)
3636
*/
3737
Chef.prototype.bake = function(inputText, recipeConfig, options, progress, step) {
38-
var startTime = new Date().getTime(),
38+
let startTime = new Date().getTime(),
3939
recipe = new Recipe(recipeConfig),
4040
containsFc = recipe.containsFlowControl(),
4141
error = false;
@@ -111,7 +111,7 @@ Chef.prototype.bake = function(inputText, recipeConfig, options, progress, step)
111111
* @returns {number} The time it took to run the silent bake in milliseconds.
112112
*/
113113
Chef.prototype.silentBake = function(recipeConfig) {
114-
var startTime = new Date().getTime(),
114+
let startTime = new Date().getTime(),
115115
recipe = new Recipe(recipeConfig),
116116
dish = new Dish("", Dish.STRING);
117117

src/core/Dish.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Utils from "./Utils.js";
22

3-
43
/**
54
* The data being operated on by each operation.
65
*
@@ -12,7 +11,7 @@ import Utils from "./Utils.js";
1211
* @param {byteArray|string|number} value - The value of the input data.
1312
* @param {number} type - The data type of value, see Dish enums.
1413
*/
15-
var Dish = function(value, type) {
14+
const Dish = function(value, type) {
1615
this.value = value || typeof value == "string" ? value : null;
1716
this.type = type || Dish.BYTE_ARRAY;
1817
};
@@ -105,7 +104,7 @@ Dish.prototype.set = function(value, type) {
105104
this.type = type;
106105

107106
if (!this.valid()) {
108-
var sample = Utils.truncate(JSON.stringify(this.value), 13);
107+
const sample = Utils.truncate(JSON.stringify(this.value), 13);
109108
throw "Data is not a valid " + Dish.enumLookup(type) + ": " + sample;
110109
}
111110
};
@@ -180,7 +179,7 @@ Dish.prototype.valid = function() {
180179
}
181180

182181
// Check that every value is a number between 0 - 255
183-
for (var i = 0; i < this.value.length; i++) {
182+
for (let i = 0; i < this.value.length; i++) {
184183
if (typeof this.value[i] != "number" ||
185184
this.value[i] < 0 ||
186185
this.value[i] > 255) {

src/core/FlowControl.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const FlowControl = {
3939
* @returns {Object} The updated state of the recipe.
4040
*/
4141
runFork: function(state) {
42-
var opList = state.opList,
42+
let opList = state.opList,
4343
inputType = opList[state.progress].inputType,
4444
outputType = opList[state.progress].outputType,
4545
input = state.dish.get(inputType),
@@ -48,30 +48,31 @@ const FlowControl = {
4848
mergeDelim = ings[1],
4949
ignoreErrors = ings[2],
5050
subOpList = [],
51-
inputs = [];
51+
inputs = [],
52+
i;
5253

5354
if (input)
5455
inputs = input.split(splitDelim);
5556

5657
// Create subOpList for each tranche to operate on
5758
// (all remaining operations unless we encounter a Merge)
58-
for (var i = state.progress + 1; i < opList.length; i++) {
59+
for (i = state.progress + 1; i < opList.length; i++) {
5960
if (opList[i].name === "Merge" && !opList[i].isDisabled()) {
6061
break;
6162
} else {
6263
subOpList.push(opList[i]);
6364
}
6465
}
6566

66-
var recipe = new Recipe(),
67+
let recipe = new Recipe(),
6768
output = "",
6869
progress = 0;
6970

7071
recipe.addOperations(subOpList);
7172

7273
// Run recipe over each tranche
7374
for (i = 0; i < inputs.length; i++) {
74-
var dish = new Dish(inputs[i], inputType);
75+
const dish = new Dish(inputs[i], inputType);
7576
try {
7677
progress = recipe.execute(dish, 0);
7778
} catch (err) {
@@ -127,7 +128,7 @@ const FlowControl = {
127128
* @returns {Object} The updated state of the recipe.
128129
*/
129130
runJump: function(state) {
130-
var ings = state.opList[state.progress].getIngValues(),
131+
let ings = state.opList[state.progress].getIngValues(),
131132
jumpNum = ings[0],
132133
maxJumps = ings[1];
133134

@@ -156,7 +157,7 @@ const FlowControl = {
156157
* @returns {Object} The updated state of the recipe.
157158
*/
158159
runCondJump: function(state) {
159-
var ings = state.opList[state.progress].getIngValues(),
160+
let ings = state.opList[state.progress].getIngValues(),
160161
dish = state.dish,
161162
regexStr = ings[0],
162163
jumpNum = ings[1],

src/core/Ingredient.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Utils from "./Utils.js";
1111
* @class
1212
* @param {Object} ingredientConfig
1313
*/
14-
var Ingredient = function(ingredientConfig) {
14+
const Ingredient = function(ingredientConfig) {
1515
this.name = "";
1616
this.type = "";
1717
this.value = null;
@@ -63,6 +63,8 @@ Ingredient.prototype.setValue = function(value) {
6363
* @param {string} type - The name of the data type.
6464
*/
6565
Ingredient.prepare = function(data, type) {
66+
let number;
67+
6668
switch (type) {
6769
case "binaryString":
6870
case "binaryShortString":
@@ -76,9 +78,9 @@ Ingredient.prepare = function(data, type) {
7678
return data;
7779
}
7880
case "number":
79-
var number = parseFloat(data);
81+
number = parseFloat(data);
8082
if (isNaN(number)) {
81-
var sample = Utils.truncate(data.toString(), 10);
83+
const sample = Utils.truncate(data.toString(), 10);
8284
throw "Invalid ingredient value. Not a number: " + sample;
8385
}
8486
return number;

src/core/Operation.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Ingredient from "./Ingredient.js";
1313
* @param {string} operationName
1414
* @param {Object} operationConfig
1515
*/
16-
var Operation = function(operationName, operationConfig) {
16+
const Operation = function(operationName, operationConfig) {
1717
this.name = operationName;
1818
this.description = "";
1919
this.inputType = -1;
@@ -46,9 +46,9 @@ Operation.prototype._parseConfig = function(operationConfig) {
4646
this.highlightReverse = operationConfig.highlightReverse;
4747
this.flowControl = operationConfig.flowControl;
4848

49-
for (var a = 0; a < operationConfig.args.length; a++) {
50-
var ingredientConfig = operationConfig.args[a];
51-
var ingredient = new Ingredient(ingredientConfig);
49+
for (let a = 0; a < operationConfig.args.length; a++) {
50+
const ingredientConfig = operationConfig.args[a];
51+
const ingredient = new Ingredient(ingredientConfig);
5252
this.addIngredient(ingredient);
5353
}
5454
};
@@ -60,13 +60,13 @@ Operation.prototype._parseConfig = function(operationConfig) {
6060
* @returns {Object}
6161
*/
6262
Operation.prototype.getConfig = function() {
63-
var ingredientConfig = [];
63+
const ingredientConfig = [];
6464

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

69-
var operationConfig = {
69+
const operationConfig = {
7070
"op": this.name,
7171
"args": ingredientConfig
7272
};
@@ -91,7 +91,7 @@ Operation.prototype.addIngredient = function(ingredient) {
9191
* @param {Object[]} ingValues
9292
*/
9393
Operation.prototype.setIngValues = function(ingValues) {
94-
for (var i = 0; i < ingValues.length; i++) {
94+
for (let i = 0; i < ingValues.length; i++) {
9595
this.ingList[i].setValue(ingValues[i]);
9696
}
9797
};
@@ -103,8 +103,8 @@ Operation.prototype.setIngValues = function(ingValues) {
103103
* @returns {Object[]}
104104
*/
105105
Operation.prototype.getIngValues = function() {
106-
var ingValues = [];
107-
for (var i = 0; i < this.ingList.length; i++) {
106+
const ingValues = [];
107+
for (let i = 0; i < this.ingList.length; i++) {
108108
ingValues.push(this.ingList[i].value);
109109
}
110110
return ingValues;

0 commit comments

Comments
 (0)