Skip to content

Commit

Permalink
feat: better error output for eslint / remark
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianCataldo committed Oct 30, 2022
1 parent 7a961a7 commit aff95db
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ function pushErrors(
`${error.message.charAt(0).toUpperCase()}` +
`${error.message.substring(1)}`;
/* Sub-path -OR- Root error? */
if (error.instancePath) {
reason = `${error.instancePath}: ${errMessage}`;
} else {
reason = errMessage;
}
const expected = Array.isArray(error.params.allowedValues)
? `: \`${error.params.allowedValues.join('`, `')}\``
: '';
const sPath = schemaRelPath ? ` • ${schemaRelPath}` : '';
reason = `${errMessage}${expected}${sPath}${error.schemaPath}`;
}

/* Explode AJV error instance path and get corresponding YAML AST node */
Expand Down Expand Up @@ -146,7 +146,7 @@ function pushErrors(
note += `\nSchema path: ${schemaRelPath} · ${error.schemaPath}`;
message.note = note;
/* `message` comes from native JS `Error` object */
message.message = note;
message.message = reason;

/**
* Adding custom data from AJV
Expand Down Expand Up @@ -196,10 +196,10 @@ async function validateFrontmatter(

/* Global schemas associations, only if no local schema is set */
if (yamlDoc && yamlJS && !hasLocalAssoc) {
Object.entries(settings.schemas || {}).forEach(
Object.entries(settings.schemas ?? {}).forEach(
([globSchemaPath, globSchemaAssocs]) => {
/* Check if current markdown file is associated with this schema */
globSchemaAssocs?.forEach((mdFilePath) => {
globSchemaAssocs.forEach((mdFilePath) => {
if (typeof mdFilePath === 'string') {
/* Remove appended `./` or `/` */
const mdPathCleaned = path.join(mdFilePath);
Expand Down

0 comments on commit aff95db

Please sign in to comment.