Skip to content

Commit

Permalink
Metadata line length check ignores API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Feb 28, 2024
1 parent eb1912f commit db5effd
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions scripts/commands/checkMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ const readMetadata = async (filePath: string): Promise<Record<string, any>> => {
}
};

const isValidMetadata = (metadata: Record<string, any>): boolean =>
const isValidMetadata = (
metadata: Record<string, any>,
filePath: string,
): boolean =>
metadata.title &&
metadata.description &&
metadata.title != metadata.description &&
metadata.description.length <= 160 &&
metadata.description.length >= 50;
(isApi(filePath) ||
(metadata.title != metadata.description &&
metadata.description.length <= 160 &&
metadata.description.length >= 50));

const main = async (): Promise<void> => {
const args = readArgs();
Expand All @@ -67,15 +71,15 @@ const main = async (): Promise<void> => {
const mdErrors = [];
for (const file of mdFiles) {
const metadata = await readMetadata(file);
if (!isValidMetadata(metadata)) {
if (!isValidMetadata(metadata, file)) {
mdErrors.push(file);
}
}

const notebookErrors = [];
for (const file of notebookFiles) {
const metadata = await readMetadata(file);
if (!isValidMetadata(metadata)) {
if (!isValidMetadata(metadata, file)) {
notebookErrors.push(file);
}
}
Expand All @@ -99,6 +103,14 @@ async function determineFiles(args: Arguments): Promise<[string[], string[]]> {
return [await globby(mdGlobs), await globby(notebookGlobs)];
}

function isApi(filePath: string): boolean {
return (
filePath.includes("/api/qiskit/") ||
filePath.includes("/api/qiskit-ibm-runtime/") ||
filePath.includes("/api/qiskit-ibm-provider/")
);
}

function handleErrors(mdErrors: string[], notebookErrors: string[]): void {
if (mdErrors.length > 0) {
console.error(`
Expand Down

0 comments on commit db5effd

Please sign in to comment.