textlint-rule-helper
Version:
A helper library for textlint rule.
50 lines • 1.89 kB
JavaScript
// LICENSE : MIT
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SourceLocation = void 0;
var structured_source_1 = require("structured-source");
var SourceLocation = /** @class */ (function () {
function SourceLocation(text) {
this.source = new structured_source_1.StructuredSource(text);
}
SourceLocation.prototype.toAbsoluteLocation = function (node, padding) {
var nodeRange = node.range;
var line = node.loc.start.line;
var column = node.loc.start.column;
// when use {index}
if (padding.index !== undefined) {
var paddingIndex = padding.index;
return nodeRange[0] + paddingIndex;
}
// when use {line, column}
if (padding.line !== undefined && padding.column !== undefined) {
var addedLine = line + padding.line;
// when report with padding {line, column}, message.column should be 0 + padding.column.
// In other word, padding line > 0 and message.column start with 0.
if (padding.column > 0) {
return this.source.positionToIndex({
line: addedLine,
column: padding.column
});
}
else {
return this.source.positionToIndex({
line: addedLine,
column: column
});
}
}
// when use { line } only
if (padding.line !== undefined && padding.line > 0) {
var addedLine = line + padding.line;
return this.source.positionToIndex({
line: addedLine,
column: column
});
}
return nodeRange[0];
};
return SourceLocation;
}());
exports.SourceLocation = SourceLocation;
//# sourceMappingURL=SourceLocation.js.map