Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add atomic values in API messages #92

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import Logger from "./logger.js";
/**
* @typedef {Object} Result
* @property {String} message The message as a single string, suitable for human consumption
* @property {String} reason The message as a single string
* @property {"error"|"warn"|"exception"} type The type of result
* @property {String} [stacktrace] If Result is related to a node, a human-suitable string showing the related part of the file
* @property {number} [line] If Result is related to a node, the related line in the file
* @property {number} [column] If Result is related to a node, the related column in the file
* @property {any[]} _message The original message, as given by the rule
* @property {Node} [_node] If Result is related to a node, the related node
* @property {AST} [_ast] If Result is related to a node, the related AST
Expand All @@ -31,17 +34,22 @@ function generateResult(message, type, node, ast) {
const _message = message instanceof Array ? message : [message];
const outp = {
message: message,
reason: message,
_message,
_node: node,
_ast: ast,
type,
};
if (message instanceof Error) {
outp.message = message.stack || message.toString();
outp.reason = message.toString();
}
if (node) {
// @ts-ignore
outp.message += `\n At node ${chalk.bold("<"+node.name+">")} (${node.lineNum}:${node.columnNum})`;
outp.reason += " at node <"+node.name+">";
outp.line = node.lineNum;
outp.column = node.columnNum;
}
// @ts-ignore
return outp;
Expand Down