@storm-software/linting-tools
Version:
⚡ A package containing various linting tools used to validate syntax, enforce design standards, and format code in a Storm workspace.
75 lines (68 loc) • 3.23 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunk6B2W5NCRcjs = require('./chunk-6B2W5NCR.cjs');
// ../../node_modules/.pnpm/confbox@0.1.8/node_modules/confbox/dist/shared/confbox.9388d834.mjs
_chunk6B2W5NCRcjs.init_cjs_shims.call(void 0, );
var b = /^(?:( )+|\t+)/;
var d = "space";
var h = "tab";
function g(e, t) {
const n = /* @__PURE__ */ new Map();
let i = 0, s, o;
for (const c of e.split(/\n/g)) {
if (!c) continue;
let f, a, l, p, r;
const y = c.match(b);
if (y === null) i = 0, s = "";
else {
if (f = y[0].length, a = y[1] ? d : h, t && a === d && f === 1) continue;
a !== s && (i = 0), s = a, l = 1, p = 0;
const u = f - i;
if (i = f, u === 0) l = 0, p = 1;
else {
const I = u > 0 ? u : -u;
o = T(a, I);
}
r = n.get(o), r = r === void 0 ? [1, 0] : [r[0] + l, r[1] + p], n.set(o, r);
}
}
return n;
}
function T(e, t) {
return (e === d ? "s" : "t") + String(t);
}
function w(e) {
const n = e[0] === "s" ? d : h, i = Number(e.slice(1));
return { type: n, amount: i };
}
function E(e) {
let t, n = 0, i = 0;
for (const [s, [o, c]] of e) (o > n || o === n && c > i) && (n = o, i = c, t = s);
return t;
}
function S(e, t) {
return (e === d ? " " : " ").repeat(t);
}
function _(e) {
if (typeof e != "string") throw new TypeError("Expected a string");
let t = g(e, true);
t.size === 0 && (t = g(e, false));
const n = E(t);
let i, s = 0, o = "";
return n !== void 0 && ({ type: i, amount: s } = w(n), o = S(i, s)), { amount: s, type: i, indent: o };
}
var m = Symbol.for("__confbox_fmt__");
var k = /^(\s+)/;
var v = /(\s+)$/;
function x(e, t = {}) {
const n = t.indent === void 0 && t.preserveIndentation !== false && e.slice(0, _optionalChain([t, 'optionalAccess', _2 => _2.sampleSize]) || 1024), i = t.preserveWhitespace === false ? void 0 : { start: _optionalChain([k, 'access', _3 => _3.exec, 'call', _4 => _4(e), 'optionalAccess', _5 => _5[0]]) || "", end: _optionalChain([v, 'access', _6 => _6.exec, 'call', _7 => _7(e), 'optionalAccess', _8 => _8[0]]) || "" };
return { sample: n, whiteSpace: i };
}
function N(e, t, n) {
!t || typeof t != "object" || Object.defineProperty(t, m, { enumerable: false, configurable: true, writable: true, value: x(e, n) });
}
function C(e, t) {
if (!e || typeof e != "object" || !(m in e)) return { indent: _optionalChain([t, 'optionalAccess', _9 => _9.indent]), whitespace: { start: "", end: "" } };
const n = e[m];
return { indent: _optionalChain([t, 'optionalAccess', _10 => _10.indent]) || _(n.sample || "").indent, whitespace: n.whiteSpace || { start: "", end: "" } };
}
exports.N = N; exports.C = C;