Fixed lint warnings and handled some edge cases. r?jaws
draft
Fixed lint warnings and handled some edge cases. r?jaws
MozReview-Commit-ID: HCLKtxdjJvN
--- a/browser/tools/mozscreenshots/browser_screenshots.js
+++ b/browser/tools/mozscreenshots/browser_screenshots.js
@@ -4,53 +4,52 @@
"use strict";
/**
* Finds the index of the first comma that is not enclosed within square brackets.
* @param {String} env - the string that needs to be searched
* @return {Integer} index of valid comma or -1 if not found.
*/
-function findComma(env){
- let ignore = false;
- for(let i = 0; i < env.length; i++){
- if(env[i] === '[')
- ignore = true;
- else if(env[i] === ']')
- ignore = false;
- else if(env[i] === ',' && ignore === false){
+function findComma(env) {
+ let nestingDepth = 0;
+ for (let i = 0; i < env.length; i++) {
+ if (env[i] === "[")
+ nestingDepth += 1;
+ else if (env[i] === "]")
+ nestingDepth -= 1;
+ else if (env[i] === "," && nestingDepth === 0) {
return i;
}
}
-
+
return -1;
}
/**
* Splits the environment variable around commas not enclosed in brackets.
* @param {String} env - The environment variable
- * @return {String[]} Array of strings containing the configurations
- * e.g. ["Toolbars[onlyNavBar,allToolbars]","DevTools[jsdebugger,webconsole]","Tabs"]
+ * @return {String[]} Array of strings containing the configurations
+ * e.g. ["Toolbars[onlyNavBar,allToolbars]","DevTools[jsdebugger,webconsole]","Tabs"]
*/
-function splitEnv(env){
+function splitEnv(env) {
let result = [];
-
+
let commaIndex = findComma(env);
- while( commaIndex != -1 ){
+ while ( commaIndex != -1 ) {
result.push( env.slice(0, commaIndex).trim() );
- env = env.slice(commaIndex+1);
+ env = env.slice(commaIndex + 1);
commaIndex = findComma(env);
}
result.push( env.trim() );
-
return result;
}
add_task(async function capture() {
let setsEnv = env.get("MOZSCREENSHOTS_SETS");
if (!setsEnv) {
ok(true, "MOZSCREENSHOTS_SETS wasn't specified so there's nothing to capture");
return;
}
- let sets = splitEnv(setsEnv);
+ let sets = splitEnv(setsEnv.trim());
await TestRunner.start(sets);
});
--- a/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm
+++ b/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm
@@ -126,33 +126,31 @@ this.TestRunner = {
let match = /\[([^\]]+)\]$/.exec(setName);
if (!match) {
throw new Error(`Invalid restrictions in ${setName}`);
}
// Trim the restrictions from the set name.
setName = setName.slice(0, match.index);
restrictions = match[1].split(",").reduce((set, name) =>
set.add(name.trim()), new Set());
-
}
try {
let imported = {};
Cu.import("chrome://mozscreenshots/content/configurations/" + setName + ".jsm",
imported);
imported[setName].init(this._libDir);
let configurationNames = Object.keys(imported[setName].configurations);
if (!configurationNames.length) {
throw new Error(setName + " has no configurations for this environment");
}
- //Checks to see if nonexistent configuration have been specified
- if(restrictions != null) {
- for(let restriction of restrictions){
- if( !configurationNames.includes(restriction) ){
- throw new Error(restriction + " is a nonexistent configuration");
- }
+ // Checks to see if nonexistent configuration have been specified
+ if (restrictions) {
+ let incorrectConfigs = [...restrictions].filter(r => !configurationNames.includes(r) );
+ if (incorrectConfigs.length > 0) {
+ throw new Error("non existent configurations: " + incorrectConfigs);
}
}
let configurations = [];
for (let config of configurationNames) {
// Automatically set the name property of the configuration object to
// its name from the configuration object.
imported[setName].configurations[config].name = config;
// Filter restricted configurations.
--- a/npm-shrinkwrap.json
+++ b/npm-shrinkwrap.json
@@ -999,34 +999,34 @@
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz",
"integrity": "sha1-7b+JA/ZvfOL46v1s7tZeJkyDGzU="
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
},
+ "string_decoder": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
+ "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
+ "requires": {
+ "safe-buffer": "5.1.1"
+ }
+ },
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"requires": {
"code-point-at": "1.1.0",
"is-fullwidth-code-point": "1.0.0",
"strip-ansi": "3.0.1"
}
},
- "string_decoder": {
- "version": "1.0.3",
- "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
- "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
- "requires": {
- "safe-buffer": "5.1.1"
- }
- },
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "2.1.1"
}
},