Vous êtes sur la page 1sur 3

age description

* @typedef {Object} MessageDescriptor

* @property {ASTNode} [node] The reported node

* @property {Location} loc The location of the problem.

* @property {string} message The problem message.

* @property {Object} [data] Optional data to use to fill in placeholders in the

* message.

* @property {Function} [fix] The function to call that creates a fix command.

*/

/**

* Information about the report

* @typedef {Object} ReportInfo

* @property {string} ruleId

* @property {(0|1|2)} severity

* @property {(string|undefined)} message

* @property {(string|undefined)} messageId

* @property {number} line

* @property {number} column

* @property {(number|undefined)} endLine

* @property {(number|undefined)} endColumn

* @property {(string|null)} nodeType

* @property {string} source

* @property {({text: string, range: (number[]|null)}|null)} fix

*/

//------------------------------------------------------------------------------

// Module Definition

//------------------------------------------------------------------------------
/**

* Translates a multi-argument context.report() call into a single object argument call

* @param {...*} arguments A list of arguments passed to `context.report`

* @returns {MessageDescriptor} A normalized object containing report information

*/

function normalizeMultiArgReportCall() {

// If there is one argument, it is considered to be a new-style call already.

if (arguments.length === 1) {

// Shallow clone the object to avoid surprises if reusing the descriptor

return Object.assign({}, arguments[0]);

// If the second argument is a string, the arguments are interpreted as [node,


message, data, fix].

if (typeof arguments[1] === "string") {

return {

node: arguments[0],

message: arguments[1],

data: arguments[2],

fix: arguments[3]

};

// Otherwise, the arguments are interpreted as [node, loc, message, data, fix].

return {
node: arguments[0],

loc: arguments[1],

message: arguments[2],

data: arguments[3],

fix: arguments[4]

};

/**

* Asserts that either a loc or a node was provided, and the node is valid if it was
provided.

* @param {MessageDescriptor} descriptor A descriptor to validate

* @returns {void}

* @throws AssertionError if neither a node nor a loc was provided, or if the node is not
an object

*/

function assertValidNodeInfo(descriptor) {

if (descriptor.node) {

assert(typeof descriptor.node === "ob

Vous aimerez peut-être aussi