Skip to content
Merged
Changes from all commits
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
74 changes: 37 additions & 37 deletions napi/oxlint2/src-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,43 @@ async function loadPluginImpl(path) {
return JSON.stringify({ Success: ret });
}

/**
* Context class.
*
* Each rule has its own `Context` object. It is passed to that rule's `create` function.
*/
class Context {
// Rule ID. Index into `registeredRules` array.
#ruleId;
// Absolute path of file being linted. Set before calling `rule`'s `create` method.
physicalFilename;

/**
* @constructor
* @param {number} ruleId - Rule ID
*/
constructor(ruleId) {
this.#ruleId = ruleId;
}

/**
* Report error.
* @param {Object} diagnostic - Diagnostic object
* @param {string} diagnostic.message - Error message
* @param {Object} diagnostic.loc - Node or loc object
* @param {number} diagnostic.loc.start - Start range of diagnostic
* @param {number} diagnostic.loc.end - End range of diagnostic
* @returns {undefined}
*/
report(diagnostic) {
diagnostics.push({
message: diagnostic.message,
loc: { start: diagnostic.node.start, end: diagnostic.node.end },
externalRuleId: this.#ruleId,
});
}
}

// --------------------
// Running rules
// --------------------
Expand Down Expand Up @@ -147,43 +184,6 @@ function lintFile([filePath, bufferId, buffer, ruleIds]) {
return ret;
}

/**
* Context class.
*
* Each rule has its own `Context` object. It is passed to that rule's `create` function.
*/
class Context {
// Rule ID. Index into `registeredRules` array.
#ruleId;
// Absolute path of file being linted. Set before calling `rule`'s `create` method.
physicalFilename;

/**
* @constructor
* @param {number} ruleId - Rule ID
*/
constructor(ruleId) {
this.#ruleId = ruleId;
}

/**
* Report error.
* @param {Object} diagnostic - Diagnostic object
* @param {string} diagnostic.message - Error message
* @param {Object} diagnostic.loc - Node or loc object
* @param {number} diagnostic.loc.start - Start range of diagnostic
* @param {number} diagnostic.loc.end - End range of diagnostic
* @returns {undefined}
*/
report(diagnostic) {
diagnostics.push({
message: diagnostic.message,
loc: { start: diagnostic.node.start, end: diagnostic.node.end },
externalRuleId: this.#ruleId,
});
}
}

// --------------------
// Run linter
// --------------------
Expand Down
Loading