Skip to content

Commit d745ad4

Browse files
authored
feat(core): add lint on diff and sync in default (#155)
1 parent 1ca4d2c commit d745ad4

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

apps/cli/src/command/diff.command.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import YAML from 'yaml';
88
import { DifferV3 } from '../differ/differv3';
99
import { SignaleRenderer } from '../utils/listr';
1010
import { LoadRemoteConfigurationTask } from './dump.command';
11-
import { BackendCommand } from './helper';
11+
import { BackendCommand, NoLintOption } from './helper';
12+
import { LintTask } from './lint.command';
1213
import { BackendOptions } from './typing';
1314
import {
1415
fillLabels,
@@ -22,6 +23,7 @@ import {
2223

2324
type DiffOptions = BackendOptions & {
2425
file: Array<string>;
26+
lint: boolean;
2527
};
2628

2729
export interface TaskContext {
@@ -163,6 +165,7 @@ export const DiffCommand = new BackendCommand<DiffOptions>(
163165
'The files you want to synchronize, can be set more than one.',
164166
(filePath, files: Array<string> = []) => files.concat(filePath),
165167
)
168+
.addOption(NoLintOption)
166169
.addExample('adc diff -f service-a.yaml -f service-b.yaml')
167170
.handle(async (opts) => {
168171
const backend = loadBackend(opts.backend, opts);
@@ -175,6 +178,7 @@ export const DiffCommand = new BackendCommand<DiffOptions>(
175178
opts.includeResourceType,
176179
opts.excludeResourceType,
177180
),
181+
opts.lint ? LintTask() : { task: () => undefined },
178182
LoadRemoteConfigurationTask({
179183
backend,
180184
labelSelector: opts.labelSelector,

apps/cli/src/command/helper.ts

+2
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,5 @@ export class BackendCommand<OPTS extends object = object> extends BaseCommand {
203203
);
204204
}
205205
}
206+
207+
export const NoLintOption = new Option('--no-lint', 'Disable lint check');

apps/cli/src/command/sync.command.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import {
77
TaskContext,
88
} from './diff.command';
99
import { LoadRemoteConfigurationTask } from './dump.command';
10-
import { BackendCommand } from './helper';
10+
import { BackendCommand, NoLintOption } from './helper';
11+
import { LintTask } from './lint.command';
1112
import { BackendOptions } from './typing';
1213
import { loadBackend } from './utils';
1314

1415
type SyncOption = BackendOptions & {
1516
file: Array<string>;
17+
lint: boolean;
1618
};
1719

1820
export const SyncCommand = new BackendCommand<SyncOption>(
@@ -24,6 +26,7 @@ export const SyncCommand = new BackendCommand<SyncOption>(
2426
'The files you want to synchronize, can be set more than one.',
2527
(filePath, files: Array<string> = []) => files.concat(filePath),
2628
)
29+
.addOption(NoLintOption)
2730
.addExample('adc sync -f service-a.yaml -f service-b.yaml')
2831
.handle(async (opts) => {
2932
const backend = loadBackend(opts.backend, opts);
@@ -36,6 +39,7 @@ export const SyncCommand = new BackendCommand<SyncOption>(
3639
opts.includeResourceType,
3740
opts.excludeResourceType,
3841
),
42+
opts.lint ? LintTask() : { task: () => undefined },
3943
LoadRemoteConfigurationTask({
4044
backend,
4145
labelSelector: opts.labelSelector,

apps/cli/src/linter/schema.ts

+24-26
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,30 @@ const upstreamSchema = z
6565
key: z.string().optional(),
6666
checks: z
6767
.object({
68-
active: z
69-
.object({
70-
type: upstreamHealthCheckType.optional(),
71-
timeout: z.number().default(1).optional(),
72-
concurrency: z.number().default(10).optional(),
73-
host: z.string(),
74-
port: portSchema,
75-
http_path: z.string().default('/').optional(),
76-
https_verify_cert: z.boolean().default(true).optional(),
77-
http_request_headers: z.array(z.string()).min(1).optional(),
78-
healthy: z
79-
.object({
80-
interval: z.number().int().min(1).default(1),
81-
})
82-
.merge(upstreamHealthCheckPassiveHealthy)
83-
.strict()
84-
.optional(),
85-
unhealthy: z
86-
.object({
87-
interval: z.number().int().min(1).default(1),
88-
})
89-
.merge(upstreamHealthCheckPassiveUnhealthy)
90-
.strict()
91-
.optional(),
92-
})
93-
.optional(),
68+
active: z.object({
69+
type: upstreamHealthCheckType.optional(),
70+
timeout: z.number().default(1).optional(),
71+
concurrency: z.number().default(10).optional(),
72+
host: z.string(),
73+
port: portSchema,
74+
http_path: z.string().default('/').optional(),
75+
https_verify_cert: z.boolean().default(true).optional(),
76+
http_request_headers: z.array(z.string()).min(1).optional(),
77+
healthy: z
78+
.object({
79+
interval: z.number().int().min(1).default(1),
80+
})
81+
.merge(upstreamHealthCheckPassiveHealthy)
82+
.strict()
83+
.optional(),
84+
unhealthy: z
85+
.object({
86+
interval: z.number().int().min(1).default(1),
87+
})
88+
.merge(upstreamHealthCheckPassiveUnhealthy)
89+
.strict()
90+
.optional(),
91+
}),
9492
passive: z
9593
.object({
9694
type: upstreamHealthCheckType.optional(),

0 commit comments

Comments
 (0)