Skip to content

Commit

Permalink
feat: add lint in default
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Jul 20, 2024
1 parent 1ca4d2c commit d5c8f05
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
6 changes: 5 additions & 1 deletion apps/cli/src/command/diff.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import YAML from 'yaml';
import { DifferV3 } from '../differ/differv3';
import { SignaleRenderer } from '../utils/listr';
import { LoadRemoteConfigurationTask } from './dump.command';
import { BackendCommand } from './helper';
import { BackendCommand, NoLintOption } from './helper';
import { LintTask } from './lint.command';
import { BackendOptions } from './typing';
import {
fillLabels,
Expand All @@ -22,6 +23,7 @@ import {

type DiffOptions = BackendOptions & {
file: Array<string>;
lint: boolean;
};

export interface TaskContext {
Expand Down Expand Up @@ -163,6 +165,7 @@ export const DiffCommand = new BackendCommand<DiffOptions>(
'The files you want to synchronize, can be set more than one.',
(filePath, files: Array<string> = []) => files.concat(filePath),
)
.addOption(NoLintOption)
.addExample('adc diff -f service-a.yaml -f service-b.yaml')
.handle(async (opts) => {
const backend = loadBackend(opts.backend, opts);
Expand All @@ -175,6 +178,7 @@ export const DiffCommand = new BackendCommand<DiffOptions>(
opts.includeResourceType,
opts.excludeResourceType,
),
opts.lint ? LintTask() : { task: () => undefined },
LoadRemoteConfigurationTask({
backend,
labelSelector: opts.labelSelector,
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/command/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,5 @@ export class BackendCommand<OPTS extends object = object> extends BaseCommand {
);
}
}

export const NoLintOption = new Option('--no-lint', 'Disable lint check');
6 changes: 5 additions & 1 deletion apps/cli/src/command/sync.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
TaskContext,
} from './diff.command';
import { LoadRemoteConfigurationTask } from './dump.command';
import { BackendCommand } from './helper';
import { BackendCommand, NoLintOption } from './helper';
import { LintTask } from './lint.command';
import { BackendOptions } from './typing';
import { loadBackend } from './utils';

type SyncOption = BackendOptions & {
file: Array<string>;
lint: boolean;
};

export const SyncCommand = new BackendCommand<SyncOption>(
Expand All @@ -24,6 +26,7 @@ export const SyncCommand = new BackendCommand<SyncOption>(
'The files you want to synchronize, can be set more than one.',
(filePath, files: Array<string> = []) => files.concat(filePath),
)
.addOption(NoLintOption)
.addExample('adc sync -f service-a.yaml -f service-b.yaml')
.handle(async (opts) => {
const backend = loadBackend(opts.backend, opts);
Expand All @@ -36,6 +39,7 @@ export const SyncCommand = new BackendCommand<SyncOption>(
opts.includeResourceType,
opts.excludeResourceType,
),
opts.lint ? LintTask() : { task: () => undefined },
LoadRemoteConfigurationTask({
backend,
labelSelector: opts.labelSelector,
Expand Down
50 changes: 24 additions & 26 deletions apps/cli/src/linter/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,30 @@ const upstreamSchema = z
key: z.string().optional(),
checks: z
.object({
active: z
.object({
type: upstreamHealthCheckType.optional(),
timeout: z.number().default(1).optional(),
concurrency: z.number().default(10).optional(),
host: z.string(),
port: portSchema,
http_path: z.string().default('/').optional(),
https_verify_cert: z.boolean().default(true).optional(),
http_request_headers: z.array(z.string()).min(1).optional(),
healthy: z
.object({
interval: z.number().int().min(1).default(1),
})
.merge(upstreamHealthCheckPassiveHealthy)
.strict()
.optional(),
unhealthy: z
.object({
interval: z.number().int().min(1).default(1),
})
.merge(upstreamHealthCheckPassiveUnhealthy)
.strict()
.optional(),
})
.optional(),
active: z.object({
type: upstreamHealthCheckType.optional(),
timeout: z.number().default(1).optional(),
concurrency: z.number().default(10).optional(),
host: z.string(),
port: portSchema,
http_path: z.string().default('/').optional(),
https_verify_cert: z.boolean().default(true).optional(),
http_request_headers: z.array(z.string()).min(1).optional(),
healthy: z
.object({
interval: z.number().int().min(1).default(1),
})
.merge(upstreamHealthCheckPassiveHealthy)
.strict()
.optional(),
unhealthy: z
.object({
interval: z.number().int().min(1).default(1),
})
.merge(upstreamHealthCheckPassiveUnhealthy)
.strict()
.optional(),
}),
passive: z
.object({
type: upstreamHealthCheckType.optional(),
Expand Down

0 comments on commit d5c8f05

Please sign in to comment.