import { Rule } from "../rule"; import { Context } from "../context"; import { Options } from "../options"; import { Client } from "../client"; export default class ResourceName extends Rule { private readonly type: string | null; private readonly pattern: string; constructor(context: Context, options: Options) { super(context, options); this.pattern = options.string("pattern"); this.type = options.string("type", null); } async run(client: Client): Promise { const pattern = new RegExp(`^${this.pattern}$`); const resources = await client.listResources(); for (const resource of resources) { if (this.type && resource.type !== this.type) { continue; } if (resource.name && !resource.name.match(pattern)) { this.report(resource, "resourceNameDoesNotMatchPattern", { name: resource.name, pattern: pattern.toString() }); } } } }