diff --git a/.eslintignore b/.eslintignore index 4277ae0f..5ef090e8 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ src/core/lib/** +build diff --git a/.eslintrc.json b/.eslintrc.json index 8632d2e6..97c6d6e8 100755 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -85,7 +85,9 @@ "no-whitespace-before-property": "error", "operator-linebreak": ["error", "after"], "space-in-parens": "error", - "no-var": "error" + "no-var": "error", + "prefer-template": "error", + "template-curly-spacing": ["error", "never"] }, "globals": { "$": false, diff --git a/Gruntfile.js b/Gruntfile.js index b57f7f6d..17e57f37 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -54,7 +54,7 @@ module.exports = function (grunt) { // Project configuration - const 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" + @@ -229,7 +229,7 @@ module.exports = function (grunt) { entry: "./src/web/index.js", output: { filename: "scripts.js", - path: __dirname + "/build/dev" + path: `${__dirname}/build/dev` }, plugins: [ new HtmlWebpackPlugin({ @@ -245,7 +245,7 @@ module.exports = function (grunt) { entry: "./src/web/index.js", output: { filename: "scripts.js", - path: __dirname + "/build/prod" + path: `${__dirname}/build/prod` }, plugins: [ new webpack.optimize.UglifyJsPlugin({ @@ -287,7 +287,7 @@ module.exports = function (grunt) { entry: "./test/index.js", output: { filename: "index.js", - path: __dirname + "/build/test" + path: `${__dirname}/build/test` } }, node: { @@ -295,7 +295,7 @@ module.exports = function (grunt) { entry: "./src/node/index.js", output: { filename: "CyberChef.js", - path: __dirname + "/build/node", + path: `${__dirname}/build/node`, library: "CyberChef", libraryTarget: "commonjs2" } @@ -307,7 +307,7 @@ module.exports = function (grunt) { process: function (content) { // Add Google Analytics code to index.html content = content.replace("", - grunt.file.read("src/web/static/ga.html") + ""); + `${grunt.file.read("src/web/static/ga.html")}`); return grunt.template.process(content); } }, diff --git a/src/core/Dish.js b/src/core/Dish.js index 914188c1..b20a0869 100755 --- a/src/core/Dish.js +++ b/src/core/Dish.js @@ -105,7 +105,7 @@ Dish.prototype.set = function(value, type) { if (!this.valid()) { const sample = Utils.truncate(JSON.stringify(this.value), 13); - throw "Data is not a valid " + Dish.enumLookup(type) + ": " + sample; + throw `Data is not a valid ${Dish.enumLookup(type)}: ${sample}`; } }; diff --git a/src/core/Ingredient.js b/src/core/Ingredient.js index 543f732b..81cd500c 100755 --- a/src/core/Ingredient.js +++ b/src/core/Ingredient.js @@ -81,7 +81,7 @@ Ingredient.prepare = function(data, type) { number = parseFloat(data); if (isNaN(number)) { const sample = Utils.truncate(data.toString(), 10); - throw "Invalid ingredient value. Not a number: " + sample; + throw `Invalid ingredient value. Not a number: ${sample}`; } return number; default: diff --git a/src/core/Recipe.js b/src/core/Recipe.js index 1b0e7f73..7648b78a 100755 --- a/src/core/Recipe.js +++ b/src/core/Recipe.js @@ -182,11 +182,11 @@ Recipe.prototype.execute = async function(dish, startFrom) { e.progress = i; if (e.fileName) { - e.displayStr = op.name + " - " + e.name + " in " + - e.fileName + " on line " + e.lineNumber + - ".

Message: " + (e.displayStr || e.message); + e.displayStr = `${op.name} - ${e.name} in ${ + e.fileName} on line ${e.lineNumber + }.

Message: ${e.displayStr || e.message}`; } else { - e.displayStr = op.name + " - " + (e.displayStr || e.message); + e.displayStr = `${op.name} - ${e.displayStr || e.message}`; } throw e; diff --git a/src/core/Utils.js b/src/core/Utils.js index 368633b9..20a416d0 100755 --- a/src/core/Utils.js +++ b/src/core/Utils.js @@ -240,7 +240,7 @@ const Utils = { */ parseEscapedChars: 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"; @@ -338,7 +338,7 @@ const Utils = { if (!byteArray) return ""; let hexStr = ""; for (let i = 0; i < byteArray.length; i++) { - hexStr += Utils.hex(byteArray[i]) + " "; + hexStr += `${Utils.hex(byteArray[i])} `; } return hexStr.slice(0, hexStr.length-1); }, @@ -587,7 +587,7 @@ const Utils = { for (let i = 0; i < unicStr.length; i++) { const ord = unicStr.charCodeAt(i); if (!(ord in Utils.UNIC_WIN1251_MAP)) - throw "Character '" + unicStr.charAt(i) + "' isn't supported by Windows-1251"; + throw `Character '${unicStr.charAt(i)}' isn't supported by Windows-1251`; res.push(String.fromCharCode(Utils.UNIC_WIN1251_MAP[ord])); } @@ -611,7 +611,7 @@ const Utils = { for (let i = 0; i < win1251Str.length; i++) { const ord = win1251Str.charCodeAt(i); if (!(ord in Utils.WIN1251_UNIC_MAP)) - throw "Character '" + win1251Str.charAt(i) + "' isn't supported by Windows-1251"; + throw `Character '${win1251Str.charAt(i)}' isn't supported by Windows-1251`; res.push(String.fromCharCode(Utils.WIN1251_UNIC_MAP[ord])); } @@ -706,7 +706,7 @@ const Utils = { i = 0; if (removeNonAlphChars) { - const re = new RegExp("[^" + alphabet.replace(/[\[\]\\\-^$]/g, "\\$&") + "]", "g"); + const re = new RegExp(`[^${alphabet.replace(/[\[\]\\\-^$]/g, "\\$&")}]`, "g"); data = data.replace(re, ""); } @@ -765,8 +765,8 @@ const 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); @@ -1017,12 +1017,12 @@ const Utils = { */ displayFilesAsHTML: function(files){ const formatDirectory = function(file) { - const html = "
" + + const html = `${"
" + "" + "
"; @@ -1036,45 +1036,45 @@ const Utils = { ); const blobUrl = URL.createObjectURL(blob); - const downloadAnchorElem = "\u21B4"; + const downloadAnchorElem = `\u21B4`; - const expandFileContentsElem = "🔍"; + `aria-controls='collapse${i}' ` + + `title="Show/hide contents of '${Utils.escapeHtml(file.fileName)}'">🔍`; - const html = "
" + - "