Skip to content

Commit 95584f1

Browse files
committed
🔧 Fix lint errors
1 parent 4b729c3 commit 95584f1

File tree

14 files changed

+584
-247
lines changed

14 files changed

+584
-247
lines changed

src/cli.js

Lines changed: 90 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#!/usr/bin/env node
22
import 'dotenv/config';
33
import { program } from 'commander';
4+
import { apiCommand, validateApiOptions } from './commands/api.js';
5+
import {
6+
baselinesCommand,
7+
validateBaselinesOptions,
8+
} from './commands/baselines.js';
9+
import { buildsCommand, validateBuildsOptions } from './commands/builds.js';
10+
import {
11+
comparisonsCommand,
12+
validateComparisonsOptions,
13+
} from './commands/comparisons.js';
14+
import { configCommand, validateConfigOptions } from './commands/config-cmd.js';
415
import { doctorCommand, validateDoctorOptions } from './commands/doctor.js';
516
import {
617
finalizeCommand,
@@ -17,14 +28,13 @@ import {
1728
projectTokenCommand,
1829
validateProjectOptions,
1930
} from './commands/project.js';
31+
import {
32+
approveCommand,
33+
commentCommand,
34+
rejectCommand,
35+
} from './commands/review.js';
2036
import { runCommand, validateRunOptions } from './commands/run.js';
2137
import { statusCommand, validateStatusOptions } from './commands/status.js';
22-
import { buildsCommand, validateBuildsOptions } from './commands/builds.js';
23-
import { comparisonsCommand, validateComparisonsOptions } from './commands/comparisons.js';
24-
import { configCommand, validateConfigOptions } from './commands/config-cmd.js';
25-
import { baselinesCommand, validateBaselinesOptions } from './commands/baselines.js';
26-
import { apiCommand, validateApiOptions } from './commands/api.js';
27-
import { approveCommand, rejectCommand, commentCommand } from './commands/review.js';
2838
import { tddCommand, validateTddOptions } from './commands/tdd.js';
2939
import {
3040
runDaemonChild,
@@ -90,10 +100,29 @@ const formatHelp = (cmd, helper) => {
90100
key: 'core',
91101
icon: '▸',
92102
title: 'Core',
93-
names: ['run', 'tdd', 'upload', 'status', 'finalize', 'preview', 'builds', 'comparisons'],
103+
names: [
104+
'run',
105+
'tdd',
106+
'upload',
107+
'status',
108+
'finalize',
109+
'preview',
110+
'builds',
111+
'comparisons',
112+
],
113+
},
114+
{
115+
key: 'review',
116+
icon: '▸',
117+
title: 'Review',
118+
names: ['approve', 'reject', 'comment'],
119+
},
120+
{
121+
key: 'setup',
122+
icon: '▸',
123+
title: 'Setup',
124+
names: ['init', 'doctor', 'config', 'baselines'],
94125
},
95-
{ key: 'review', icon: '▸', title: 'Review', names: ['approve', 'reject', 'comment'] },
96-
{ key: 'setup', icon: '▸', title: 'Setup', names: ['init', 'doctor', 'config', 'baselines'] },
97126
{ key: 'advanced', icon: '▸', title: 'Advanced', names: ['api'] },
98127
{
99128
key: 'auth',
@@ -114,7 +143,14 @@ const formatHelp = (cmd, helper) => {
114143
},
115144
];
116145

117-
let grouped = { core: [], setup: [], advanced: [], auth: [], project: [], other: [] };
146+
let grouped = {
147+
core: [],
148+
setup: [],
149+
advanced: [],
150+
auth: [],
151+
project: [],
152+
other: [],
153+
};
118154

119155
for (let command of commands) {
120156
let name = command.name();
@@ -243,7 +279,10 @@ program
243279
'--log-level <level>',
244280
'Log level: debug, info, warn, error (default: info, or VIZZLY_LOG_LEVEL env var)'
245281
)
246-
.option('--json [fields]', 'JSON output, optionally specify fields (e.g., --json id,status,branch)')
282+
.option(
283+
'--json [fields]',
284+
'JSON output, optionally specify fields (e.g., --json id,status,branch)'
285+
)
247286
.option('--color', 'Force colored output (even in non-TTY)')
248287
.option('--no-color', 'Disable colored output')
249288
.option(
@@ -591,9 +630,17 @@ program
591630
.description('List and query builds')
592631
.option('-b, --build <id>', 'Get a specific build by ID')
593632
.option('--branch <branch>', 'Filter by branch')
594-
.option('--status <status>', 'Filter by status (created, pending, processing, completed, failed)')
633+
.option(
634+
'--status <status>',
635+
'Filter by status (created, pending, processing, completed, failed)'
636+
)
595637
.option('--environment <env>', 'Filter by environment')
596-
.option('--limit <n>', 'Maximum results to return (1-250)', val => parseInt(val, 10), 20)
638+
.option(
639+
'--limit <n>',
640+
'Maximum results to return (1-250)',
641+
val => parseInt(val, 10),
642+
20
643+
)
597644
.option('--offset <n>', 'Skip first N results', val => parseInt(val, 10), 0)
598645
.option('--comparisons', 'Include comparisons when fetching a specific build')
599646
.action(async options => {
@@ -620,7 +667,12 @@ program
620667
.option('--name <pattern>', 'Search comparisons by name (supports wildcards)')
621668
.option('--status <status>', 'Filter by status (identical, new, changed)')
622669
.option('--branch <branch>', 'Filter by branch (for name search)')
623-
.option('--limit <n>', 'Maximum results to return (1-250)', val => parseInt(val, 10), 50)
670+
.option(
671+
'--limit <n>',
672+
'Maximum results to return (1-250)',
673+
val => parseInt(val, 10),
674+
50
675+
)
624676
.option('--offset <n>', 'Skip first N results', val => parseInt(val, 10), 0)
625677
.action(async options => {
626678
const globalOptions = program.opts();
@@ -641,7 +693,10 @@ program
641693
program
642694
.command('config')
643695
.description('Display current configuration')
644-
.argument('[key]', 'Specific config key to get (dot notation, e.g., comparison.threshold)')
696+
.argument(
697+
'[key]',
698+
'Specific config key to get (dot notation, e.g., comparison.threshold)'
699+
)
645700
.action(async (key, options) => {
646701
const globalOptions = program.opts();
647702

@@ -683,10 +738,22 @@ program
683738
.command('api')
684739
.description('Make raw API requests (for power users)')
685740
.argument('<endpoint>', 'API endpoint (e.g., /sdk/builds)')
686-
.option('-X, --method <method>', 'HTTP method (GET or POST for approve/reject/comment)', 'GET')
741+
.option(
742+
'-X, --method <method>',
743+
'HTTP method (GET or POST for approve/reject/comment)',
744+
'GET'
745+
)
687746
.option('-d, --data <json>', 'Request body (JSON)')
688-
.option('-H, --header <header>', 'Add header (key:value), can be repeated', (val, prev) => (prev ? [...prev, val] : [val]))
689-
.option('-q, --query <param>', 'Add query param (key=value), can be repeated', (val, prev) => (prev ? [...prev, val] : [val]))
747+
.option(
748+
'-H, --header <header>',
749+
'Add header (key:value), can be repeated',
750+
(val, prev) => (prev ? [...prev, val] : [val])
751+
)
752+
.option(
753+
'-q, --query <param>',
754+
'Add query param (key=value), can be repeated',
755+
(val, prev) => (prev ? [...prev, val] : [val])
756+
)
690757
.action(async (endpoint, options) => {
691758
const globalOptions = program.opts();
692759

@@ -728,7 +795,11 @@ program
728795
.description('Add a comment to a build')
729796
.argument('<build-id>', 'Build ID to comment on')
730797
.argument('<message>', 'Comment message')
731-
.option('-t, --type <type>', 'Comment type: general, approval, rejection', 'general')
798+
.option(
799+
'-t, --type <type>',
800+
'Comment type: general, approval, rejection',
801+
'general'
802+
)
732803
.action(async (buildId, message, options) => {
733804
const globalOptions = program.opts();
734805
await commentCommand(buildId, message, options, globalOptions);

src/commands/api.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import * as defaultOutput from '../utils/output.js';
1313
* @param {Object} globalOptions - Global CLI options
1414
* @param {Object} deps - Dependencies for testing
1515
*/
16-
export async function apiCommand(endpoint, options = {}, globalOptions = {}, deps = {}) {
16+
export async function apiCommand(
17+
endpoint,
18+
options = {},
19+
globalOptions = {},
20+
deps = {}
21+
) {
1722
let {
1823
loadConfig = defaultLoadConfig,
1924
createApiClient = defaultCreateApiClient,
@@ -42,7 +47,9 @@ export async function apiCommand(endpoint, options = {}, globalOptions = {}, dep
4247
}
4348

4449
// Normalize endpoint
45-
let normalizedEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
50+
let normalizedEndpoint = endpoint.startsWith('/')
51+
? endpoint
52+
: `/${endpoint}`;
4653
if (!normalizedEndpoint.startsWith('/api/')) {
4754
normalizedEndpoint = `/api${normalizedEndpoint}`;
4855
}
@@ -55,7 +62,9 @@ export async function apiCommand(endpoint, options = {}, globalOptions = {}, dep
5562
output.error(
5663
`POST not allowed for ${normalizedEndpoint}. Only approve, reject, and comment endpoints support POST.`
5764
);
58-
output.hint('Use GET for queries, or use dedicated commands (vizzly approve, vizzly reject, vizzly comment)');
65+
output.hint(
66+
'Use GET for queries, or use dedicated commands (vizzly approve, vizzly reject, vizzly comment)'
67+
);
5968
exit(1);
6069
return;
6170
}
@@ -71,7 +80,9 @@ export async function apiCommand(endpoint, options = {}, globalOptions = {}, dep
7180
// Add headers
7281
let headers = {};
7382
if (options.header) {
74-
let headerList = Array.isArray(options.header) ? options.header : [options.header];
83+
let headerList = Array.isArray(options.header)
84+
? options.header
85+
: [options.header];
7586
for (let h of headerList) {
7687
let [key, ...valueParts] = h.split(':');
7788
if (key && valueParts.length > 0) {
@@ -93,7 +104,9 @@ export async function apiCommand(endpoint, options = {}, globalOptions = {}, dep
93104
// Add query parameters
94105
if (options.query) {
95106
let params = new URLSearchParams();
96-
let queryList = Array.isArray(options.query) ? options.query : [options.query];
107+
let queryList = Array.isArray(options.query)
108+
? options.query
109+
: [options.query];
97110
for (let q of queryList) {
98111
let [key, ...valueParts] = q.split('=');
99112
if (key && valueParts.length > 0) {
@@ -102,7 +115,8 @@ export async function apiCommand(endpoint, options = {}, globalOptions = {}, dep
102115
}
103116
let queryString = params.toString();
104117
if (queryString) {
105-
normalizedEndpoint += (normalizedEndpoint.includes('?') ? '&' : '?') + queryString;
118+
normalizedEndpoint +=
119+
(normalizedEndpoint.includes('?') ? '&' : '?') + queryString;
106120
}
107121
}
108122

@@ -198,7 +212,9 @@ export function validateApiOptions(endpoint, options = {}) {
198212
// Only GET is allowed by default
199213
// POST is allowed only for whitelisted endpoints
200214
if (method !== 'GET' && method !== 'POST') {
201-
errors.push(`Method ${method} not allowed. Use GET for queries or POST for approve/reject/comment.`);
215+
errors.push(
216+
`Method ${method} not allowed. Use GET for queries or POST for approve/reject/comment.`
217+
);
202218
}
203219

204220
return errors;

0 commit comments

Comments
 (0)