Skip to content

Commit

Permalink
add linter as a command to tool cli
Browse files Browse the repository at this point in the history
  • Loading branch information
OnkarRuikar committed Feb 23, 2023
1 parent 18a8f5d commit d058166
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 44 deletions.
42 changes: 0 additions & 42 deletions fmlint/cli.ts

This file was deleted.

2 changes: 1 addition & 1 deletion fmlint/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function compileValidators(config: FMConfig) {
}

// lint front matter
export async function runLinter(
export async function lintFrontMatter(
filesAndDirectories: string[],
options: LinterOptions
) {
Expand Down
2 changes: 1 addition & 1 deletion fmlint/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionParameters } from "@caporal/core";

export interface CliArgsAndOptions extends ActionParameters {
export interface FMLintArgsAndOptions extends ActionParameters {
args: {
files?: string[];
};
Expand Down
32 changes: 32 additions & 0 deletions tool/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {
MacroInvocationError,
MacroRedirectedLinkError,
} from "../kumascript/src/errors.js";
import { FMLintArgsAndOptions } from "../fmlint/types.js";
import { lintFrontMatter } from "../fmlint/linter.js";

const { program } = caporal;
const { prompt } = inquirer;
Expand Down Expand Up @@ -1191,6 +1193,36 @@ if (Mozilla && !Mozilla.dntEnabled()) {
const { deprecatedOnly, format, unusedOnly } = options;
return macroUsageReport({ deprecatedOnly, format, unusedOnly });
})
)

.command("fmlint", "Validate and prettify front matter.")
.option("--cwd <path>", "Explicit current-working-directory", {
validator: program.STRING,
default: process.cwd(),
})
.option("--config <path>", "Front matter config file location", {
validator: program.STRING,
default: fileURLToPath(
new URL("../fmlint/front-matter-config.json", import.meta.url)
),
})
.option("--fix", "Save formatted/corrected output", {
validator: program.BOOLEAN,
default: false,
})
.argument("[files...]", "list of files and/or directories to check", {
default: [CONTENT_ROOT, CONTENT_TRANSLATED_ROOT].filter(Boolean),
})
.action(
tryOrExit(({ args, options, logger }: FMLintArgsAndOptions) => {
const cwd = options.cwd || process.cwd();
const files = (args.files || []).map((f) => path.resolve(cwd, f));
if (!files.length) {
logger.info("No files to lint.");
return;
}
return lintFrontMatter(files, options);
})
);

program.run();

0 comments on commit d058166

Please sign in to comment.