If the function returns true, the check will be set to pass.
If the function returns any other value, the check will be set to warn or fail based on the configured level.
import type { Check } from 'commonality';export default { message: 'Package has a CODEOWNER', validate: (ctx) => Boolean(ctx.codeowners.length),} satisfies Check;
import type { Check } from 'commonality';export default { message: 'Package has a CODEOWNER', validate: (ctx) => Boolean(ctx.codeowners.length),} satisfies Check;
export default { message: 'Package has a CODEOWNER', validate: (ctx) => Boolean(ctx.codeowners.length),};
Returning a message object allows you to modify the check’s default message and provide additional context about the status of the check.
import type { Check } from 'commonality';import { json, diff } from 'commonality';export default { message: 'Package has internal config', validate: (ctx) => { // ...validation logic if (fileExists) { return { // This message will override the default message message: 'File "internal-config.json" does not exist', // This path will be shown directly underneath the message for quicker debugging path: ctx.package.path, // This will be shown as a suggestion for how to fix the issue suggestion: diff(source, expected) }; } },} satisfies Check;
import type { Check } from 'commonality';import { json, diff } from 'commonality';export default { message: 'Package has internal config', validate: (ctx) => { // ...validation logic if (fileExists) { return { // This message will override the default message message: 'File "internal-config.json" does not exist', // This path will be shown directly underneath the message for quicker debugging path: ctx.package.path, // This will be shown as a suggestion for how to fix the issue suggestion: diff(source, expected) }; } },} satisfies Check;
import { json, diff } from 'commonality';export default { message: 'Package has internal config', validate: (ctx) => { // ...validation logic if (fileExists) { return { // A string that will override default message for the check message: 'File "internal-config.json" does not exist', // A string representing a path that will be shown directly underneath the check's message. path: ctx.package.path, // A string representing a suggestion for how to fix a failed check suggestion: diff(source, expected) }; } },}
A check’s fix function will only run on packages that where the check’s validate function has returned a falsey value. This function should update packages so that they pass the check’s validate function.
This function can be asynchronous.
We provide helper utilities like json and text to make it easier to read and write to files in fix functions.