UNPKG

bc-minecraft-project

Version:
133 lines 4.56 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.MCLint = void 0; const fs = __importStar(require("fs")); /** Namespace providing utilities for working with MCLint configuration */ var MCLint; (function (MCLint) { /** The default filename for MCLint configuration */ MCLint.filename = '.mclint'; /** Creates an empty MCLint configuration */ function createEmpty() { return { rules: {} }; } MCLint.createEmpty = createEmpty; /** Checks whether the given value implements the MCLint interface */ function is(value) { return (value !== null && typeof value === 'object' && 'rules' in value && value.rules !== null && typeof value.rules === 'object'); } MCLint.is = is; /** * Parses a JSON string as MCLint configuration. * Returns an empty configuration if the input is invalid. */ function parse(content) { try { const parsed = JSON.parse(content); if (is(parsed)) return parsed; } catch { // Invalid JSON — fall through to empty config } return createEmpty(); } MCLint.parse = parse; /** Loads the MCLint configuration from a file synchronously */ function loadSync(filepath) { if (fs.existsSync(filepath)) { try { return parse(fs.readFileSync(filepath).toString()); } catch { // Ignore file-read errors } } return createEmpty(); } MCLint.loadSync = loadSync; /** Loads the MCLint configuration from a file asynchronously */ async function load(filepath) { return fs.promises .readFile(filepath) .then((buf) => parse(buf.toString())) .catch(() => createEmpty()); } MCLint.load = load; /** * Resolves the effective severity string of a rule. * Returns `'off'` when the rule is undefined or explicitly disabled. */ function getSeverity(rule) { if (rule === undefined) return 'off'; const raw = Array.isArray(rule) ? rule[0] : rule; switch (raw) { case 0: case 'off': return 'off'; case 1: case 'warn': return 'warn'; case 2: case 'error': return 'error'; default: return 'off'; } } MCLint.getSeverity = getSeverity; /** * Gets the options array for a rule (all elements after the severity). * Returns an empty array when the rule has no options or is a plain severity value. */ function getOptions(rule) { if (!Array.isArray(rule) || rule.length <= 1) return []; return rule.slice(1); } MCLint.getOptions = getOptions; /** Returns `true` when the rule is enabled (not `'off'`) */ function isEnabled(rule) { return getSeverity(rule) !== 'off'; } MCLint.isEnabled = isEnabled; })(MCLint || (exports.MCLint = MCLint = {})); //# sourceMappingURL=mclint.js.map