all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Sterz <s.sterz@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-eslint] switch to using `Command.opts()` to access options
Date: Wed, 30 Aug 2023 11:24:29 +0200	[thread overview]
Message-ID: <20230830092429.108551-1-s.sterz@proxmox.com> (raw)

this fixes an issue  where the options where not properly passed to
eslint, which rendered them useless. uses the `opts()` function to
access them. see [1] for more on info on option parsing with
commander.

[1]: https://www.npmjs.com/package/commander#user-content-options

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
---

not sure how we handle this, but might need a:

Reported-by: Max Carrara <m.carrara@proxmox.com>

 src/bin/app.js | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/bin/app.js b/src/bin/app.js
index 48ae043..7d0088f 100644
--- a/src/bin/app.js
+++ b/src/bin/app.js
@@ -27,13 +27,14 @@ program.on('--help', function() {
 });
 
 program.parse(process.argv);
+let options = program.opts();
 
-if (program.config && program.extend) {
+if (options.config && options.extend) {
     console.error('Cannot use both, --config and --extend, at the same time!');
     process.exit(1);
 }
 
-if (program.args.length < 1 && !program.outputConfig) {
+if (program.args.length < 1 && !options.outputConfig) {
     program.help();
 }
 
@@ -44,8 +45,8 @@ if (!paths.length) {
 }
 
 let threadCount = 4;
-if (program.threads) {
-    threadCount = program.threads;
+if (options.threads) {
+    threadCount = options.threads;
 }
 
 const defaultConfig = {
@@ -274,16 +275,16 @@ let pathExpand = (p) => {
 };
 
 let config = defaultConfig;
-if (program.config) {
+if (options.config) {
     config = {
-	"extends": pathExpand(program.config),
+	"extends": pathExpand(options.config),
     };
-} else if (program.extend) {
-    config.extends = pathExpand(program.extend);
+} else if (options.extend) {
+    config.extends = pathExpand(options.extend);
     console.log(`Extend with path: ${config.extends}`);
 }
 
-if (program.outputConfig) {
+if (options.outputConfig) {
     let cfg = JSON.stringify(config, null, 2);
     console.log(cfg);
     process.exit(0);
@@ -292,7 +293,7 @@ if (program.outputConfig) {
 const cliOptions = {
     baseConfig: config,
     useEslintrc: true,
-    fix: !!program.fix,
+    fix: !!options.fix,
     cwd: process.cwd(),
 };
 
@@ -322,7 +323,7 @@ results.forEach(function(result) {
     let filename = path.relative(process.cwd(), result.filePath);
     let msgs = result.messages;
     let max_sev = 0;
-    if (!!program.fix && result.output) {
+    if (!!options.fix && result.output) {
 	fixes++;
     }
     if (msgs.length <= 0) {
@@ -337,7 +338,7 @@ results.forEach(function(result) {
 	let msg = `: line ${color.bold(e.line)} col ${color.bold(e.column)}: ${e.ruleId}`;
 	if (e.severity === 1) {
 	    msg = color.yellow("WARN" + msg);
-	    if (exitcode < 1 && !!program.strict) {
+	    if (exitcode < 1 && !!options.strict) {
 		exitcode = 1;
 	    }
 	} else if (e.severity === 2) {
@@ -351,7 +352,7 @@ results.forEach(function(result) {
 	if (e.message) {
 	    msg += ` - ${e.message}`;
 	}
-	if (!program.fix && e.fix) {
+	if (!options.fix && e.fix) {
 	    fixes++;
 	    msg += ' (*)';
 	}
@@ -386,7 +387,7 @@ if (results.length > 1) {
 }
 console.log('------------------------------------------------------------');
 
-if (program.fix) {
+if (options.fix) {
     if (fixes > 0) {
 	console.log(`Writing ${color.bold(fixes)} fixed files...`);
 	await eslint.ESLint.outputFixes(results);
-- 
2.39.2





             reply	other threads:[~2023-08-30  9:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30  9:24 Stefan Sterz [this message]
2023-08-30  9:39 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230830092429.108551-1-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal