export async function buildifierLint()

in src/buildifier/buildifier.ts [60:107]


export async function buildifierLint(
  fileContent: string,
  type: BuildifierFileType,
  lintMode: "fix",
): Promise<string>;

/**
 * Invokes buildifier in lint mode and emits warnings indicating any issues that
 * were found.
 *
 * @param fileContent The BUILD or .bzl file content to process, which is sent
 *     via stdin.
 * @param type Indicates whether to treat the file content as a BUILD file or a
 *     .bzl file.
 * @param lintMode Indicates whether to warn about lint findings or fix them.
 * @returns An array of objects representing the lint issues that occurred.
 */
export async function buildifierLint(
  fileContent: string,
  type: BuildifierFileType,
  lintMode: "warn",
): Promise<IBuildifierWarning[]>;

export async function buildifierLint(
  fileContent: string,
  type: BuildifierFileType,
  lintMode: BuildifierLintMode,
): Promise<string | IBuildifierWarning[]> {
  const args = [
    `--format=json`,
    `--mode=check`,
    `--type=${type}`,
    `--lint=${lintMode}`,
  ];
  const outputs = await executeBuildifier(fileContent, args, true);
  switch (lintMode) {
    case "fix":
      return outputs.stdout;
    case "warn":
      const result = JSON.parse(outputs.stdout) as IBuildifierResult;
      for (const file of result.files) {
        if (file.filename === "<stdin>") {
          return file.warnings;
        }
      }
      return [];
  }
}