From 6c864b9f5898b28afe8dc306b99121496fc80648 Mon Sep 17 00:00:00 2001 From: Benjamin Altpeter Date: Mon, 29 Jun 2020 14:33:08 +0200 Subject: [PATCH] Allow overriding the detected Electron version --- README.md | 5 ++++- src/index.js | 18 ++++++++++-------- src/runner.js | 5 +++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 31947cd..7c90b8c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ $ electronegativity -h | -r, --relative | show relative path for files | | -v, --verbose | show the description for the findings | | -u, --upgrade | run Electron upgrade checks, eg -u 7..8 to check upgrade from Electron 7 to 8 | +| -e, --electron-version | assume the set Electron version, overriding the detected one, eg -e 7.0.0 | | -h, --help | output usage information | @@ -86,7 +87,9 @@ run({ // show relative path for files (optional) isRelative: false, // run Electron upgrade checks, eg -u 7..8 to check upgrade from Electron 7 to 8 (optional) - electronUpgrade: '7..8' + electronUpgrade: '7..8', + // assume the set Electron version, overriding the detected one + electronVersion: '5.0.0' }) .then(result => console.log(result)) .catch(err => console.error(err)); diff --git a/src/index.js b/src/index.js index 8daffb8..d15ab32 100644 --- a/src/index.js +++ b/src/index.js @@ -8,11 +8,11 @@ import run from './runner.js'; const VER = require('../package.json').version; console.log(` -▄▄▄ ▄▄▌ ▄▄▄ .▄▄·▄▄▄▄▄▄▄ -▀▄.▀██• ▀▄.▀▐█ ▌•██ ▀▄ █▪ -▐▀▀▪██▪ ▐▀▀▪██ ▄▄▐█.▐▀▀▄ ▄█▀▄ -▐█▄▄▐█▌▐▐█▄▄▐███▌▐█▌▐█•█▐█▌.▐▌ - ▀▀▀.▀▀▀ ▀▀▀·▀▀▀ ▀▀▀.▀ ▀▀█▄▀▪ +▄▄▄ ▄▄▌ ▄▄▄ .▄▄·▄▄▄▄▄▄▄ +▀▄.▀██• ▀▄.▀▐█ ▌•██ ▀▄ █▪ +▐▀▀▪██▪ ▐▀▀▪██ ▄▄▐█.▐▀▀▄ ▄█▀▄ +▐█▄▄▐█▌▐▐█▄▄▐███▌▐█▌▐█•█▐█▌.▐▌ + ▀▀▀.▀▀▀ ▀▀▀·▀▀▀ ▀▀▀.▀ ▀▀█▄▀▪ ▐ ▄▄▄▄ .▄▄ • ▄▄▄▄▄▄▄▪ ▌ ▐▪▄▄▄▄▄▄· ▄▌ •█▌▐▀▄.▀▐█ ▀ ▐█ ▀•██ ██▪█·██•██ ▐█▪██▌ ▐█▐▐▐▀▀▪▄█ ▀█▄█▀▀█▐█.▐█▐█▐█▐█▐█.▐█▌▐█▪ @@ -33,6 +33,7 @@ program .option('-r, --relative', 'show relative path for files') .option('-v, --verbose', 'show the description for the findings') .option('-u, --upgrade ', 'run Electron upgrade checks, eg -u 7..8') + .option('-e, --electron-version ', 'assume the set Electron version, overriding the detected one, eg -e 7.0.0') .parse(process.argv); if(!program.input){ @@ -63,12 +64,13 @@ const forCli = true; run({ input, - output: program.output, + output: program.output, isSarif: program.fileFormat === 'sarif', customScan: program.checks, - severitySet: program.severity, + severitySet: program.severity, confidenceSet: program.confidence, isRelative: program.relative, isVerbose: program.verbose, - electronUpgrade: program.upgrade + electronUpgrade: program.upgrade, + electronVersionOverride: program.electronVersion }, forCli); diff --git a/src/runner.js b/src/runner.js index e9f90bc..3c0f310 100644 --- a/src/runner.js +++ b/src/runner.js @@ -29,7 +29,8 @@ export default async function run(options, forCli = false) { } await loader.load(options.input); - if (!loader.electron_version) + const electron_version = options.electronVersionOverride || loader.electron_version; + if (!electron_version) logger.warn("Couldn't detect Electron version, assuming v0.1.0. Defaults have probably changed for your actual version, please check manually."); if (options.severitySet) { @@ -96,7 +97,7 @@ export default async function run(options, forCli = false) { } } - const result = await finder.find(file, data, type, content, null, loader.electron_version); + const result = await finder.find(file, data, type, content, null, electron_version); issues.push(...result); } catch (error) { errors.push({ file: file, message: error.message, tolerable: false });