UNPKG

eclint

Version:

Validate or fix code that doesn't adhere to EditorConfig settings or infer settings from existing code.

99 lines 3.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var linez = require("linez"); var _ = require("lodash"); function updateDoc(doc, settings) { doc.lines = doc.lines.map(function (rawLine) { return new Line(rawLine, doc); }); if (!settings || !settings.block_comment_start || !settings.block_comment_end) { return doc; } var block_comment = settings.block_comment; if (!block_comment && settings.block_comment_start[settings.block_comment_start.length - 1] === settings.block_comment_end[0]) { block_comment = settings.block_comment_end[0]; } var padSize = 0; if (block_comment) { padSize = Math.max(0, settings.block_comment_start.indexOf(block_comment)); } var docCommentLines; doc.lines.forEach(function (line) { if (_.startsWith(line.string, settings.block_comment_start)) { docCommentLines = [line]; } else if (_.endsWith(line.string, settings.block_comment_end)) { if (docCommentLines) { var blockCommentStart_1 = docCommentLines[0]; blockCommentStart_1.isBlockCommentStart = true; var commentStartWidth = settings.block_comment_start.length; var currPadSize_1 = /^\s*/.exec(blockCommentStart_1.string.slice(commentStartWidth))[0].length || 1; currPadSize_1 += commentStartWidth; line.isBlockCommentEnd = true; docCommentLines.push(line); docCommentLines.forEach(function (docCommentLine) { if (block_comment && _.startsWith(docCommentLine.string, block_comment)) { docCommentLine.padSize = padSize; docCommentLine.isBlockComment = true; } else if (docCommentLine.isBlockCommentStart) { return; } else { docCommentLine.padSize = currPadSize_1; } docCommentLine.blockCommentStart = blockCommentStart_1; }); } docCommentLines = null; } else if (docCommentLines) { docCommentLines.push(line); } return line; }); return doc; } var Line = /** @class */ (function () { function Line(line, doc) { this.isBlockComment = false; this.isBlockCommentEnd = false; this.isBlockCommentStart = false; this.blockCommentStart = null; this.padSize = 0; _.assign(this, line); if (doc) { this.doc = doc; } } Object.defineProperty(Line.prototype, "text", { get: function () { return this.prefix + this.string + this.suffix; }, set: function (text) { var textArray = /^([\t ]*)(.*?)([\t ]*)$/.exec(text); if (textArray && textArray[2]) { this.prefix = textArray[1]; this.string = textArray[2]; this.suffix = textArray[3]; } else { this.prefix = ''; this.string = ''; this.suffix = text; } }, enumerable: true, configurable: true }); return Line; }()); exports.Line = Line; function create(file, settings) { var document = (linez(file)); updateDoc(document, settings); return document; } exports.create = create; //# sourceMappingURL=doc.js.map