Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function format(value: T, fmt = Format.Yaml): string {
value = convertToPrintable(value) || {};
switch (fmt) {
case Format.Json:
return JSON.stringify(value, undefined, 2);
case Format.Json5:
return json5.stringify(value, undefined, 2);
case Format.Yaml:
return yaml.safeDump(value, {
indent: 2,
schema: yaml.JSON_SCHEMA,
sortKeys: true,
});
default:
return assertNever(fmt);
}
}
export function format(value: T, fmt = Format.Yaml): string {
value = convertToPrintable(value) || {};
switch (fmt) {
case Format.Json:
return JSON.stringify(value, undefined, 2);
case Format.Json5:
return json5.stringify(value, undefined, 2);
case Format.Yaml:
return yaml.safeDump(value, {
indent: 2,
schema: yaml.JSON_SCHEMA,
sortKeys: true,
});
default:
return assertNever(fmt);
}
}
public run({command: _command, ...config}: LintCommand) {
const newContent = format>(
{
...this.options,
...config,
fix: config.fix || undefined,
reportUselessDirectives: config.reportUselessDirectives || undefined,
references: config.references || undefined,
},
Format.Yaml,
);
const filePath = path.join(this.directories.getCurrentDirectory(), '.fimbullinter.yaml');
if (newContent.trim() === '{}') {
try {
this.fs.remove(filePath);
this.logger.log("Removed '.fimbullinter.yaml'.");
} catch {}
} else {
this.fs.writeFile(filePath, newContent);
this.logger.log("Updated '.fimbullinter.yaml'.");
}
return true;
}
}