Skip to content

Commit 983bfc2

Browse files
committed
Fix lint issues in config command implementation
1 parent e40332c commit 983bfc2

File tree

3 files changed

+74
-41
lines changed

3 files changed

+74
-41
lines changed

packages/cli/src/commands/config.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import chalk from 'chalk';
2-
import { Logger, LogLevel } from 'mycoder-agent';
2+
import { Logger } from 'mycoder-agent';
33

44
import { SharedOptions } from '../options.js';
55
import { getConfig, updateConfig } from '../settings/config.js';
66
import { nameToLogIndex } from '../utils/nameToLogIndex.js';
77

8-
import type { CommandModule, Argv, ArgumentsCamelCase } from 'yargs';
8+
import type { CommandModule, ArgumentsCamelCase } from 'yargs';
99

10-
interface ConfigOptions extends SharedOptions {
10+
export interface ConfigOptions extends SharedOptions {
1111
command: 'get' | 'set' | 'list';
1212
key?: string;
1313
value?: string;
@@ -33,8 +33,14 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
3333
type: 'string',
3434
})
3535
.example('$0 config list', 'List all configuration values')
36-
.example('$0 config get githubMode', 'Get the value of githubMode setting')
37-
.example('$0 config set githubMode true', 'Enable GitHub mode') as any;
36+
.example(
37+
'$0 config get githubMode',
38+
'Get the value of githubMode setting',
39+
)
40+
.example(
41+
'$0 config set githubMode true',
42+
'Enable GitHub mode',
43+
) as any; // eslint-disable-line @typescript-eslint/no-explicit-any
3844
},
3945
handler: async (argv: ArgumentsCamelCase<ConfigOptions>) => {
4046
const logger = new Logger({
@@ -61,7 +67,9 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
6167
}
6268

6369
if (argv.key in config) {
64-
logger.info(`${argv.key}: ${chalk.green(config[argv.key as keyof typeof config])}`);
70+
logger.info(
71+
`${argv.key}: ${chalk.green(config[argv.key as keyof typeof config])}`,
72+
);
6573
} else {
6674
logger.error(`Configuration key '${argv.key}' not found`);
6775
}
@@ -79,28 +87,35 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
7987
logger.error('Value is required for set command');
8088
return;
8189
}
82-
90+
8391
// Parse the value based on current type or infer boolean/number
84-
let parsedValue: any = argv.value;
85-
92+
let parsedValue: string | boolean | number = argv.value;
93+
8694
// Check if config already exists to determine type
8795
if (argv.key in config) {
8896
if (typeof config[argv.key as keyof typeof config] === 'boolean') {
8997
parsedValue = argv.value.toLowerCase() === 'true';
90-
} else if (typeof config[argv.key as keyof typeof config] === 'number') {
98+
} else if (
99+
typeof config[argv.key as keyof typeof config] === 'number'
100+
) {
91101
parsedValue = Number(argv.value);
92102
}
93103
} else {
94104
// If config doesn't exist yet, try to infer type
95-
if (argv.value.toLowerCase() === 'true' || argv.value.toLowerCase() === 'false') {
105+
if (
106+
argv.value.toLowerCase() === 'true' ||
107+
argv.value.toLowerCase() === 'false'
108+
) {
96109
parsedValue = argv.value.toLowerCase() === 'true';
97110
} else if (!isNaN(Number(argv.value))) {
98111
parsedValue = Number(argv.value);
99112
}
100113
}
101-
114+
102115
const updatedConfig = updateConfig({ [argv.key]: parsedValue });
103-
logger.info(`Updated ${argv.key}: ${chalk.green(updatedConfig[argv.key as keyof typeof updatedConfig])}`);
116+
logger.info(
117+
`Updated ${argv.key}: ${chalk.green(updatedConfig[argv.key as keyof typeof updatedConfig])}`,
118+
);
104119
return;
105120
}
106121

packages/cli/src/settings/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as fs from 'fs';
2-
import * as os from 'os';
32
import * as path from 'path';
43

54
import { getSettingsDir } from './settings.js';
@@ -20,7 +19,7 @@ export const getConfig = (): Config => {
2019
}
2120
try {
2221
return JSON.parse(fs.readFileSync(configFile, 'utf-8'));
23-
} catch (error) {
22+
} catch {
2423
return defaultConfig;
2524
}
2625
};
Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { Logger } from 'mycoder-agent';
12
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
23

34
import { command } from '../../src/commands/config.js';
5+
import type { ConfigOptions } from '../../src/commands/config.js';
6+
import type { ArgumentsCamelCase } from 'yargs';
47
import { getConfig, updateConfig } from '../../src/settings/config.js';
5-
import { Logger } from 'mycoder-agent';
68

79
// Mock dependencies
810
vi.mock('../../src/settings/config.js', () => ({
@@ -30,107 +32,124 @@ vi.mock('../../src/utils/nameToLogIndex.js', () => ({
3032

3133
// Skip tests for now - they need to be rewritten for the new command structure
3234
describe.skip('Config Command', () => {
33-
let mockLogger: { info: any; error: any };
34-
35+
let mockLogger: { info: jest.Mock; error: jest.Mock };
36+
3537
beforeEach(() => {
3638
mockLogger = {
3739
info: vi.fn(),
3840
error: vi.fn(),
3941
};
40-
vi.mocked(Logger).mockImplementation(() => mockLogger as any);
42+
vi.mocked(Logger).mockImplementation(() => mockLogger as unknown as Logger);
4143
vi.mocked(getConfig).mockReturnValue({ githubMode: false });
42-
vi.mocked(updateConfig).mockImplementation((config) => ({ githubMode: false, ...config }));
44+
vi.mocked(updateConfig).mockImplementation((config) => ({
45+
githubMode: false,
46+
...config,
47+
}));
4348
});
4449

4550
afterEach(() => {
4651
vi.resetAllMocks();
4752
});
4853

4954
it('should list all configuration values', async () => {
50-
await command.handler!({
55+
await command.handler!({
5156
_: ['config', 'config', 'list'],
5257
logLevel: 'info',
5358
interactive: false,
54-
command: 'list'
59+
command: 'list',
5560
} as any);
5661

5762
expect(getConfig).toHaveBeenCalled();
5863
expect(mockLogger.info).toHaveBeenCalledWith('Current configuration:');
59-
expect(mockLogger.info).toHaveBeenCalledWith(expect.stringContaining('githubMode'));
64+
expect(mockLogger.info).toHaveBeenCalledWith(
65+
expect.stringContaining('githubMode'),
66+
);
6067
});
6168

6269
it('should get a configuration value', async () => {
63-
await command.handler!({
70+
await command.handler!({
6471
_: ['config', 'config', 'get', 'githubMode'],
6572
logLevel: 'info',
6673
interactive: false,
6774
command: 'get',
68-
key: 'githubMode'
75+
key: 'githubMode',
6976
} as any);
7077

7178
expect(getConfig).toHaveBeenCalled();
72-
expect(mockLogger.info).toHaveBeenCalledWith(expect.stringContaining('githubMode'));
79+
expect(mockLogger.info).toHaveBeenCalledWith(
80+
expect.stringContaining('githubMode'),
81+
);
7382
});
7483

7584
it('should show error when getting non-existent key', async () => {
76-
await command.handler!({
85+
await command.handler!({
7786
_: ['config', 'config', 'get', 'nonExistentKey'],
7887
logLevel: 'info',
7988
interactive: false,
8089
command: 'get',
81-
key: 'nonExistentKey'
90+
key: 'nonExistentKey',
8291
} as any);
8392

84-
expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining("not found"));
93+
expect(mockLogger.error).toHaveBeenCalledWith(
94+
expect.stringContaining('not found'),
95+
);
8596
});
8697

8798
it('should set a configuration value', async () => {
88-
await command.handler!({
99+
await command.handler!({
89100
_: ['config', 'config', 'set', 'githubMode', 'true'],
90101
logLevel: 'info',
91102
interactive: false,
92103
command: 'set',
93104
key: 'githubMode',
94-
value: 'true'
105+
value: 'true',
95106
} as any);
96107

97108
expect(updateConfig).toHaveBeenCalledWith({ githubMode: true });
98-
expect(mockLogger.info).toHaveBeenCalledWith(expect.stringContaining('Updated'));
109+
expect(mockLogger.info).toHaveBeenCalledWith(
110+
expect.stringContaining('Updated'),
111+
);
99112
});
100113

101114
it('should handle missing key for set command', async () => {
102-
await command.handler!({
115+
await command.handler!({
103116
_: ['config', 'config', 'set'],
104117
logLevel: 'info',
105118
interactive: false,
106119
command: 'set',
107-
key: undefined
120+
key: undefined,
108121
} as any);
109122

110-
expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining('Key is required'));
123+
expect(mockLogger.error).toHaveBeenCalledWith(
124+
expect.stringContaining('Key is required'),
125+
);
111126
});
112127

113128
it('should handle missing value for set command', async () => {
114-
await command.handler!({
129+
await command.handler!({
115130
_: ['config', 'config', 'set', 'githubMode'],
116131
logLevel: 'info',
117132
interactive: false,
118133
command: 'set',
119134
key: 'githubMode',
120-
value: undefined
135+
value: undefined,
121136
} as any);
122137

123-
expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining('Value is required'));
138+
expect(mockLogger.error).toHaveBeenCalledWith(
139+
expect.stringContaining('Value is required'),
140+
);
124141
});
125142

126143
it('should handle unknown command', async () => {
127-
await command.handler!({
144+
await command.handler!({
128145
_: ['config', 'config', 'unknown'],
129146
logLevel: 'info',
130147
interactive: false,
131-
command: 'unknown' as any
148+
command: 'unknown' as any,
132149
} as any);
133150

134-
expect(mockLogger.error).toHaveBeenCalledWith(expect.stringContaining('Unknown config command'));
151+
expect(mockLogger.error).toHaveBeenCalledWith(
152+
expect.stringContaining('Unknown config command'),
153+
);
135154
});
136155
});

0 commit comments

Comments
 (0)