{
  "schema": 1,
  "id": "addon.formatter",
  "name": "Formatter",
  "version": "1.0.0",
  "category": "tool",
  "description": "Formats and checks code in the Pureline style (Java, JavaScript, TypeScript, Go, Crystal) and uses Prettier when a project is configured for it. Ships with program code.",
  "author": "ezTxmMC",
  "icon": "Fm",
  "color": "#6c8cff",
  "license": "AGPL-3.0-or-later",
  "minAppVersion": "0.6.4",
  "keywords": [
    "formatter",
    "format",
    "pureline",
    "prettier",
    "linter",
    "checker",
    "style"
  ],
  "readme": "# Formatter\n\nFormats and checks code in the **Pureline** style, and hands files to\n**Prettier** when a project is set up for it.\n\n- **Pureline** (the default): Java, JavaScript, TypeScript (also JSX/TSX), Go and\n  Crystal, plus whitespace-only support for Kotlin. The rules of the\n  Pureline Specification 1.1 (`PURELINE_SPECIFICATION_1.1.md` in the Lumen repository) — guard\n  clauses instead of `else`, explicit blocks, semicolons, compact calls — are\n  applied as safe rewrites and reported as diagnostics.\n- **Prettier**: used when a Prettier config exists for the file (or the engine is\n  forced); it runs from the project, from `prettierPath` or from the PATH.\n\nThe extension ships program code, which must be confirmed on install. It runs in\nLumen's main process, needs no npm packages and only starts `gofmt`, `crystal`\nand `prettier` — without a shell (Windows aside), with the text on stdin.\n\nNeeds Lumen 0.7.0 (formatter and checker providers).\n\n## Which engine formats a file\n\nFor every request the extension walks up from the file's folder to the\nworkspace root (to the filesystem root for a file outside the workspace) and\nlooks for configuration files. The **nearest folder that has any of them wins**;\ninside one folder a `.pureline` beats the Prettier configs.\n\n| Found | Engine |\n| --- | --- |\n| `.pureline` | Pureline, with that file (and its parents, see `root`) |\n| a Prettier config | Prettier (Pureline with the readable Prettier options if Prettier is not installed — a note says so once per workspace) |\n| nothing | Pureline defaults |\n\nThe `engine` setting (`auto`, `pureline`, `prettier`) forces one. Prettier only\ngets file types it supports (js jsx ts tsx mjs cjs mts cts json jsonc json5 css\nscss less html vue markdown md mdx yaml yml graphql hbs); other languages always\ngo to Pureline. A Prettier-only file type (CSS, JSON …) with no Prettier config is\nnot handled here at all, so other formatters can take it.\n\nThe status bar shows the engine for the active file (`Pureline`,\n`Pureline · .pureline`, `Prettier`); a click opens **Formatter: Show active\nconfiguration**.\n\nThe Pureline checker runs only for files that Pureline formats. A project that\nruns on Prettier has chosen its own style and is not checked.\n\n## Pureline defaults\n\nWithout a `.pureline` file: indentation from the editor options in the request\n(`tabWidth`, `useTabs`) when the setting *Default indentation* is `editor`, a\nfixed 2 or 4 spaces otherwise (default **4**, as in the spec's examples). Go\nalways uses tabs, Crystal two spaces. Print width 120, semicolons, final newline,\ntrimmed trailing whitespace; line endings follow the editor.\n\n## The `.pureline` file\n\nJSON, with `//` and `/* */` comments and trailing commas. Create one with\n**Formatter: Create .pureline file**.\n\n```json\n{\n  \"pureline\": \"1.1\",\n  \"root\": true,\n  \"indent\": { \"style\": \"space\", \"size\": 4 },\n  \"endOfLine\": \"lf\",\n  \"printWidth\": 120,\n  \"semicolons\": true,\n  \"finalNewline\": true,\n  \"trimTrailingWhitespace\": true,\n  \"rules\": { \"PL-CF-002\": \"error\", \"PL-FMT-001\": \"off\", \"PL-JS-002\": \"warn\" },\n  \"languages\": { \"typescript\": { \"indent\": { \"size\": 2 } }, \"go\": { \"indent\": { \"style\": \"tab\" } } },\n  \"ignore\": [\"dist/**\", \"*.min.js\"]\n}\n```\n\n| Key | Meaning |\n| --- | --- |\n| `pureline` | The spec version the file was written for (`\"1.1\"`). |\n| `root` | `true` stops the search for parent `.pureline` files. Without it, values of parent files are inherited and the nearer file overrides them; `indent`, `rules` and `languages` merge key by key. |\n| `indent` | `{ \"style\": \"space\" \\| \"tab\", \"size\": 1–16 }` (`2` or `\"tab\"` work as shorthand). |\n| `endOfLine` | `lf`, `crlf` or `keep` (the dominant ending of the file). |\n| `printWidth` | 20–1000; limits how far PL-FMT-001 collapses calls. |\n| `semicolons` | `false` switches PL-JS-002 off (JavaScript/TypeScript). Existing semicolons are never removed. |\n| `finalNewline` | End the file with exactly one line break. |\n| `trimTrailingWhitespace` | Strip blanks at the end of lines (never inside template literals, text blocks or raw strings). |\n| `rules` | Rule id to `off`, `info`, `warn` or `error` (`true` = the rule's default level, `false` = `off`; `hint` is accepted too). |\n| `languages` | Per-language overrides (`java`, `javascript`, `typescript`, `go`, `crystal`, `kotlin`; `js`/`ts` work as aliases) of every key except `pureline`, `root`, `languages` and `ignore`. |\n| `ignore` | Globs relative to the folder of the file that lists them (`*`, `**`, `?`, `[a-z]`, `{a,b}`); a pattern without a slash matches the file name at any depth. Ignored files are neither formatted nor checked. |\n\nA rule that is `off` is neither fixed by the formatter nor reported by the\nchecker. Every other rule that has a safe automatic fix is applied when you\nformat; the level only decides how the checker reports it. For the brace fix\nboth `PL-CF-003` and `PL-JS-001` must be on in JavaScript/TypeScript.\n\nBad input never breaks formatting: unknown keys, wrong value types, unknown rule\nids and unknown languages become *notes* on the format result and the default\nstays in force.\n\n## Prettier detection\n\nDetected configs, per folder: `.prettierrc` (JSON or YAML), `.prettierrc.json`,\n`.yaml`, `.yml`, `.json5`, `.toml`, `.js`, `.cjs`, `.mjs`, `.ts`, `.cts`, `.mts`,\n`prettier.config.js|cjs|mjs|ts|cts|mts` and a `\"prettier\"` key in `package.json`.\n\nJSON, JSON5, flat YAML and flat TOML configs are *read* (`tabWidth`, `useTabs`,\n`semi`, `printWidth`, `endOfLine` feed the Pureline fallback; JSON/JSON5\n`overrides` with `files`/`excludeFiles` globs are honoured). JavaScript and\nTypeScript configs are never executed — Prettier resolves them itself.\n`.prettierignore` (nearest one above the file, `.gitignore` rules) and\n`node_modules` mean: not formatted.\n\nPrettier is found in this order: the `prettierPath` setting,\n`node_modules/.bin/prettier` from the file's folder upwards, `prettier` on the\nPATH. It runs as `prettier --stdin-filepath <file>` in the file's folder\n(`--range-start/--range-end` for a selection). A non-zero exit, output on stderr\nor a timeout leaves the document alone and shows a message.\n\n## What Pureline formats\n\nEvery fix works on tokens (strings, comments, templates, text blocks and raw\nstrings are never touched), keeps the meaning of the program, is idempotent and\ndoes nothing when it is not sure.\n\n- **Blocks** (PL-CF-003 Java, PL-JS-001 JS/TS): `if`/`else if`/`else`/`for`/\n  `while`/`do-while` bodies get braces; the dangling `else` stays with the inner\n  `if`. JavaScript statements without a semicolon are only wrapped when their end\n  is certain.\n- **`else`** (PL-CF-002, PL-GO-002): removed when the branch before it ends in\n  `return`, `throw`, `continue` or `break`; `else if` chains become separate\n  `if`s. Skipped when the moved body declares a name that exists elsewhere in the\n  file or is used around it, for Go `if` with an init statement, and when\n  comments sit in between.\n- **Semicolons** (PL-JS-002): added at clear statement ends only (balanced\n  brackets, the next line cannot continue the statement); never after `}` of\n  functions, classes or blocks; class, interface and enum bodies are left alone.\n- **Compact calls** (PL-FMT-001): arguments spread one per line collapse onto one\n  line when they fit `printWidth`; builder chains, comments, declarations and\n  multi-line arguments stay as they are.\n- **Whitespace**: trailing blanks, one final newline, line endings, runs of blank\n  lines, indentation by bracket depth (continuation lines, ternaries and chains\n  one level deeper, `case` bodies one level inside `switch`, block comments move\n  as a block).\n- **Go**: `gofmt` runs first (and again after a rewrite) when installed.\n  **Crystal**: `crystal tool format` runs first when installed; Pureline only\n  tidies whitespace and reports `else`. **Kotlin**: whitespace and indentation.\n- **Selections** (*Format Selection*): the whole document is formatted in\n  memory; only changes that touch the selected lines are applied and a\n  structural rewrite (for example removing an `else`) is applied whole or not at\n  all.\n\nFiles with JSX, or with brackets that do not balance, only get the whitespace\nfixes (and a note).\n\n## Rules\n\n`Fix` = the formatter rewrites code; the others are reported by the checker (the\nrule ids and titles come from the specification). Levels are the defaults.\n\n| Rule | What | Languages | Level | Fix |\n| --- | --- | --- | --- | --- |\n| PL-CF-001 | Prefer guard clauses (control flow nested deeper than 3 levels) | all but Crystal | warning | — |\n| PL-CF-002 | Avoid else (after a terminating branch: warning, otherwise info) | java, javascript, typescript, go | warning | yes |\n| PL-CF-003 | Explicit blocks in brace-based languages | java, javascript, typescript | warning | yes |\n| PL-NAME-001 | Names must be meaningful (`i j k` and catch `e` are fine, Go keeps `ctx err wg tx conn …`) | all but Crystal | warning | — |\n| PL-FN-001 | One clear responsibility per function (over 30 lines: review, over 50: split; vague names) | all | warning | — |\n| PL-STRUCT-001 | One clear responsibility per class or module (over 200 lines) | all | info | — |\n| PL-FMT-001 | Prefer compact horizontal calls | all brace languages | info | yes |\n| PL-DOC-001 | Comments explain why, not what | all | hint | — |\n| PL-JAVA-002 | Interfaces use the `I` prefix (Java only) | java | hint | — |\n| PL-JAVA-003 | Prefer records for immutable data | java | hint | — |\n| PL-JAVA-004 | Explicit null handling (`Objects.requireNonNull`) | java | info | — |\n| PL-JAVA-005 | Use imports instead of fully qualified class names | java | warning | — |\n| PL-JS-001 | Braces are mandatory | javascript, typescript | warning | yes |\n| PL-JS-002 | Use semicolons | javascript, typescript | warning | yes |\n| PL-JS-003 | `const` first, never `var` (`var`: error, never-reassigned `let`: warning) | javascript, typescript | warning | — |\n| PL-JS-004 | Prefer async / await | javascript, typescript | hint | — |\n| PL-TS-001 | Avoid `any` | typescript | warning | — |\n| PL-TS-003 | No Java-style `I` prefix | typescript | warning | — |\n| PL-TS-005 | Prefer union types over enums when appropriate | typescript | hint | — |\n| PL-GO-002 | Avoid else after terminating branches | go | warning | yes |\n| PL-CR-002 | Avoid else | crystal | info | — |\n\nThe other rules of the specification (PL-CORE-001 to 020, PL-JAVA-001, 006 to\n010, PL-JS-005/006, PL-TS-002/004/006, PL-GO-001, 003 to 009, PL-CR-001, 003 to 007,\nPL-ARCH-001) are principles for reviews: they are valid in a `.pureline` but\nnothing is reported for them. **Formatter: Show Pureline rule catalog** lists all\nof them. A level in `rules` replaces the default for every finding of that rule.\n\n## Settings\n\n| Setting | Meaning |\n| --- | --- |\n| Formatter engine (`engine`) | `auto`, `pureline` or `prettier`. |\n| Path to Prettier (`prettierPath`) | Empty: project `node_modules/.bin/prettier`, then the PATH. |\n| Default indentation (`defaultIndent`) | `editor`, `2` or `4` (default `4`); only without a `.pureline`. |\n| Pureline checker while typing (`checkOnType`) | Show rule violations as diagnostics. |\n| Show the engine in the status bar (`showStatus`) | |\n\n## Commands\n\n- **Formatter: Show active configuration** — opens a document with the engine, the\n  config files in use, the resolved options and the active rules.\n- **Formatter: Create .pureline file** — writes the documented default file into\n  the project root (never overwrites) and opens it.\n- **Formatter: Show Pureline rule catalog** — the rules with their ids, levels\n  and whether the formatter fixes them.\n\n## Known limitations\n\n- The tokenizer is not a parser. Regex-versus-division and JSX are decided by\n  heuristics; a JSX file gets whitespace fixes only.\n- Semicolon and brace fixes in JavaScript follow the automatic-semicolon rules\n  conservatively: a statement that could continue on the next line is left alone.\n- Without `gofmt`, continuation lines in Go may differ from gofmt's style.\n- Kotlin has no structural fixes; Crystal's structure belongs to\n  `crystal tool format`.\n- PL-NAME-001 and PL-FN-001 are heuristics; callback parameters such as `(a, b) =>`\n  are reported as `info`.\n\nLicense: AGPL-3.0-or-later.\n",
  "settings": [
    {
      "key": "engine",
      "label": "Formatter-Engine",
      "type": "select",
      "default": "auto",
      "section": "Engine",
      "hint": "Automatisch: eine .pureline-Datei gewinnt, danach eine Prettier-Konfiguration, ohne beides gilt der Pureline-Standard. Pureline und Prettier erzwingen eine Engine.",
      "choices": [
        {
          "value": "auto",
          "label": "Automatisch"
        },
        {
          "value": "pureline",
          "label": "Immer Pureline"
        },
        {
          "value": "prettier",
          "label": "Immer Prettier"
        }
      ],
      "i18n": {
        "en": {
          "label": "Formatter engine",
          "section": "Engine",
          "hint": "Automatic: a .pureline file wins, then a Prettier config; with neither the Pureline defaults apply. Pureline and Prettier force one engine.",
          "choices": {
            "auto": "Automatic",
            "pureline": "Always Pureline",
            "prettier": "Always Prettier"
          }
        }
      }
    },
    {
      "key": "prettierPath",
      "label": "Pfad zu Prettier",
      "type": "path",
      "pathKind": "file",
      "default": "",
      "placeholder": "node_modules/.bin/prettier oder prettier im PATH",
      "section": "Engine",
      "hint": "Leer lassen: zuerst node_modules/.bin/prettier des Projekts, dann prettier aus dem PATH.",
      "i18n": {
        "en": {
          "label": "Path to Prettier",
          "placeholder": "node_modules/.bin/prettier or prettier on the PATH",
          "section": "Engine",
          "hint": "Leave empty: the project's node_modules/.bin/prettier first, then prettier from the PATH."
        }
      }
    },
    {
      "key": "defaultIndent",
      "label": "Standard-Einrückung",
      "type": "select",
      "default": "4",
      "section": "Pureline",
      "hint": "Gilt nur ohne .pureline-Datei. Go nutzt immer Tabs, Crystal immer zwei Leerzeichen.",
      "choices": [
        {
          "value": "editor",
          "label": "Wie im Editor"
        },
        {
          "value": "2",
          "label": "2 Leerzeichen"
        },
        {
          "value": "4",
          "label": "4 Leerzeichen"
        }
      ],
      "i18n": {
        "en": {
          "label": "Default indentation",
          "section": "Pureline",
          "hint": "Only applies without a .pureline file. Go always uses tabs, Crystal always two spaces.",
          "choices": {
            "2": "2 spaces",
            "4": "4 spaces",
            "editor": "Like the editor"
          }
        }
      }
    },
    {
      "key": "checkOnType",
      "label": "Pureline-Prüfung während des Tippens",
      "type": "toggle",
      "default": "true",
      "section": "Pureline",
      "hint": "Zeigt Verstöße gegen die Pureline-Regeln als Hinweise im Editor. Projekte, die Prettier nutzen, werden nicht geprüft.",
      "i18n": {
        "en": {
          "label": "Pureline checker while typing",
          "section": "Pureline",
          "hint": "Shows violations of the Pureline rules as diagnostics in the editor. Projects that use Prettier are not checked."
        }
      }
    },
    {
      "key": "showStatus",
      "label": "Engine in der Statusleiste anzeigen",
      "type": "toggle",
      "default": "true",
      "section": "Anzeige",
      "hint": "Zeigt, welche Engine die aktive Datei formatiert, zum Beispiel Pureline oder Prettier.",
      "i18n": {
        "en": {
          "label": "Show the engine in the status bar",
          "section": "Display",
          "hint": "Shows which engine formats the active file, for example Pureline or Prettier."
        }
      }
    }
  ],
  "pages": [],
  "agents": [],
  "views": [],
  "commands": [
    {
      "id": "format.explain",
      "title": "Formatter: Aktive Konfiguration anzeigen",
      "category": "Formatter",
      "icon": "info",
      "i18n": {
        "en": {
          "title": "Formatter: Show active configuration",
          "category": "Formatter"
        }
      }
    },
    {
      "id": "pureline.init",
      "title": "Formatter: .pureline-Datei erstellen",
      "category": "Formatter",
      "icon": "file-plus",
      "i18n": {
        "en": {
          "title": "Formatter: Create .pureline file",
          "category": "Formatter"
        }
      }
    },
    {
      "id": "pureline.rules",
      "title": "Formatter: Pureline-Regelkatalog anzeigen",
      "category": "Formatter",
      "icon": "list",
      "i18n": {
        "en": {
          "title": "Formatter: Show Pureline rule catalog",
          "category": "Formatter"
        }
      }
    }
  ],
  "code": {
    "main": "import { createRequire as __lumenRequire } from 'node:module'; const require = __lumenRequire(import.meta.url);\nimport Cn from\"node:fs/promises\";import Nn from\"node:path\";import ht from\"node:fs/promises\";import $ from\"node:path\";var In=/[.+^$()|\\\\]/;function xn(e){let t=\"\",n=0;for(let r=0;r<e.length;r++){let i=e[r];if(i===\"*\"&&e[r+1]===\"*\"){let s=e[r+2]===\"/\";r+=s?2:1,t+=s?\"(?:.*/)?\":\".*\";continue}if(i===\"*\"){t+=\"[^/]*\";continue}if(i===\"?\"){t+=\"[^/]\";continue}if(i===\"[\"){let s=e.indexOf(\"]\",r+2);if(s!==-1){let o=e.slice(r+1,s).replace(/^!/,\"^\").replace(/\\\\/g,\"\\\\\\\\\");t+=`[${o}]`,r=s;continue}}if(i===\"{\"){n++,t+=\"(?:\";continue}if(i===\"}\"&&n>0){n--,t+=\")\";continue}if(i===\",\"&&n>0){t+=\"|\";continue}t+=In.test(i)?`\\\\${i}`:i}return t+\")\".repeat(n)}var _e=new Map;function ie(e){let t=_e.get(e);if(t)return t;let n;try{n=new RegExp(`^${xn(e)}$`)}catch{n=/$^/}return _e.set(e,n),n}function se(e,t){let n=String(e).trim(),r=String(t).replace(/\\\\/g,\"/\").replace(/^\\.\\//,\"\");if(!n)return!1;let i=!1;n.startsWith(\"./\")&&(n=n.slice(2),i=!0),n.startsWith(\"/\")&&(n=n.slice(1),i=!0),n.endsWith(\"/\")&&(n+=\"**\");let s=ie(n),o=n.includes(\"/\");return s.test(r)?!0:!o&&!i?s.test(r.split(\"/\").pop()):(r=r.replace(/^\\/+/,\"\"),ie(`${n}/**`).test(r))}function Be(e,t){return e.some(n=>se(n,t))}var B=[\"java\",\"javascript\",\"typescript\",\"go\",\"crystal\"],z=[\"javascript\",\"typescript\"];function b(e,t,n,r={}){return{id:e,title:t,languages:n,fixable:!1,checked:!1,severity:\"info\",...r}}var jn=[\"Control flow should be as linear as possible\",\"Avoid else\",\"Prefer guard clauses\",\"Use the clearest control-flow form for the language\",\"Idiomatic language-native shorthand is allowed\",\"Functions should be small and focused\",\"Names must carry meaning\",\"Avoid unnecessary abstractions\",\"Avoid God Classes and God Modules\",\"Prefer immutable state\",\"Prefer modern language features where they improve clarity\",\"Avoid unnecessary vertical formatting\",\"Comments must not compensate for unclear code\",\"Handle invalid and error states early\",\"Keep important side effects visible\",\"Resources must have a clear lifecycle\",\"Prefer framework-native APIs\",\"Avoid magic values\",\"Make dependencies explicit\",\"Optimize hot paths deliberately, not accidentally\"],Rn=jn.map((e,t)=>b(`PL-CORE-${String(t+1).padStart(3,\"0\")}`,e,B)),oe=Object.freeze([...Rn,b(\"PL-CF-001\",\"Prefer guard clauses (control flow nested deeper than 3 levels)\",B,{checked:!0,severity:\"warn\"}),b(\"PL-CF-002\",\"Avoid else\",[\"java\",\"javascript\",\"typescript\",\"go\"],{checked:!0,fixable:!0,severity:\"warn\"}),b(\"PL-CF-003\",\"Explicit blocks in brace-based languages\",[\"java\",\"javascript\",\"typescript\"],{checked:!0,fixable:!0,severity:\"warn\"}),b(\"PL-NAME-001\",\"Names must be meaningful\",B,{checked:!0,severity:\"warn\"}),b(\"PL-FN-001\",\"One clear responsibility per function\",B,{checked:!0,severity:\"warn\"}),b(\"PL-STRUCT-001\",\"One clear responsibility per class or module\",B,{checked:!0,severity:\"info\"}),b(\"PL-FMT-001\",\"Prefer compact horizontal calls\",B,{checked:!0,fixable:!0,severity:\"info\"}),b(\"PL-DOC-001\",\"Comments explain why, not what\",B,{checked:!0,severity:\"hint\"}),b(\"PL-JAVA-001\",\"Package by responsibility\",[\"java\"]),b(\"PL-JAVA-002\",\"Interfaces use the I prefix\",[\"java\"],{checked:!0,severity:\"hint\"}),b(\"PL-JAVA-003\",\"Prefer records for immutable data\",[\"java\"],{checked:!0,severity:\"hint\"}),b(\"PL-JAVA-004\",\"Explicit null handling\",[\"java\"],{checked:!0,severity:\"info\"}),b(\"PL-JAVA-005\",\"Use imports instead of fully qualified class names\",[\"java\"],{checked:!0,severity:\"warn\"}),b(\"PL-JAVA-006\",\"Prefer modern Java\",[\"java\"]),b(\"PL-JAVA-007\",\"Prefer switch for real state branching\",[\"java\"]),b(\"PL-JAVA-008\",\"Do not block main or tick threads\",[\"java\"]),b(\"PL-JAVA-009\",\"Streams only when clearer\",[\"java\"]),b(\"PL-JAVA-010\",\"Lifecycle symmetry\",[\"java\"]),b(\"PL-JS-001\",\"Braces are mandatory\",z,{checked:!0,fixable:!0,severity:\"warn\"}),b(\"PL-JS-002\",\"Use semicolons\",z,{checked:!0,fixable:!0,severity:\"warn\"}),b(\"PL-JS-003\",\"const first, never var\",z,{checked:!0,severity:\"warn\"}),b(\"PL-JS-004\",\"Prefer async / await\",z,{checked:!0,severity:\"hint\"}),b(\"PL-JS-005\",\"Arrow functions are contextual\",z),b(\"PL-JS-006\",\"Destructuring must improve clarity\",z),b(\"PL-TS-001\",\"Avoid any\",[\"typescript\"],{checked:!0,severity:\"warn\"}),b(\"PL-TS-002\",\"Use types deliberately\",[\"typescript\"]),b(\"PL-TS-003\",\"No Java-style I prefix\",[\"typescript\"],{checked:!0,severity:\"warn\"}),b(\"PL-TS-004\",\"interface vs type\",[\"typescript\"]),b(\"PL-TS-005\",\"Prefer union types over enums when appropriate\",[\"typescript\"],{checked:!0,severity:\"hint\"}),b(\"PL-TS-006\",\"Strong types at boundaries, freedom internally\",[\"typescript\"]),b(\"PL-GO-001\",\"Error guards\",[\"go\"]),b(\"PL-GO-002\",\"Avoid else after terminating branches\",[\"go\"],{checked:!0,fixable:!0,severity:\"warn\"}),b(\"PL-GO-003\",\"Naming must remain idiomatic\",[\"go\"]),b(\"PL-GO-004\",\"Short receiver names are allowed\",[\"go\"]),b(\"PL-GO-005\",\"Small interfaces\",[\"go\"]),b(\"PL-GO-006\",\"Define interfaces near consumers\",[\"go\"]),b(\"PL-GO-007\",\"Use defer for clear resource lifecycles\",[\"go\"]),b(\"PL-GO-008\",\"Goroutines need ownership\",[\"go\"]),b(\"PL-GO-009\",\"Avoid premature interface abstraction\",[\"go\"]),b(\"PL-CR-001\",\"Idiomatic postfix guards are allowed\",[\"crystal\"]),b(\"PL-CR-002\",\"Avoid else\",[\"crystal\"],{checked:!0,severity:\"info\"}),b(\"PL-CR-003\",\"Idiomatic naming\",[\"crystal\"]),b(\"PL-CR-004\",\"Prefer type inference\",[\"crystal\"]),b(\"PL-CR-005\",\"Explicit nil guards\",[\"crystal\"]),b(\"PL-CR-006\",\"Exceptions are for exceptional states\",[\"crystal\"]),b(\"PL-CR-007\",\"Avoid macro cleverness without need\",[\"crystal\"]),b(\"PL-ARCH-001\",\"Abstraction requires a reason\",B)]),Me=new Map(oe.map(e=>[e.id,e]));function G(e){return Me.get(e)??null}function Ue(e){return Me.has(e)}var Je=Object.freeze([\"off\",\"hint\",\"info\",\"warn\",\"error\"]),An={error:\"error\",warn:\"warning\",info:\"info\",hint:\"hint\"};function ze(e){return An[e]??\"info\"}function q(e,t){let n=e?.rules?.[t];return n||(G(t)?.severity??\"info\")}function V(e,t){return q(e,t)!==\"off\"}var Ge=/[+-]?(?:0[xX][0-9a-fA-F]+|(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?|Infinity|NaN)/y,Ve=/[A-Za-z_$][\\w$-]*/y,Wn={n:`\n`,t:\"\t\",r:\"\\r\",b:\"\\b\",f:\"\\f\",v:\"\\v\",0:\"\\0\"},ye=class{constructor(t){this.text=t.replace(/^﻿/,\"\"),this.pos=0}fail(t){let r=this.text.slice(0,this.pos).split(`\n`).length;throw new SyntaxError(`${t} (line ${r})`)}skipBlanks(){let{text:t}=this;for(;;){let n=t[this.pos];if(n===\" \"||n===\"\t\"||n===`\n`||n===\"\\r\"){this.pos++;continue}if(n===\"/\"&&t[this.pos+1]===\"/\"){let r=t.indexOf(`\n`,this.pos);this.pos=r===-1?t.length:r+1;continue}if(n===\"/\"&&t[this.pos+1]===\"*\"){let r=t.indexOf(\"*/\",this.pos+2);this.pos=r===-1?t.length:r+2;continue}return}}readString(t){let{text:n}=this;this.pos++;let r=\"\";for(;this.pos<n.length;){let i=n[this.pos];if(i===t)return this.pos++,r;if(i===\"\\\\\"){r+=this.readEscape();continue}r+=i,this.pos++}return this.fail(\"Unterminated string\")}readEscape(){let{text:t}=this,n=t[this.pos+1];if(this.pos+=2,n===\"u\"){let r=t.slice(this.pos,this.pos+4);return this.pos+=4,String.fromCharCode(parseInt(r,16)||0)}return n===`\n`?\"\":Wn[n]??n}readKey(){let t=this.text[this.pos];if(t==='\"'||t===\"'\")return this.readString(t);Ve.lastIndex=this.pos;let n=Ve.exec(this.text);return n?(this.pos+=n[0].length,n[0]):this.fail(\"Expected a property name\")}readObject(){let t={};for(this.pos++;;){if(this.skipBlanks(),this.text[this.pos]===\"}\")return this.pos++,t;let n=this.readKey();this.skipBlanks(),this.text[this.pos]!==\":\"&&this.fail('Expected \":\"'),this.pos++,t[n]=this.readValue(),this.skipBlanks();let r=this.text[this.pos];if(r===\",\"){this.pos++;continue}r!==\"}\"&&this.fail('Expected \",\" or \"}\"')}}readArray(){let t=[];for(this.pos++;;){if(this.skipBlanks(),this.text[this.pos]===\"]\")return this.pos++,t;t.push(this.readValue()),this.skipBlanks();let n=this.text[this.pos];if(n===\",\"){this.pos++;continue}n!==\"]\"&&this.fail('Expected \",\" or \"]\"')}}readValue(){this.skipBlanks();let t=this.text[this.pos];if(t===\"{\")return this.readObject();if(t===\"[\")return this.readArray();if(t==='\"'||t===\"'\")return this.readString(t);for(let[r,i]of[[\"true\",!0],[\"false\",!1],[\"null\",null]])if(this.text.startsWith(r,this.pos))return this.pos+=r.length,i;Ge.lastIndex=this.pos;let n=Ge.exec(this.text);return n?(this.pos+=n[0].length,Number(n[0])):this.fail(\"Unexpected character\")}};function K(e){let t=new ye(String(e??\"\"));try{let n=t.readValue();return t.skipBlanks(),t.pos<t.text.length&&t.fail(\"Unexpected content after the value\"),{value:n,error:null}}catch(n){return{value:void 0,error:n.message}}}var Ke=[\"java\",\"javascript\",\"typescript\",\"go\",\"crystal\",\"kotlin\"],$n={js:\"javascript\",jsx:\"javascript\",javascriptreact:\"javascript\",ts:\"typescript\",tsx:\"typescript\",typescriptreact:\"typescript\",golang:\"go\",cr:\"crystal\",kt:\"kotlin\"},Dn={warning:\"warn\",err:\"error\",information:\"info\"},Ye=[\"indent\",\"endOfLine\",\"printWidth\",\"semicolons\",\"finalNewline\",\"trimTrailingWhitespace\",\"rules\"],Fn=[\"pureline\",\"root\",\"languages\",\"ignore\",...Ye],He=Object.freeze({indent:Object.freeze({style:\"space\",size:4}),endOfLine:\"lf\",printWidth:120,semicolons:!0,finalNewline:!0,trimTrailingWhitespace:!0,rules:Object.freeze({})});function ee(e){return e!==null&&typeof e==\"object\"&&!Array.isArray(e)}function Xe(e,t,n){if(typeof e==\"number\")return Xe({size:e},t,n);if(e===\"tab\"||e===\"space\")return{style:e};if(!ee(e)){n.push(`${t}: \"indent\" must be an object like { \"style\": \"space\", \"size\": 4 } (ignored)`);return}let r={};for(let i of Object.keys(e))i!==\"style\"&&i!==\"size\"&&n.push(`${t}: unknown key \"indent.${i}\" (ignored)`);return e.style!==void 0&&((e.style===\"space\"||e.style===\"tab\")&&(r.style=e.style),e.style!==\"space\"&&e.style!==\"tab\"&&n.push(`${t}: \"indent.style\" must be \"space\" or \"tab\" (got ${JSON.stringify(e.style)})`)),e.size!==void 0&&(Number.isInteger(e.size)&&e.size>=1&&e.size<=16&&(r.size=e.size),Number.isInteger(e.size)&&e.size>=1&&e.size<=16||n.push(`${t}: \"indent.size\" must be a whole number from 1 to 16 (got ${JSON.stringify(e.size)})`)),r}function _n(e,t,n,r){if(t===!1)return\"off\";if(t===!0)return G(e)?.severity??\"info\";let i=typeof t==\"string\"?t.toLowerCase():\"\",s=Dn[i]??i;if(Je.includes(s))return s;r.push(`${n}: rule ${e} has the invalid value ${JSON.stringify(t)}; use off, info, warn or error (ignored)`)}function Bn(e,t,n){if(!ee(e)){n.push(`${t}: \"rules\" must be an object (ignored)`);return}let r={};for(let[i,s]of Object.entries(e)){if(!Ue(i)){n.push(`${t}: unknown rule \"${i}\" (not in the Pureline 1.1 catalog, ignored)`);continue}let o=_n(i,s,t,n);o&&(r[i]=o)}return r}function Ze(e,t,n,r){if(typeof t==\"boolean\")return t;r.push(`${n}: \"${e}\" must be true or false (got ${JSON.stringify(t)})`)}function Qe(e,t,n){let r={};if(e.indent!==void 0){let i=Xe(e.indent,t,n);i&&(r.indent=i)}if(e.endOfLine!==void 0&&([\"lf\",\"crlf\",\"keep\"].includes(e.endOfLine)&&(r.endOfLine=e.endOfLine),[\"lf\",\"crlf\",\"keep\"].includes(e.endOfLine)||n.push(`${t}: \"endOfLine\" must be \"lf\", \"crlf\" or \"keep\" (got ${JSON.stringify(e.endOfLine)})`)),e.printWidth!==void 0){let i=Number.isInteger(e.printWidth)&&e.printWidth>=20&&e.printWidth<=1e3;i&&(r.printWidth=e.printWidth),i||n.push(`${t}: \"printWidth\" must be a whole number from 20 to 1000 (got ${JSON.stringify(e.printWidth)})`)}for(let i of[\"semicolons\",\"finalNewline\",\"trimTrailingWhitespace\"]){if(e[i]===void 0)continue;let s=Ze(i,e[i],t,n);s!==void 0&&(r[i]=s)}if(e.rules!==void 0){let i=Bn(e.rules,t,n);i&&(r.rules=i)}return r}function Mn(e,t){if(!ee(e)){t.push('\"languages\" must be an object (ignored)');return}let n={};for(let[r,i]of Object.entries(e)){let s=$n[r.toLowerCase()]??r.toLowerCase();if(!Ke.includes(s)){t.push(`languages: unknown language \"${r}\" (known: ${Ke.join(\", \")})`);continue}if(!ee(i)){t.push(`languages.${r} must be an object (ignored)`);continue}for(let o of Object.keys(i))Ye.includes(o)||t.push(`languages.${r}: unknown key \"${o}\" (ignored)`);n[s]=Y(n[s]??{},Qe(i,`languages.${r}`,t))}return n}function Un(e,t){if(!Array.isArray(e)||e.some(n=>typeof n!=\"string\")){t.push('\"ignore\" must be a list of glob strings (ignored)');return}return e.map(n=>n.trim()).filter(Boolean)}function qe(e){let t=[],{value:n,error:r}=K(e);if(r)return t.push(`.pureline is not valid JSON: ${r} \\u2014 defaults are used`),{config:{},notes:t};if(!ee(n))return t.push(\".pureline must contain a JSON object \\u2014 defaults are used\"),{config:{},notes:t};for(let s of Object.keys(n))Fn.includes(s)||t.push(`.pureline: unknown key \"${s}\" (ignored)`);let i=Qe(n,\".pureline\",t);if(n.pureline!==void 0&&!/^1(\\.\\d+)?$/.test(String(n.pureline))&&t.push(`.pureline: \"pureline\" says ${JSON.stringify(n.pureline)}, this formatter implements Pureline 1.1`),n.root!==void 0){let s=Ze(\"root\",n.root,\".pureline\",t);s!==void 0&&(i.root=s)}if(n.languages!==void 0){let s=Mn(n.languages,t);s&&(i.languages=s)}if(n.ignore!==void 0){let s=Un(n.ignore,t);s&&(i.ignore=s)}return{config:i,notes:t}}function Y(e,t){let n={...e};for(let r of[\"endOfLine\",\"printWidth\",\"semicolons\",\"finalNewline\",\"trimTrailingWhitespace\"])t[r]!==void 0&&(n[r]=t[r]);if((e.indent||t.indent)&&(n.indent={...e.indent,...t.indent}),(e.rules||t.rules)&&(n.rules={...e.rules,...t.rules}),e.languages||t.languages){let r={...e.languages};for(let[i,s]of Object.entries(t.languages??{}))r[i]=Y(r[i]??{},s);n.languages=r}return n}function et(e,t,n=He){let r=Y(n,e??{}),i=r.languages?.[t]??{},s=Y(r,i);return{indent:{style:s.indent?.style??\"space\",size:s.indent?.size??4},endOfLine:s.endOfLine,printWidth:s.printWidth,semicolons:s.semicolons,finalNewline:s.finalNewline,trimTrailingWhitespace:s.trimTrailingWhitespace,rules:{...s.rules}}}function tt(e){return e.indent.style===\"tab\"?\"\t\":\" \".repeat(e.indent.size)}function nt(e,t={},n={}){let r=n.defaultIndent??\"4\",i={style:t.useTabs?\"tab\":\"space\",size:Number.isInteger(t.tabWidth)?t.tabWidth:4},s={style:\"space\",size:Number(r)||4},o=r===\"editor\"?i:s;return e===\"go\"&&(o={style:\"tab\",size:4}),e===\"crystal\"&&(o={style:\"space\",size:2}),{indent:o,endOfLine:t.endOfLine??\"lf\",printWidth:He.printWidth,semicolons:!0,finalNewline:t.insertFinalNewline??!0,trimTrailingWhitespace:t.trimTrailingWhitespace??!0,rules:{}}}function rt(){return`{\n  // Pureline spec file \\u2014 https://github.com/ezTxmMC/lumen-ide (Pureline 1.1)\n  \"pureline\": \"1.1\",\n\n  // true: do not inherit values from a .pureline in a parent folder.\n  \"root\": true,\n\n  \"indent\": { \"style\": \"space\", \"size\": 4 },\n  \"endOfLine\": \"lf\",\n  \"printWidth\": 120,\n  \"semicolons\": true,\n  \"finalNewline\": true,\n  \"trimTrailingWhitespace\": true,\n\n  // off | info | warn | error. A rule that is \"off\" is neither fixed by the\n  // formatter nor reported by the checker. Every other rule that has a safe\n  // automatic fix is applied when you format.\n  \"rules\": {\n    // \"PL-CF-002\": \"error\",\n    // \"PL-FMT-001\": \"off\"\n  },\n\n  // Per-language overrides of indent, endOfLine, printWidth, semicolons,\n  // finalNewline, trimTrailingWhitespace and rules.\n  \"languages\": {\n    // \"typescript\": { \"indent\": { \"size\": 2 } },\n    // \"go\": { \"indent\": { \"style\": \"tab\" } }\n  },\n\n  // Files the Pureline formatter and checker skip (globs relative to this\n  // file; *, ** and ? are supported).\n  \"ignore\": [\n    // \"dist/**\",\n    // \"*.min.js\"\n  ]\n}\n`}function it(e){let t=null;for(let n=0;n<e.length;n++){let r=e[n];if(t){r===t&&(t=null);continue}if((r==='\"'||r===\"'\")&&(t=r),r===\"#\"&&(n===0||/\\s/.test(e[n-1])))return e.slice(0,n)}return e}function st(e){let t=e.trim();if(t===\"\")return;if(t.toLowerCase()===\"true\")return!0;if(t.toLowerCase()===\"false\")return!1;if(t===\"null\"||t===\"~\")return null;if(/^[+-]?\\d+(\\.\\d+)?$/.test(t))return Number(t);let n=/^([\"'])(.*)\\1$/.exec(t);if(n)return n[2];if(!(t.startsWith(\"[\")||t.startsWith(\"{\")))return t}function ve(e){let t={};for(let n of String(e).replace(/^﻿/,\"\").split(/\\r?\\n/)){let r=it(n);if(!r.trim()||r.trim()===\"---\"||/^\\s/.test(r)||r.startsWith(\"-\"))continue;let i=r.indexOf(\":\");if(i===-1)continue;let s=r.slice(0,i).trim().replace(/^[\"']|[\"']$/g,\"\"),o=st(r.slice(i+1));s&&o!==void 0&&(t[s]=o)}return t}function ot(e){let t={};for(let n of String(e).replace(/^﻿/,\"\").split(/\\r?\\n/)){let r=it(n).trim();if(!r)continue;if(r.startsWith(\"[\"))break;let i=r.indexOf(\"=\");if(i===-1)continue;let s=r.slice(0,i).trim().replace(/^[\"']|[\"']$/g,\"\"),o=st(r.slice(i+1));s&&o!==void 0&&(t[s]=o)}return t}var lt=Object.freeze([\".prettierrc\",\".prettierrc.json\",\".prettierrc.yaml\",\".prettierrc.yml\",\".prettierrc.json5\",\".prettierrc.toml\",\".prettierrc.js\",\".prettierrc.cjs\",\".prettierrc.mjs\",\".prettierrc.ts\",\".prettierrc.cts\",\".prettierrc.mts\",\"prettier.config.js\",\"prettier.config.cjs\",\"prettier.config.mjs\",\"prettier.config.ts\",\"prettier.config.cts\",\"prettier.config.mts\"]);function Jn(e){return e===\".prettierrc\"?\"rc\":/\\.(?:json|json5)$/.test(e)?\"json\":/\\.ya?ml$/.test(e)?\"yaml\":/\\.toml$/.test(e)?\"toml\":\"script\"}function ae(e){return e!==null&&typeof e==\"object\"&&!Array.isArray(e)}function zn(e,t){return e===\"json\"?K(t):e===\"yaml\"?{value:ve(t),error:null}:e===\"toml\"?{value:ot(t),error:null}:e===\"rc\"?/^\\s*(?:\\{|\\/[/*])/.test(t)?K(t):{value:ve(t),error:null}:{value:void 0,error:\"not read\"}}function le(e,t,n=!1){if(n){let f=K(t).value?.prettier;return ae(f)?{options:f,overrides:Array.isArray(f.overrides)?f.overrides:[],readable:!0,error:null}:{options:{},overrides:[],readable:!1,error:null}}let r=Jn(e);if(r===\"script\")return{options:{},overrides:[],readable:!1,error:null};let{value:i,error:s}=zn(r,t);if(s||!ae(i))return{options:{},overrides:[],readable:!1,error:s??\"The config is not an object.\"};let a=(r===\"json\"||r===\"rc\"&&/^\\s*\\{/.test(t))&&Array.isArray(i.overrides)?i.overrides:[];return{options:i,overrides:a,readable:!0,error:null}}function at(e){return typeof e==\"string\"?[e]:Array.isArray(e)?e.filter(t=>typeof t==\"string\"):[]}function Gn(e,t){if(!ae(e))return!1;let n=at(e.files),r=at(e.excludeFiles);return n.some(s=>se(s,t))&&!r.some(s=>se(s,t))}function ct(e,t){let{overrides:n,options:r}=e,i=Object.fromEntries(Object.entries(r).filter(([s])=>s!==\"overrides\"));for(let s of n)Gn(s,t)&&ae(s.options)&&(i={...i,...s.options});return i}function ut(e){let t={},n={};return Number.isInteger(e.tabWidth)&&e.tabWidth>=1&&e.tabWidth<=16&&(n.size=e.tabWidth),typeof e.useTabs==\"boolean\"&&(n.style=e.useTabs?\"tab\":\"space\"),Object.keys(n).length&&(t.indent=n),typeof e.semi==\"boolean\"&&(t.semicolons=e.semi),Number.isInteger(e.printWidth)&&e.printWidth>=20&&(t.printWidth=e.printWidth),(e.endOfLine===\"lf\"||e.endOfLine===\"crlf\")&&(t.endOfLine=e.endOfLine),(e.endOfLine===\"auto\"||e.endOfLine===\"cr\")&&(t.endOfLine=\"keep\"),t}function ft(e){return String(e).split(/\\r?\\n/).map(t=>t.replace(/\\s+$/,\"\")).filter(t=>t&&!t.startsWith(\"#\")).map(t=>{let n=t.startsWith(\"!\");return{pattern:n?t.slice(1):t,negated:n}})}function Vn(e,t){let n=e.replace(/^\\.\\//,\"\"),r=n.endsWith(\"/\");r&&(n=n.slice(0,-1));let i=n.startsWith(\"/\")||n.slice(0,-1).includes(\"/\");n=n.replace(/^\\//,\"\");let s=t.split(\"/\"),o=ie(n);if(i){for(let a=s.length;a>=1;a--)if(!(r&&a===s.length)&&o.test(s.slice(0,a).join(\"/\")))return!0;return!1}return s.some((a,l)=>r&&l===s.length-1?!1:o.test(a))}function dt(e,t){let n=String(t).replace(/\\\\/g,\"/\").replace(/^\\.\\//,\"\"),r=!1;for(let{pattern:i,negated:s}of e)Vn(i,n)&&(r=!s);return r}var ce=\".pureline\";async function pt(e){try{return await ht.access(e),!0}catch{return!1}}async function we(e){try{return await ht.readFile(e,\"utf8\")}catch{return null}}function ue(e,t){let n=$.relative(e,t);return n===\"\"||!n.startsWith(\"..\")&&!$.isAbsolute(n)}function te(e,t){let n=[],r=$.resolve(e);for(;;){if(n.push(r),t&&$.resolve(t)===r)return n;let i=$.dirname(r);if(i===r)return n;r=i}}function mt(e,t){return t&&e&&ue(t,e)?t:null}async function Kn(e){let t=$.join(e,ce),n={pureline:await pt(t)?t:null,prettier:null};for(let s of lt){let o=$.join(e,s);if(await pt(o))return n.prettier={file:o,name:s,packageJson:!1},n}let r=$.join(e,\"package.json\"),i=await we(r);return i&&i.includes('\"prettier\"')&&(le(\"package.json\",i,!0).readable||/\"prettier\"\\s*:\\s*\"/.test(i))&&(n.prettier={file:r,name:\"package.json\",packageJson:!0}),n}async function ne(e,t,n=\"auto\"){for(let r of te(e,t)){let i=await Kn(r),s=n!==\"prettier\"?i.pureline:null,o=n!==\"pureline\"?i.prettier:null;if(s||o)return{folder:r,pureline:s,prettier:o}}return null}async function gt(e,t){let n=[],r=[],i={},s=[];for(let o of te(e,t)){let a=$.join(o,ce),l=await we(a);if(l===null)continue;let{config:f,notes:u}=qe(l);for(let h of u)r.push(`${a}: ${h}`);if(s.push({file:a,folder:o,config:f}),f.root===!0)break}for(let o of[...s].reverse())i=Y(i,o.config);for(let o of s)n.push({file:o.file,folder:o.folder,ignore:o.config.ignore??[]});return{config:i,files:n,notes:r}}function yt(e,t){return t?e.some(n=>!n.ignore.length||!ue(n.folder,t)?!1:Be(n.ignore,$.relative(n.folder,t).split($.sep).join(\"/\"))):!1}async function vt(e,t){for(let n of te(e,t)){let r=await we($.join(n,\".prettierignore\"));if(r!==null)return{folder:n,entries:ft(r)}}return null}import fs from\"node:fs/promises\";import U from\"node:path\";var d=Object.freeze({WS:\"ws\",NEWLINE:\"newline\",COMMENT:\"comment\",STRING:\"string\",TEMPLATE:\"template\",REGEX:\"regex\",WORD:\"word\",NUMBER:\"number\",PUNCT:\"punct\"}),Yn=new Set([\"return\",\"typeof\",\"case\",\"do\",\"else\",\"in\",\"of\",\"void\",\"delete\",\"throw\",\"new\",\"yield\",\"await\",\"instanceof\"]),Hn=[\">>>=\"],Xn=[\"...\",\"===\",\"!==\",\"**=\",\"<<=\",\">>=\",\">>>\",\"&&=\",\"||=\",\"??=\"],Zn=[\"==\",\"!=\",\"<=\",\">=\",\"&&\",\"||\",\"++\",\"--\",\"+=\",\"-=\",\"*=\",\"/=\",\"%=\",\"&=\",\"|=\",\"^=\",\"<<\",\">>\"],Qn={js:[\"=>\",\"??\",\"?.\",\"**\"],java:[\"->\",\"::\"],kotlin:[\"->\",\"::\",\"?.\",\"?:\",\"..\"],go:[\":=\",\"<-\",\"&^\"]},wt=/(?:0[xXbBoO][0-9a-fA-F_]+|(?:\\d[\\d_]*\\.?[\\d_]*|\\.\\d[\\d_]*)(?:[eE][+-]?\\d+)?)[a-zA-Z]*/y,bt=/[A-Za-z_$\\u0080-￿][\\w$\\u0080-￿]*/y;function qn(e){let t=0;for(let n=e.indexOf(`\n`);n!==-1;n=e.indexOf(`\n`,n+1))t++;return t}function kt(e,t,n){let r=t+1;for(;r<e.length;){let i=e[r];if(i===\"\\\\\"){r+=2;continue}if(i===n)return r+1;if(i===`\n`)return r;r++}return e.length}function er(e,t){let n=1,r=t;for(;r<e.length;){let i=e[r];if(i===\"{\"&&n++,i===\"}\"&&n--,n===0)return r+1;if(i===\"'\"||i==='\"'){r=kt(e,r,i);continue}if(i===\"`\"){r=be(e,r,\"`\");continue}if(i===\"/\"&&e[r+1]===\"/\"){let s=e.indexOf(`\n`,r);r=s===-1?e.length:s;continue}if(i===\"/\"&&e[r+1]===\"*\"){let s=e.indexOf(\"*/\",r+2);r=s===-1?e.length:s+2;continue}if(i===\"/\"&&tr(e,t,r)){let s=St(e,r);if(s!==-1){r=s;continue}}r++}return e.length}function tr(e,t,n){let r=n-1;for(;r>=t&&` \t\n`.includes(e[r]);)r--;return r<t?!0:\"(,=:[!&|?{};+-*%<>~^\".includes(e[r])}function be(e,t,n){let r=t+1;for(;r<e.length;){let i=e[r];if(i===\"\\\\\"){r+=2;continue}if(i===n)return r+1;if(i===\"$\"&&e[r+1]===\"{\"){r=er(e,r+2);continue}r++}return e.length}function nr(e,t){let n=t+3;for(;n<e.length;){if(e[n]===\"\\\\\"){n+=2;continue}if(e.startsWith('\"\"\"',n)){let r=n+3;for(;e[r]==='\"';)r++;return r}n++}return e.length}function rr(e,t){let n=e.indexOf(\"`\",t+1);return n===-1?e.length:n+1}function St(e,t){let n=t+1,r=!1;for(;n<e.length;){let i=e[n];if(i===`\n`)return-1;if(i===\"\\\\\"){n+=2;continue}if(i===\"[\"&&(r=!0),i===\"]\"&&(r=!1),i===\"/\"&&!r){let s=n+1;for(;/[a-z]/i.test(e[s]??\"\");)s++;return s}n++}return-1}function ir(e){return e?e.type===d.WORD?Yn.has(e.value):e.type!==d.PUNCT?!1:![\")\",\"]\",\"}\",\"++\",\"--\"].includes(e.value):!0}function sr(e,t,n){for(let r of Hn)if(e.startsWith(r,t))return r;for(let r of Xn)if(e.startsWith(r,t))return r;for(let r of n)if(e.startsWith(r,t))return r;return e[t]}function Ot(e,t){let n=[],r=[...Zn,...Qn[t]??[]],i=0,s=0,o=null,a=(l,f)=>{let u={type:l,value:e.slice(i,f),start:i,end:f,line:s};return n.push(u),s+=qn(u.value),l!==d.WS&&l!==d.NEWLINE&&l!==d.COMMENT&&(o=u),i=f,u};for(;i<e.length;){let l=e[i],f=e[i+1];if(l===`\n`){a(d.NEWLINE,i+1);continue}if(l===\" \"||l===\"\t\"||l===\"\\r\"||l===\"\\f\"||l===\"\\v\"){let h=i+1;for(;h<e.length&&\" \t\\r\\f\\v\".includes(e[h]);)h++;a(d.WS,h);continue}if(l===\"/\"&&f===\"/\"){let h=e.indexOf(`\n`,i);a(d.COMMENT,h===-1?e.length:h).block=!1;continue}if(l===\"/\"&&f===\"*\"){let h=e.indexOf(\"*/\",i+2);a(d.COMMENT,h===-1?e.length:h+2).block=!0;continue}if(l==='\"'&&e.startsWith('\"\"\"',i)&&(t===\"java\"||t===\"kotlin\")){a(d.TEMPLATE,nr(e,i)).kind=\"textblock\";continue}if(l==='\"'&&t===\"kotlin\"){a(d.TEMPLATE,be(e,i,'\"')).kind=\"string\";continue}if(l==='\"'||l===\"'\"){a(d.STRING,kt(e,i,l));continue}if(l===\"`\"&&t===\"go\"){a(d.TEMPLATE,rr(e,i)).kind=\"raw\";continue}if(l===\"`\"&&t===\"js\"){a(d.TEMPLATE,be(e,i,\"`\")).kind=\"template\";continue}if(l===\"/\"&&t===\"js\"&&ir(o)){let h=St(e,i);if(h!==-1){a(d.REGEX,h);continue}}if(/\\d/.test(l)||l===\".\"&&/\\d/.test(f??\"\")){wt.lastIndex=i;let h=wt.exec(e);if(h){a(d.NUMBER,i+h[0].length);continue}}bt.lastIndex=i;let u=bt.exec(e);if(u){a(d.WORD,i+u[0].length);continue}a(d.PUNCT,i+sr(e,i,r).length)}return n}var or=/^(?:check(?:s|ing)?\\s+(?:if|whether|that)|get(?:s)?\\s+the|set(?:s)?\\s+the|return(?:s)?\\s+the|create(?:s)?\\s+(?:a|an|the)\\s+new|loop(?:s)?\\s+(?:through|over)|iterate(?:s)?\\s+(?:through|over)|increment(?:s)?\\b|decrement(?:s)?\\b|initiali[sz]e(?:s)?\\s+(?:the|a)|call(?:s)?\\s+the|define(?:s)?\\s+(?:a|the)|declare(?:s)?\\s+(?:a|the)|if\\s+the\\b)/i;function ke(e){let t=e.replace(/^\\s*(?:\\/\\/+|#+|\\/\\*+|\\*+)\\s*/,\"\").replace(/\\s*\\*\\/\\s*$/,\"\").trim();return t.length<8||t.includes(`\n`)?!1:or.test(t)}function Pt(e){for(let t of e.src.tokens)t.type!==d.COMMENT||!ke(t.value)||e.report(\"PL-DOC-001\",{start:t.start,end:t.end,message:\"This comment restates what the code already says.\",suggestion:\"Say why something unusual is necessary, or delete the comment.\",severity:\"hint\"})}var Lt=\"([{\",Et=\")]}\";function H(e){let t=[0];for(let n=e.indexOf(`\n`);n!==-1;n=e.indexOf(`\n`,n+1))t.push(n+1);return t}function fe(e,t){let n=0,r=e.length-1;for(;n<r;){let i=n+r+1>>1;if(e[i]<=t){n=i;continue}r=i-1}return n}function Se(e,t){let n=fe(e,t);return{line:n,column:t-e[n]}}function c(e,t){return!!e&&e.type===d.PUNCT&&e.value===t}function m(e,t){return!e||e.type!==d.WORD?!1:t===void 0||e.value===t}function ar(e){return e.type===d.COMMENT?e.block&&!e.value.endsWith(\"*/\"):e.type===d.STRING?e.value.length<2||e.value[e.value.length-1]!==e.value[0]:e.type!==d.TEMPLATE?!1:e.kind===\"textblock\"?!e.value.endsWith('\"\"\"')||e.value.length<6:e.value.length<2||!e.value.endsWith(e.value[0])}function M(e,t){let n=Ot(e,t.family),r=[],i=0,s=!1;for(let u of n){if(u.type===d.NEWLINE){i++;continue}if(u.type!==d.WS){if(u.type===d.COMMENT){s=!0,i+=u.value.split(`\n`).length-1;continue}u.si=r.length,u.nlBefore=i,u.commentBefore=s,i=0,s=!1,r.push(u)}}let o=new Array(r.length).fill(-1),a=new Array(r.length).fill(-1),l=[],f=!0;return r.forEach((u,h)=>{if(a[h]=l.length?l[l.length-1]:-1,u.type!==d.PUNCT)return;if(Lt.includes(u.value)&&u.value.length===1){l.push(h);return}if(!Et.includes(u.value)||u.value.length!==1)return;let g=l.pop();if(g===void 0||Lt.indexOf(r[g].value)!==Et.indexOf(u.value)){f=!1;return}o[g]=h,o[h]=g,a[h]=a[g]}),(l.length||n.some(ar))&&(f=!1),{text:e,language:t,tokens:n,sig:r,match:o,parent:a,balanced:f,lineStarts:H(e)}}function Tt(e){let t=new Set,n=new Set;for(let r of e.tokens){if(r.type!==d.STRING&&r.type!==d.TEMPLATE)continue;let i=r.value.split(`\n`).length-1;for(let s=1;s<=i;s++)t.add(r.line+s),n.add(r.line+s-1)}return{startsInside:t,endsInside:n}}function Ct(e){let t=new Map;for(let n of e.tokens)n.type===d.COMMENT&&n.block&&n.value.includes(`\n`)&&t.set(n.line,n);return t}function de(e,t,n=0){let r=[],i=t-1;for(;i>=n&&e[i].type===d.WORD&&(r.push(e[i]),!!c(e[i-1],\",\"));)i-=2;return r}function Oe(e,t){let n=[],r=new Set,i=o=>{let a=G(o);return a?q(t,o)!==\"off\"&&a.languages.includes(e.language.name):!1};return{src:e,config:t,diagnostics:n,report:(o,a)=>{if(!i(o))return;let l=Se(e.lineStarts,a.start),f=Se(e.lineStarts,a.end??a.start+1),u=`${o}:${l.line}:${l.column}:${a.message}`;if(r.has(u))return;r.add(u);let g=t?.rules?.[o]??a.severity??G(o).severity;n.push({line:l.line,column:l.column,endLine:f.line,endColumn:f.column,severity:ze(g),message:a.message,code:o,source:\"Pureline\",...a.suggestion?{suggestion:a.suggestion}:{}})},applies:i}}var lr=new Set([\"if\",\"for\",\"while\",\"switch\",\"catch\",\"function\",\"return\",\"typeof\",\"new\",\"synchronized\",\"with\",\"await\",\"yield\",\"case\",\"in\",\"of\",\"else\",\"do\",\"throw\",\"func\",\"try\",\"assert\",\"instanceof\",\"void\",\"delete\",\"import\",\"export\",\"var\",\"const\",\"type\",\"select\",\"go\",\"defer\",\"range\",\"package\"]),cr=new Set([\"func\",\"function\",\"fn\"]);function ur(e,t,n){let{sig:r,match:i}=e,s=0;for(let o=t+1;o<n;o++){let a=r[o],l=a.type===d.PUNCT&&[\")\",\"]\",\"}\"].includes(a.value);if(a.commentBefore||a.nlBefore>0&&s>0||(a.type===d.TEMPLATE||a.type===d.STRING)&&a.value.includes(`\n`))return!1;if(a.type===d.PUNCT&&[\"(\",\"[\",\"{\"].includes(a.value)){if(i[o]===-1)return!1;s++}l&&s--}return s===0&&!r[n].commentBefore}function fr(e,t){let n=t;for(;n>0&&e.sig[n].nlBefore===0;)n--;return e.sig[n]}function Nt(e,t){let n=e.lastIndexOf(`\n`,t-1)+1,r=e.indexOf(`\n`,t);return{start:n,end:r===-1?e.length:r}}function dr(e,t){return[.../^[ \\t]*/.exec(e)[0]].reduce((r,i)=>r+(i===\"\t\"?t:1),0)}function pr(e,t,n){let{sig:r,text:i}=e;return n===t+1?\"\":r[n].nlBefore>0?\" \":i.slice(r[n-1].end,r[n].start)}function hr(e,t,n){let{sig:r}=e,i=n-1;c(r[i],\",\")&&i>t&&i--;let s=\"\";for(let o=t+1;o<=i;o++)s+=pr(e,t,o)+r[o].value;return s}function mr(e,t){let{sig:n,match:r}=e,i=r[t],s=n[t-1];if(i===-1||!s||s.type!==d.WORD||lr.has(s.value))return!1;let o=n[t+1];if(i===t+1)return n[i].nlBefore>0&&!n[i].commentBefore;if(!o||o.nlBefore===0||o.commentBefore||n[i].nlBefore===0)return!1;let a=n[i+1];if(a&&(c(a,\"{\")||c(a,\"=>\")||c(a,\":\")||a.type===d.WORD&&a.value===\"throws\"))return!1;let l=fr(e,t);return c(l,\".\")||c(l,\"?.\")||l.type===d.WORD&&cr.has(l.value)?!1:ur(e,t,i)}function pe(e,t,n){if(!e.language.structural)return[];let{sig:r,text:i}=e,s=[];for(let o=0;o<r.length;o++){if(!c(r[o],\"(\")||!mr(e,o))continue;let a=e.match[o],l=hr(e,o,a),f=Nt(i,r[o].start),u=Nt(i,r[a].start),h=i.slice(f.start,r[o].end),g=i.slice(r[a].end,u.end).trimEnd();dr(h,n)+h.trimStart().length+l.length+1+g.length>t||s.push({rule:\"PL-FMT-001\",openIndex:o,start:r[o].start,end:r[a].end,edits:[{start:r[o].end,end:r[a].end,text:`${l})`}]})}return s}var gr=new Set([\"in\",\"of\",\"instanceof\",\"typeof\",\"new\",\"await\",\"void\",\"delete\",\"extends\",\"as\",\"satisfies\",\"keyof\",\"yield\",\"is\",\"async\"]),yr=new Set([\")\",\"]\",\"}\",\"++\",\"--\"]),vr=new Set([\"in\",\"of\",\"instanceof\",\"as\",\"satisfies\",\"extends\",\"implements\"]),Pe=new Set([\"return\",\"throw\",\"new\",\"else\",\"case\",\"default\",\"break\",\"continue\",\"yield\",\"assert\",\"super\",\"this\",\"goto\",\"if\",\"for\",\"while\",\"do\",\"switch\",\"try\",\"catch\",\"finally\",\"import\",\"package\",\"export\",\"await\",\"delete\",\"typeof\"]),wr=new Set([\"return\",\"throw\",\"continue\",\"break\"]);function _(e){return e?e.type===d.WORD?!gr.has(e.value):e.type===d.PUNCT?yr.has(e.value):!0:!1}function X(e){if(!e)return!1;if(e.type===d.TEMPLATE)return!0;if(e.type===d.WORD)return vr.has(e.value);if(e.type!==d.PUNCT)return!1;let t=e.value;return[\".\",\"?.\",\"(\",\"[\",\",\",\"?\",\":\",\"=>\",\"+\",\"-\",\"*\",\"/\",\"%\",\"&\",\"|\",\"^\",\"<\",\">\",\"&&\",\"||\",\"??\",\"**\",\"<<\",\">>\",\">>>\",\"++\",\"--\",\"{\",\"->\",\"::\"].includes(t)?!0:t.endsWith(\"=\")}function Ee(e){return!!e&&e.type===d.PUNCT&&(e.value===\")\"||e.value===\"]\"||e.value===\"}\")}function Te(e){return!!e&&e.type===d.PUNCT&&(e.value===\"(\"||e.value===\"[\"||e.value===\"{\")}function It(e,t){let{sig:n,match:r,language:i}=e,s=i.family===\"js\",o=t;for(;o<n.length;){let a=n[o];if(Te(a)){if(r[o]===-1)return-1;o=r[o]}if(c(n[o],\";\"))return o;let l=n[o+1];if(!l||Ee(l))return s&&_(n[o])?o:-1;if(s&&l.nlBefore>0&&_(n[o])&&!X(l))return o;o++}return-1}function Le(e,t){let n=m(e.sig[t+1],\"await\")?t+2:t+1;return!c(e.sig[n],\"(\")||e.match[n]===-1?-1:e.match[n]+1}function br(e,t){let{sig:n,match:r}=e,i=t+1;if(c(n[i],\"(\")&&r[i]!==-1&&(i=r[i]+1),!c(n[i],\"{\")||r[i]===-1)return-1;let s=r[i];for(;;){let o=n[s+1];if(m(o,\"catch\")){let a=s+2,l=c(n[a],\"(\")&&r[a]!==-1?r[a]+1:a;if(!c(n[l],\"{\")||r[l]===-1)return-1;s=r[l];continue}if(m(o,\"finally\")){let a=s+2;if(!c(n[a],\"{\")||r[a]===-1)return-1;s=r[a];continue}return s}}function kr(e,t){let n=J(e,t+1);if(n===-1)return-1;let r=n+1;if(!m(e.sig[r],\"while\")||!c(e.sig[r+1],\"(\")||e.match[r+1]===-1)return-1;let i=e.match[r+1];return c(e.sig[i+1],\";\")?i+1:i}function Sr(e,t){let n=Le(e,t);if(n===-1)return-1;let r=J(e,n);return r===-1?-1:m(e.sig[r+1],\"else\")?J(e,r+2):r}function J(e,t){let n=e.sig[t];if(!n)return-1;if(c(n,\"{\"))return e.match[t];if(c(n,\";\"))return-1;if(n.type!==d.WORD)return It(e,t);if(c(e.sig[t+1],\":\")&&![\"case\",\"default\"].includes(n.value))return J(e,t+2);switch(n.value){case\"if\":return Sr(e,t);case\"for\":case\"while\":{let r=Le(e,t);return r===-1?-1:J(e,r)}case\"do\":return kr(e,t);case\"try\":return br(e,t);case\"switch\":{let r=Le(e,t);return r===-1||!c(e.sig[r],\"{\")?-1:e.match[r]}case\"else\":case\"case\":case\"default\":case\"function\":case\"class\":case\"interface\":case\"enum\":case\"async\":return-1;default:return It(e,t)}}function Or(e,t){let n=e.match[t];if(n===-1)return!1;let r=e.sig[n-1];return r?r.type===d.PUNCT?[\";\",\"{\",\"}\",\")\"].includes(r.value):r.type===d.WORD&&[\"else\",\"do\",\"try\",\"finally\"].includes(r.value):!0}function xt(e,t,n){let{sig:r,language:i}=e,s=[],o=!0,a=t+1;for(;a<n;){o&&(s.push(a),o=!1);let l=a;if(Te(r[a])&&(l=e.match[a]),l===-1||l>=n)break;let f=r[l],u=r[l+1],h=i.family!==\"java\"&&u.nlBefore>0&&_(f)&&!X(u),g=c(f,\"}\")&&Or(e,l);o=c(f,\";\")||g||h,a=l+1}for(;s.length&&c(r[s[s.length-1]],\";\");)s.pop();return s}function Ce(e,t){let n=e.match[t];if(n===-1||n===t+1)return!1;let r=xt(e,t,n);if(!r.length)return!1;let i=e.sig[r[r.length-1]];return i.type===d.WORD&&wr.has(i.value)}function Pr(e,t){let{sig:n,match:r}=e;for(let o=t-2,a=0;o>=0&&a<40;o--,a++){let l=n[o];if(Ee(l)&&r[o]!==-1&&!c(l,\"}\")){o=r[o];continue}if(m(l,\"case\")||m(l,\"default\"))return\"block\";if(c(l,\";\")||c(l,\"{\")||c(l,\"}\"))break}let i=n[t-2],s=n[t-3];return m(i)&&(!s||c(s,\";\")||c(s,\"}\")||c(s,\"{\")&&jt(e,t-3)===\"block\")?\"block\":\"unknown\"}function jt(e,t){let{sig:n,match:r}=e,i=n[t-1];if(!i)return\"block\";if(i.type===d.PUNCT){if([\";\",\"{\",\"}\",\")\",\"=>\",\"->\"].includes(i.value))return\"block\";if(i.value===\":\")return Pr(e,t);if(i.value!==\">\")return\"object\"}if(i.type===d.WORD&&[\"else\",\"do\",\"try\",\"finally\",\"static\"].includes(i.value))return\"block\";if(i.type===d.WORD&&i.value===\"return\")return\"object\";if(i.type===d.WORD&&[\"export\",\"import\",\"as\",\"from\",\"default\"].includes(i.value))return\"unknown\";for(let s=t-1,o=0;s>=0&&o<300;s--,o++){let a=n[s];if(Ee(a)&&r[s]!==-1&&!c(a,\"}\")){s=r[s];continue}if(a.type===d.PUNCT&&[\";\",\"{\",\"}\",\"=\"].includes(a.value))return\"unknown\";if(a.type===d.WORD){if(a.value===\"class\")return\"class\";if(a.value===\"interface\"||a.value===\"enum\"||a.value===\"struct\")return\"type\";if(a.value===\"function\"||a.value===\"namespace\"||a.value===\"module\"||e.language.family===\"go\"&&[\"func\",\"if\",\"for\",\"switch\",\"select\"].includes(a.value))return\"block\"}if(a.nlBefore>0&&_(n[s-1])&&!X(a))return\"unknown\"}return\"unknown\"}function Z(e,t){let n=e.parent[t];return n===-1?\"block\":c(e.sig[n],\"{\")?jt(e,n):\"expression\"}function Lr(e,t){return Te(e.sig[t])&&e.match[t]!==-1?e.match[t]:t}function Er(e,t){let{sig:n}=e,r=t;for(;c(n[r],\"@\")&&m(n[r+1]);){for(r+=2;c(n[r],\".\")&&m(n[r+1]);)r+=2;c(n[r],\"(\")&&e.match[r]!==-1&&(r=e.match[r]+1)}for(;m(n[r],\"final\");)r++;if(!m(n[r])||Pe.has(n[r].value))return null;for(r++;c(n[r],\".\")&&m(n[r+1]);)r+=2;if(c(n[r],\"<\")){let s=0;for(;r<n.length&&(s+=n[r].value===\"<\"?1:0,s-=n[r].value===\">\"?1:0,s-=n[r].value===\">>\"?2:0,!(s<=0));r++);r++}for(;c(n[r],\"[\")&&c(n[r+1],\"]\");)r+=2;if(!m(n[r])||Pe.has(n[r].value))return null;let i=n[r+1];return!i||i.type!==d.PUNCT||![\"=\",\";\",\",\",\":\"].includes(i.value)?null:n[r].value}function Rt(e,t,n){let{sig:r,language:i}=e,s=new Set,o=!1,a=t+1;for(;a<n;){let l=r[a];if(l.type===d.WORD&&[\"const\",\"let\",\"var\",\"function\",\"class\",\"interface\",\"enum\",\"type\",\"namespace\"].includes(l.value)&&i.family===\"js\"){let u=a+1;c(r[u],\"*\")&&u++,m(r[u])&&s.add(r[u].value),!m(r[u])&&l.value!==\"type\"&&(o=!0)}if(i.family===\"go\"&&l.type===d.WORD&&[\"var\",\"const\",\"type\"].includes(l.value)&&(m(r[a+1])&&s.add(r[a+1].value),m(r[a+1])||(o=!0)),i.family===\"go\"&&c(l,\":=\"))for(let u of de(r,a,t+1))s.add(u.value);a=Lr(e,a)+1}if(i.family===\"java\")for(let l of xt(e,t,n)){let f=Er(e,l);f&&s.add(f),m(r[l])&&[\"class\",\"interface\",\"enum\",\"record\"].includes(r[l].value)&&m(r[l+1])&&s.add(r[l+1].value)}return{names:s,unsure:o}}function At(e,t){let{sig:n,language:r}=e,i=0;for(let s=0;s<n.length;s++){if(!m(n[s],t)||c(n[s-1],\".\"))continue;let o=n[s-1],a=n[s+1];r.family===\"js\"&&o?.type===d.WORD&&[\"const\",\"let\",\"var\",\"function\",\"class\",\"interface\",\"enum\",\"type\",\"namespace\"].includes(o.value)&&i++,r.family===\"go\"&&(c(a,\":=\")||o?.type===d.WORD&&[\"var\",\"const\",\"type\"].includes(o.value))&&i++,r.family===\"go\"&&c(a,\",\")&&c(n[s+2],\":=\")&&i++;let l=o&&(o.type===d.WORD&&!Pe.has(o.value)||c(o,\">\")||c(o,\"]\")),f=a&&a.type===d.PUNCT&&[\"=\",\";\",\",\",\":\",\")\"].includes(a.value);r.family===\"java\"&&l&&f&&i++}return i}function Wt(e,t,n,r,i,s){for(let o=n;o<=r;o++)if(!(o>=i&&o<=s)&&m(e.sig[o],t)&&!c(e.sig[o-1],\".\"))return!0;return!1}var Tr=new Set([\"if\",\"for\",\"while\"]);function Ne(e){let{sig:t,match:n,language:r}=e,i=[];if(r.family===\"go\"||!r.structural)return i;let s=new Set;for(let o=0;o<t.length;o++){let a=t[o];if(a.type!==d.WORD||c(t[o-1],\".\")||c(t[o-1],\"?.\"))continue;let l=a.value;if(c(t[o+1],\":\")||Z(e,o)!==\"block\")continue;let f=-1;if(Tr.has(l)){let k=m(t[o+1],\"await\")&&l===\"for\"?o+2:o+1;if(!c(t[k],\"(\")||n[k]===-1||l===\"while\"&&s.has(o))continue;f=n[k]}if(l===\"else\"){if(m(t[o+1],\"if\"))continue;f=o}if(l===\"do\"&&(f=o),f===-1)continue;let u=f+1,h=t[u];if(!h||c(h,\";\"))continue;let g=c(h,\"{\"),v=g?n[u]:J(e,u);l===\"do\"&&v!==-1&&m(t[v+1],\"while\")&&s.add(v+1),i.push({keyword:l,keywordIndex:o,headerEnd:f,bodyIndex:u,braced:g,endIndex:v})}return i}function Cr(e,t,n){let r=e.sig[t+1];return!r||r.nlBefore>0||r.commentBefore||n===\"do\"&&m(r,\"while\")||m(r,\"else\")&&n!==\"else\"?null:r}function $t(e){if(!e.language.structural||e.language.family===\"go\")return[];let t=[],n=new Set;for(let r of Ne(e)){if(r.braced||r.endIndex===-1)continue;let i=e.sig[r.bodyIndex];if(i.commentBefore)continue;let s=e.sig[r.headerEnd],o=e.sig[r.endIndex],a=[{start:s.end,end:i.start,text:` {\n`},{start:o.end,end:o.end,text:`\n}`,tie:-i.start}];Cr(e,r.endIndex,r.keyword)&&!n.has(o.end)&&(n.add(o.end),a.push({start:o.end,end:o.end,text:`\n`,tie:1e9})),t.push({rule:e.language.name===\"java\"?\"PL-CF-003\":\"PL-JS-001\",start:e.sig[r.keywordIndex].start,end:o.end,edits:a})}return t}function Nr(e,t){let{sig:n,match:r,language:i}=e;if(i.family!==\"go\"){let o=t+1;if(!c(n[o],\"(\")||r[o]===-1)return null;let a=r[o]+1;return!c(n[a],\"{\")||r[a]===-1?null:{open:a,close:r[a],hasInit:!1}}let s=!1;for(let o=t+1;o<n.length;o++){if(c(n[o],\"{\"))return r[o]===-1?null:{open:o,close:r[o],hasInit:s};if(c(n[o],\":=\")&&(s=!0),c(n[o],\"}\"))return null;if(c(n[o],\"(\")||c(n[o],\"[\")){if(r[o]===-1)return null;o=r[o]}}return null}function Dt(e){let{sig:t,match:n,language:r}=e,i=[];if(!r.structural)return i;for(let s=1;s<t.length;s++)!m(t[s],\"else\")||!c(t[s-1],\"}\")||n[s-1]===-1||i.push({elseIndex:s,terminated:Ce(e,n[s-1]),elseIf:m(t[s+1],\"if\")});return i}function Ir(e,t){let n=e.sig[t-1];return n?n.type===\"punct\"&&[\";\",\"{\",\"}\"].includes(n.value):!0}function xr(e,t,n){let r=t;for(;r<n&&` \t\n`.includes(e[r]);)r++;return r}function jr(e,t,n){let r=n;for(;r>t&&` \t\n`.includes(e[r-1]);)r--;return r}function Rr(e,t,n,r){let{names:i,unsure:s}=Rt(e,n,r);if(s)return!1;let o=e.parent[t],a=o===-1?0:o,l=o===-1?e.sig.length-1:e.match[o];for(let f of i)if(Wt(e,f,a,l,n,r)||At(e,f)>1)return!1;return!0}function Ar(e,t,n,r){let{sig:i,text:s,match:o}=e,a=o[r];if(a===-1||i[r].commentBefore)return null;let l=i[a+1];if(l&&l.nlBefore===0&&!l.commentBefore||!Rr(e,t,r,a))return null;let f=i[n.close],u=xr(s,i[r].end,i[a].start),h={start:f.start,end:i[a].end};if(u>=i[a].start)return{...h,edits:[{start:f.end,end:i[a].end,text:\"\"}]};let g=jr(s,u,i[a].start);return{...h,edits:[{start:f.end,end:u,text:`\n\n`},{start:g,end:i[a].end,text:\"\"}]}}function Wr(e,t,n){let{sig:r}=e,i=[],s=t;for(;;){let o=Nr(e,s);if(!o||o.hasInit)return i;let a=o.close+1;if(!m(r[a],\"else\")||r[a].commentBefore||!Ce(e,o.open))return i;let l=a+1;if(m(r[l],\"if\")&&!r[l].commentBefore){i.push({rule:n,start:r[o.close].start,end:r[l].end,edits:[{start:r[o.close].end,end:r[l].start,text:`\n\n`}]}),s=l;continue}if(!c(r[l],\"{\"))return i;let f=Ar(e,s,o,l);return f&&i.push({rule:n,...f}),i}}function Ft(e){let{sig:t,language:n}=e;if(!n.structural)return[];let r=n.name===\"go\"?\"PL-GO-002\":\"PL-CF-002\",i=[];for(let s=0;s<t.length;s++)!m(t[s],\"if\")||m(t[s-1],\"else\")||!Ir(e,s)||Z(e,s)===\"block\"&&i.push(...Wr(e,s,r));return i}var $r=new Set([\"if\",\"else\",\"for\",\"while\",\"do\",\"switch\",\"try\",\"catch\",\"finally\",\"function\",\"class\",\"interface\",\"enum\",\"namespace\",\"module\",\"declare\",\"abstract\",\"async\",\"case\",\"default\",\"with\",\"import\",\"export\",\"const\",\"let\",\"var\",\"return\",\"throw\",\"break\",\"continue\",\"type\",\"static\",\"public\",\"private\",\"protected\",\"readonly\",\"get\",\"set\",\"from\",\"of\",\"in\",\"as\",\"extends\",\"implements\"]),Dr=new Set([\"function\",\"class\",\"abstract\",\"interface\",\"enum\"]);function _t(e){return!!e&&e.type===d.PUNCT&&[\")\",\"]\",\"}\"].includes(e.value)}function Fr(e){return!!e&&e.type===d.PUNCT&&[\"(\",\"[\",\"{\"].includes(e.value)}function _r(e,t){let{sig:n,match:r}=e;if(!c(n[t-1],\":\"))return!1;for(let i=t-2,s=0;i>=0&&s<60;i--,s++){let o=n[i];if(_t(o)&&r[i]!==-1){i=r[i];continue}if(m(o,\"case\")||m(o,\"default\"))return!0;if(c(o,\";\")||c(o,\"{\")||c(o,\"}\"))return!1}return!1}function he(e,t){let{sig:n}=e,r=n[t],i=n[t-1];return r.nlBefore>0&&_(i)&&!X(r)}function Q(e,t,n){let{sig:r}=e,i=r[t-1];return i?i.type===d.PUNCT?[\";\",\"{\"].includes(i.value)?!0:i.value===\"}\"||i.value===\")\"?n||he(e,t):i.value===\":\"?n||_r(e,t):he(e,t):i.type===d.WORD&&(i.value===\"else\"||i.value===\"do\")?!0:he(e,t):!0}function Br(e,t){let{sig:n}=e,r=n[t+1];if(!r)return!1;if(c(r,\"{\")||c(r,\"*\")||c(r,\"=\"))return!0;if(r.type!==d.WORD)return!1;if([\"const\",\"let\",\"var\",\"import\"].includes(r.value))return r.value!==\"const\"||!m(n[t+2],\"enum\");if(r.value===\"default\"){let i=n[t+2];return!i||i.type===d.WORD&&Dr.has(i.value)?!1:!(m(i,\"async\")&&m(n[t+3],\"function\"))}if(r.value===\"type\"){let i=n[t+2];return c(i,\"{\")||c(i,\"*\")?!0:m(i)&&(c(n[t+3],\"=\")||c(n[t+3],\"<\"))}return!1}function Mr(e,t){let{sig:n}=e,r=n[t];if(r.type!==d.WORD||c(n[t-1],\".\")||c(n[t-1],\"?.\"))return null;let i=n[t+1],s=r.value,o=e.parent[t];return o!==-1&&!c(n[o],\"{\")?null:[\"const\",\"let\",\"var\"].includes(s)?!(i&&(i.type===d.WORD||c(i,\"{\")||c(i,\"[\")))||s!==\"var\"&&m(i)&&[\"in\",\"of\",\"instanceof\",\"enum\"].includes(i.value)?null:Q(e,t,!0)?\"keyword\":null:[\"return\",\"throw\",\"break\",\"continue\"].includes(s)?c(i,\":\")||c(i,\"=\")?null:Q(e,t,!0)?\"keyword\":null:s===\"import\"?c(i,\"(\")||c(i,\".\")?null:Q(e,t,!0)?\"keyword\":null:s===\"export\"?Br(e,t)&&Q(e,t,!0)?\"keyword\":null:s===\"type\"?m(i)&&(c(n[t+2],\"=\")||c(n[t+2],\"<\"))&&Q(e,t,!0)?\"keyword\":null:$r.has(s)||c(i,\":\")||c(i,\"=>\")||Z(e,t)!==\"block\"?null:Q(e,t,!1)?\"expression\":null}function Ur(e,t){let{sig:n,match:r}=e,i=t;for(;i<n.length;){if(Fr(n[i])){if(r[i]===-1)return-1;i=r[i]}let s=n[i],o=n[i+1];if(c(o,\";\"))return-1;if(!o||_t(o))return _(s)?i:-1;if(o.nlBefore>0&&_(s)&&!X(o))return i;i++}return-1}function me(e){if(!e.language.semicolons)return[];let t=[],n=new Set;for(let r=0;r<e.sig.length;r++){if(!Mr(e,r))continue;let i=Ur(e,r);if(i===-1||n.has(i))continue;n.add(i);let s=e.sig[i];t.push({rule:\"PL-JS-002\",start:e.sig[r].start,end:s.end,edits:[{start:s.end,end:s.end,text:\";\"}]})}return t}var Jr=new Set([\"if\",\"else\",\"for\",\"while\",\"do\",\"switch\",\"select\",\"try\",\"catch\",\"finally\"]),zr=3;function Gr(e,t){let{sig:n,match:r}=e,i=t;for(let s=t-1;s>=0;s--){let o=n[s];if(c(o,\")\")||c(o,\"]\")){if(r[s]===-1)return n[i];s=r[s],i=s;continue}if(c(o,\";\")||c(o,\"{\")||c(o,\"}\"))return n[i];i=s}return n[i]}function Vr(e){let{src:t}=e,{sig:n,match:r}=t,i=[];for(let s=0;s<n.length;s++){let o=n[s];if(o.type===d.PUNCT){if(o.value===\"{\"&&r[s]!==-1){let a=Gr(t,s),l=a.type===d.WORD&&Jr.has(a.value);i.push(l);let f=i.filter(Boolean).length,u=a.value===\"else\"&&n[a.si+1]?.value===\"if\";l&&f>zr&&!u&&e.report(\"PL-CF-001\",{start:a.start,end:a.end,message:`Control flow is nested ${f} levels deep.`,suggestion:\"Handle the unusual case early and return, throw or continue, so the happy path stays near the base indentation.\",severity:\"warn\"});continue}o.value===\"}\"&&i.pop()}}}function Kr(e){let{src:t}=e,n=t.language.name===\"go\";for(let r of Dt(t)){let i=t.sig[r.elseIndex];if(r.terminated){e.report(n?\"PL-GO-002\":\"PL-CF-002\",{start:i.start,end:i.end,message:\"The branch before this `else` always leaves (return, throw, continue or break).\",suggestion:\"Remove the `else` and continue with the happy path.\",severity:\"warn\"});continue}(!r.elseIf||!n)&&e.report(\"PL-CF-002\",{start:i.start,end:i.end,message:\"Avoid `else`: Pureline prefers guard clauses.\",suggestion:\"Invert the condition, handle that case first and return early.\",severity:\"info\"})}}function Yr(e){let{src:t}=e,n=t.language.name===\"java\"?\"PL-CF-003\":\"PL-JS-001\";for(let r of Ne(t)){if(r.braced)continue;let i=t.sig[r.keywordIndex],s=t.sig[r.headerEnd];e.report(n,{start:i.start,end:s.end,message:`The body of \\`${r.keyword}\\` has no braces.`,suggestion:\"Wrap the body in { } \\u2014 the formatter does it when the end of the statement is certain.\",severity:\"warn\"})}}function Hr(e){let{src:t,config:n}=e;if(!(!t.language.semicolons||n.semicolons===!1))for(let r of me(t)){let i=r.edits[0].start;e.report(\"PL-JS-002\",{start:i-1,end:i,message:\"Missing semicolon.\",suggestion:\"Add `;` at the end of the statement.\",severity:\"warn\"})}}function Xr(e){let{src:t,config:n}=e,r=n.indent?.style===\"tab\"?4:n.indent?.size??4;for(let i of pe(t,n.printWidth??120,r)){let s=t.sig[i.openIndex-1];e.report(\"PL-FMT-001\",{start:s.start,end:i.end,message:`The arguments of \\`${s.value}(...)\\` are spread over lines but fit on one.`,suggestion:\"Put the call on one line, or keep it vertical only when it shows meaningful structure.\",severity:\"info\"})}}function Bt(e){e.src.language.structural&&(Vr(e),Kr(e),Yr(e),Hr(e),Xr(e))}var Zr=new Set([\"=\",\"+=\",\"-=\",\"*=\",\"/=\",\"%=\",\"**=\",\"<<=\",\">>=\",\">>>=\",\"&=\",\"|=\",\"^=\",\"&&=\",\"||=\",\"??=\"]),Qr=new Set([\"java\",\"javax\",\"jakarta\",\"org\",\"com\",\"net\",\"io\"]);function qr(e,t,n){for(let r=0;r<e.length;r++){let i=e[r];if(r===n+1||!m(i,t)||c(e[r-1],\".\"))continue;let s=e[r+1],o=e[r-1];if(s&&s.type===d.PUNCT&&(Zr.has(s.value)||s.value===\"++\"||s.value===\"--\")||o&&o.type===d.PUNCT&&(o.value===\"++\"||o.value===\"--\")||o&&(c(o,\",\")||c(o,\"[\")||c(o,\"{\"))&&s&&(c(s,\",\")||c(s,\"]\")||c(s,\"}\")))return!0;m(o,\"of\")||m(o,\"in\")}return!1}function Ie(e){let{src:t}=e,{sig:n}=t;if(t.language.family===\"js\"){for(let r=0;r<n.length;r++){let i=n[r];m(i,\"var\")&&!c(n[r-1],\".\")&&m(n[r+1])&&e.report(\"PL-JS-003\",{start:i.start,end:i.end,message:\"`var` is not used in Pureline code.\",suggestion:\"Use `const`, or `let` when the variable really is reassigned.\",severity:\"error\"}),m(i,\"let\")&&m(n[r+1])&&c(n[r+2],\"=\")&&!c(n[r-1],\"(\")&&!qr(n,n[r+1].value,r)&&e.report(\"PL-JS-003\",{start:i.start,end:n[r+1].end,message:`\\`${n[r+1].value}\\` is never reassigned.`,suggestion:\"Declare it with `const`; use `let` only for actual reassignment.\",severity:\"warn\"}),c(i,\".\")&&m(n[r+1],\"then\")&&c(n[r+2],\"(\")&&e.report(\"PL-JS-004\",{start:n[r+1].start,end:n[r+1].end,message:\"Promise chain: `async` / `await` usually reads more linearly.\",suggestion:\"Make the surrounding function `async` and `await` the call.\",severity:\"hint\"})}t.language.name===\"typescript\"&&ei(e)}}function ei(e){let{sig:t}=e.src;for(let n=0;n<t.length;n++){let r=t[n];if(m(r,\"any\")&&!c(t[n-1],\".\")){let i=c(t[n-1],\":\")||m(t[n-1],\"as\")||c(t[n-1],\"<\")||c(t[n-1],\",\"),s=c(t[n+1],\">\")||c(t[n+1],\",\")||c(t[n+1],\")\")||c(t[n+1],\";\")||c(t[n+1],\"[\")||c(t[n+1],\"=\")||c(t[n+1],\"|\")||c(t[n+1],\"&\")||!t[n+1];i&&s&&e.report(\"PL-TS-001\",{start:r.start,end:r.end,message:\"`any` switches the type checker off.\",suggestion:\"Use a precise type, or `unknown` for data of an unknown shape.\",severity:\"warn\"})}m(r,\"interface\")&&m(t[n+1])&&/^I[A-Z]/.test(t[n+1].value)&&e.report(\"PL-TS-003\",{start:t[n+1].start,end:t[n+1].end,message:`\\`${t[n+1].value}\\`: the \\`I\\` prefix is a Java convention.`,suggestion:`Call it \\`${t[n+1].value.slice(1)}\\`.`,severity:\"warn\"}),m(r,\"enum\")&&m(t[n+1])&&!c(t[n-1],\".\")&&e.report(\"PL-TS-005\",{start:r.start,end:t[n+1].end,message:\"A union of string literals is often simpler than an enum.\",suggestion:'Consider `type State = \"idle\" | \"ready\"` unless you need the enum object at runtime.',severity:\"hint\"})}}function ti(e){let t=[],n=!0;for(let r=0;r<e.length;r++){let i=e[r];if(n&&(m(i,\"import\")||m(i,\"package\"))){for(;r<e.length&&!c(e[r],\";\");)r++;n=!0;continue}if(n=c(i,\";\")||c(i,\"{\")||c(i,\"}\"),i.type!==d.WORD||!Qr.has(i.value)||c(e[r-1],\".\"))continue;let o=r,a=!1;for(;c(e[o+1],\".\")&&m(e[o+2])&&(o+=2,a=a||/^[A-Z]/.test(e[o].value),!a););a&&o-r>=4&&t.push({from:i,to:e[o]})}return t}function ni(e){let{sig:t}=e.src;for(let n=0;n<t.length-1;n++){if(!m(t[n],\"interface\")||c(t[n-1],\"@\")||!m(t[n+1]))continue;let r=t[n+1];/^I[A-Z]/.test(r.value)||e.report(\"PL-JAVA-002\",{start:r.start,end:r.end,message:`Pureline Java names interfaces with the \\`I\\` prefix: \\`I${r.value}\\`.`,suggestion:`Rename \\`${r.value}\\` to \\`I${r.value}\\`.`,severity:\"hint\"})}}function ri(e){let t=e.map(s=>s.value);if(t[0]!==\"return\")return!1;let n=t.slice(1),r=n.length===2&&n[1]===\";\",i=n.length===4&&n[0]===\"this\"&&n[1]===\".\"&&n[3]===\";\";return r||i}function ii(e){if(e.length%6!==0)return!1;for(let t=0;t<e.length;t+=6){let n=e.slice(t,t+6).map(r=>r.value);if(n[0]!==\"this\"||n[1]!==\".\"||n[3]!==\"=\"||n[5]!==\";\")return!1}return!0}function si(e,t,n,r){let{sig:i,match:s}=e,o=0,a=[],l=n+1;for(;l<r;){let f=i[l];if(c(f,\"@\")){l+=2,c(i[l],\"(\")&&s[l]!==-1&&(l=s[l]+1);continue}if(a.filter(h=>m(h,\"static\")||m(h,\"abstract\")||m(h,\"class\")).length)return!1;if(c(f,\"{\")&&s[l]!==-1){let h=i.slice(l+1,s[l]),g=a.findIndex(S=>c(S,\"(\")),k=(g>0?a[g-1].value:null)===t?ii(h):ri(h);if(g===-1||!k)return!1;a=[],l=s[l]+1;continue}if(c(f,\";\")){if(!!a.some(g=>c(g,\"(\"))||!a.some(g=>m(g,\"final\")))return!1;o++,a=[],l++;continue}a.push(f),l++}return o>0&&a.length===0}function oi(e){let{src:t}=e,{sig:n,match:r}=t;for(let i=0;i<n.length-2;i++){if(!m(n[i],\"class\")||!m(n[i+1])||c(n[i-1],\".\"))continue;let s=i+2;for(;s<n.length&&!c(n[s],\"{\")&&!m(n[s],\"extends\");)s++;!c(n[s],\"{\")||r[s]===-1||si(t,n[i+1].value,s,r[s])&&e.report(\"PL-JAVA-003\",{start:n[i+1].start,end:n[i+1].end,message:`\\`${n[i+1].value}\\` only holds final fields and getters.`,suggestion:\"A `record` states that in one line and generates the boilerplate.\",severity:\"hint\"})}}function Mt(e){let{src:t}=e,{sig:n}=t;if(t.language.name===\"java\"){ni(e),oi(e);for(let r=0;r<n.length-3;r++)m(n[r],\"Objects\")&&c(n[r+1],\".\")&&m(n[r+2],\"requireNonNull\")&&!c(n[r-1],\".\")&&e.report(\"PL-JAVA-004\",{start:n[r].start,end:n[r+2].end,message:\"`Objects.requireNonNull` hides the decision about a missing value.\",suggestion:\"Check `== null` and return, or throw a domain-specific exception.\",severity:\"info\"});for(let r of ti(n))e.report(\"PL-JAVA-005\",{start:r.from.start,end:r.to.end,message:`Fully qualified name \\`${r.to.value}\\` used in code.`,suggestion:`Import ${r.to.value} and use the simple name.`,severity:\"warn\"})}}var je=new Set([\"if\",\"for\",\"while\",\"switch\",\"catch\",\"with\",\"synchronized\",\"return\",\"throw\",\"new\",\"else\",\"do\",\"try\",\"finally\",\"await\",\"typeof\",\"case\",\"in\",\"of\"]),ai=new Set([\"function\",\"async\",\"static\",\"public\",\"private\",\"protected\",\"get\",\"set\",\"abstract\",\"override\",\"export\",\"default\",\"readonly\",\"declare\"]),Ut=new Set([\"public\",\"private\",\"protected\",\"readonly\",\"final\",\"static\",\"override\"]);function zt(e,t){let n=e[t];return c(n,\"=\")&&m(e[t-1])||c(n,\":\")&&m(e[t-1])?e[t-1]:null}function li(e,t){let{sig:n}=e,r=n[t-1];if(c(r,\")\"))return t-1;let i=e.language.family;for(let s=t-1,o=0;s>0&&o<40;s--,o++){let a=n[s];if(a.type===d.PUNCT&&[\";\",\"{\",\"}\",\"=\",\"=>\"].includes(a.value))return-1;if(c(a,\")\")&&(c(n[s+1],\":\")||m(n[s+1],\"throws\"))||i===\"go\"&&c(a,\")\"))return s}return-1}function ci(e,t){let{sig:n}=e,r=n[t-1];return r?m(r,\"function\")?zt(n,t-2):r.type!==d.WORD||je.has(r.value)||m(n[t-2],\"new\")?null:r:null}function ui(e,t){let{sig:n,match:r}=e;for(let i=t-1,s=0;i>=0&&s<80;i--,s++){if(c(n[i],\")\")&&r[i]!==-1){i=r[i];continue}if(m(n[i],\"func\")){let o=i+1;return c(n[o],\"(\")&&r[o]!==-1&&(o=r[o]+1),m(n[o])&&c(n[o+1],\"(\")?n[o]:null}if(c(n[i],\"}\")||c(n[i],\";\"))return null}return null}function fi(e,t){let{sig:n,match:r}=e,i=t-2;c(n[i],\")\")&&r[i]!==-1&&(i=r[i]);let s=i-1;return m(n[s],\"async\")&&s--,zt(n,s)}function Gt(e){let{sig:t,match:n,language:r}=e,i=[];for(let s=0;s<t.length;s++){if(!c(t[s],\"{\")||n[s]===-1)continue;let o=null;if(r.family===\"go\"&&(o=ui(e,s)),r.family!==\"go\"&&c(t[s-1],\"=>\")&&(o=fi(e,s)),r.family!==\"go\"&&!c(t[s-1],\"=>\")){let l=li(e,s);l!==-1&&n[l]!==-1&&(o=ci(e,n[l]))}if(!o)continue;let a=t[n[s]];i.push({name:o.value,nameToken:o,open:s,close:n[s],startLine:o.line,endLine:a.line,lines:a.line-o.line+1})}return i}function Vt(e){let{sig:t,match:n,language:r}=e,i=[];if(r.family===\"go\"||r.family===\"crystal\")return i;for(let s=0;s<t.length-1;s++){if(!m(t[s],\"class\")||c(t[s-1],\".\")||!m(t[s+1]))continue;let o=s+2;for(;o<t.length&&!c(t[o],\"{\")&&!c(t[o],\";\");)o=c(t[o],\"(\")&&n[o]!==-1?n[o]+1:o+1;if(!c(t[o],\"{\")||n[o]===-1)continue;let a=t[n[o]];i.push({name:t[s+1].value,nameToken:t[s+1],open:o,close:n[o],lines:a.line-t[s+1].line+1})}return i}function xe(e,t,n){let{sig:r,match:i}=e,s=[[]],o=0;for(let a=t+1;a<n;a++){let l=r[a];if(c(l,\",\")&&o===0){s.push([]);continue}if(s[s.length-1].push(l),c(l,\"<\")&&o++,c(l,\">\")&&o>0&&o--,c(l,\">>\")&&o>0&&(o=Math.max(0,o-2)),l.type===d.PUNCT&&\"([{\".includes(l.value)&&i[a]!==-1){let f=i[a];for(a+=1;a<=f;a++)s[s.length-1].push(r[a]);a=f}}return s}function Jt(e,t){let n=e.filter(o=>o.type===d.WORD&&!Ut.has(o.value));if(!n.length||e.some(o=>c(o,\"{\")||c(o,\"[\")))return null;if(t===\"js\"){let o=e.findIndex(a=>c(a,\"...\"));return o===-1?n[0]:e[o+1]}let r=e.findIndex(o=>c(o,\"=\")),s=(r===-1?e:e.slice(0,r)).filter(o=>o.type===d.WORD&&!Ut.has(o.value));return s.length<2&&e.length>1?null:s[s.length-1]??null}function Kt(e){let{sig:t,match:n,language:r}=e,i=[],s=r.family,o=(a,l)=>{a&&a.type===d.WORD&&i.push({name:a.value,token:a,kind:l})};for(let a=0;a<t.length;a++){let l=t[a];if(s===\"js\"&&l.type===d.WORD&&[\"const\",\"let\",\"var\"].includes(l.value)&&!c(t[a-1],\".\")){let p=c(t[a-1],\"(\")&&m(t[a-2],\"for\");o(m(t[a+1])?t[a+1]:null,p?\"loop\":\"variable\")}if(s===\"go\"&&c(l,\":=\"))for(let p of de(t,a))o(p,\"variable\");if(s===\"go\"&&m(l,\"var\")&&m(t[a+1])&&o(t[a+1],\"variable\"),!c(l,\"(\")||n[a]===-1)continue;let f=n[a],u=t[a-1],h=t[f+1],g=m(u,\"catch\"),v=m(u,\"for\"),k=t[a-2],S=c(h,\":\")&&s===\"js\"&&u?.type===d.WORD&&(!k||[\";\",\"{\",\"}\"].includes(k.value)||k.type===d.WORD&&ai.has(k.value)),L=!!h&&(c(h,\"=>\")||c(h,\"->\")),O=L||S||!!h&&(c(h,\"{\")||m(h,\"throws\"));if(s===\"go\")continue;if(v&&s===\"java\"){let p=xe(e,a,f)[0]??[],y=p.findIndex(w=>c(w,\":\"));y>0&&p[y-1].type===d.WORD&&o(p[y-1],\"loop\");continue}if(g){for(let p of xe(e,a,f))o(Jt(p,s),\"catch\");continue}let T=u&&u.type===d.WORD&&je.has(u.value);if(!(!O||T)&&!(c(h,\"{\")&&!(u&&(u.type===d.WORD||c(u,\">\")))))for(let p of xe(e,a,f))o(Jt(p,s),L?\"lambda\":\"parameter\")}if(s===\"js\"&&t.forEach((a,l)=>{c(a,\"=>\")&&m(t[l-1])&&!c(t[l-2],\".\")&&o(t[l-1],\"lambda\")}),s===\"java\")for(let a=1;a<t.length-1;a++)m(t[a])&&m(t[a-1])&&c(t[a+1],\"=\")&&!je.has(t[a-1].value)&&o(t[a],\"variable\");return i}var di=30,Yt=50,Ht=200,pi=new Set([\"handleeverything\",\"process\",\"dostuff\",\"executeall\",\"handleall\",\"dothings\"]),hi=new Set([\"tmp\",\"temp\",\"obj\",\"thing\",\"stuff\"]),mi=new Set([\"i\",\"j\",\"k\"]),gi=new Set([\"ctx\",\"err\",\"wg\",\"tx\",\"conn\",\"ok\",\"n\",\"w\",\"r\",\"t\",\"b\",\"db\",\"mu\",\"id\"]);function yi(e,t){let{name:n,kind:r}=e;return n===\"_\"||n===\"$\"?!0:n.length>1?!hi.has(n)&&!/^(?:data|value|result|item)\\d+$/i.test(n):mi.has(n)||n===\"e\"&&r===\"catch\"?!0:t===\"go\"&&gi.has(n)}function Xt(e){let{src:t}=e;if(t.language.family!==\"crystal\")for(let n of Kt(t))yi(n,t.language.name)||e.report(\"PL-NAME-001\",{start:n.token.start,end:n.token.end,message:`\\`${n.name}\\` does not say what it holds.`,suggestion:\"Name it after its role \\u2014 as short as possible, as explicit as necessary. Loop counters (i, j, k) are fine.\",severity:n.kind===\"lambda\"?\"info\":\"warn\"})}function Re(e){for(let t of Gt(e.src)){let n=t.nameToken;if(pi.has(t.name.toLowerCase())&&e.report(\"PL-FN-001\",{start:n.start,end:n.end,message:`\\`${t.name}\\` is a vague name for a function.`,suggestion:\"Name the one action it performs, like validateRequest() or sendPacket().\",severity:\"warn\"}),t.lines>Yt){e.report(\"PL-FN-001\",{start:n.start,end:n.end,message:`\\`${t.name}\\` is ${t.lines} lines long; functions over ${Yt} lines are usually split.`,suggestion:\"Extract the steps into functions that each do one clearly named thing.\",severity:\"warn\"});continue}t.lines>di&&e.report(\"PL-FN-001\",{start:n.start,end:n.end,message:`\\`${t.name}\\` is ${t.lines} lines long; worth a review.`,suggestion:\"Functions of about 30 to 50 lines are worth a look: does it do one thing?\",severity:\"info\"})}}function Ae(e){for(let t of Vt(e.src))t.lines<=Ht||e.report(\"PL-STRUCT-001\",{start:t.nameToken.start,end:t.nameToken.end,message:`\\`${t.name}\\` is ${t.lines} lines long; classes above roughly ${Ht} lines should be reviewed for several responsibilities.`,suggestion:\"Look for groups of members that belong together and move them into their own type.\",severity:\"info\"})}var Zt=/<<-([\"']?)([A-Za-z_][A-Za-z0-9_]*)\\1/g,vi={\"(\":\")\",\"[\":\"]\",\"{\":\"}\",\"<\":\">\",\"|\":\"|\"};function wi(e,t){let n=1,r=t;for(;r<e.length&&n>0;){if(e[r]===\"{\"&&n++,e[r]===\"}\"&&n--,e[r]==='\"'){r=Qt(e,r);continue}r++}return r}function Qt(e,t){let n=t+1;for(;n<e.length;){if(e[n]===\"\\\\\"){n+=2;continue}if(e[n]===\"#\"&&e[n+1]===\"{\"){n=wi(e,n+2);continue}if(e[n]==='\"')return n+1;n++}return e.length}function bi(e,t){let n=e[t+1]&&\"qQwWiIr\".includes(e[t+1])?e[t+2]:e[t+1],r=vi[n];if(!r)return-1;let i=t+(e[t+1]&&\"qQwWiIr\".includes(e[t+1])?3:2),s=1;for(let o=i;o<e.length;o++){if(e[o]===\"\\\\\"){o++;continue}if(n!==r&&e[o]===n&&s++,e[o]===r&&s--,s===0)return o+1}return e.length}function ki(e,t,n,r,i){let s=t;for(let o of n){let a=s;for(;s<e.length&&e[s].trim()!==o;)s++;let l=Math.min(s,e.length-1);for(let f=a;f<=l;f++)r.add(f),f<l&&i.add(f);s=l+1}return s}function qt(e){let t=[0];for(let f=e.indexOf(`\n`);f!==-1;f=e.indexOf(`\n`,f+1))t.push(f+1);let n=f=>{let u=0,h=t.length-1;for(;u<h;){let g=u+h+1>>1;if(t[g]<=f){u=g;continue}h=g-1}return u},r=new Set,i=new Set,s=(f,u)=>{let h=n(f),g=n(Math.max(f,u-1));for(let v=h+1;v<=g;v++)r.add(v);for(let v=h;v<g;v++)i.add(v)},o=e.split(`\n`),a=[],l=0;for(;l<e.length;){let f=e[l];if(f===`\n`){let u=n(l);if(a.length){let h=ki(o,u+1,a.splice(0),r,i);l=h<o.length?t[h]:e.length;continue}l++;continue}if(f===\"#\"){let u=e.indexOf(`\n`,l);l=u===-1?e.length:u;continue}if(f==='\"'){let u=Qt(e,l);s(l,u),l=u;continue}if(f===\"<\"&&e[l+1]===\"<\"){Zt.lastIndex=l;let u=Zt.exec(e);if(u&&u.index===l){a.push(u[2]),l+=u[0].length;continue}}if(f===\"%\"&&/[\\s(,=[]/.test(e[l-1]??\" \")){let u=bi(e,l);if(u!==-1){s(l,u),l=u;continue}}l++}return{startsInside:r,endsInside:i}}function en(e,t){let{startsInside:n,endsInside:r}=qt(e),i=[],s=0;return e.split(`\n`).forEach((o,a)=>{if(n.has(a)){s=0,i.push({text:t.trim&&!r.has(a)?o.trimEnd():o});return}if(o.trim()===\"\"){s++,i.push({text:t.collapse&&s>1?null:\"\"});return}s=0,i.push({text:t.trim&&!r.has(a)?o.trimEnd():o})}),i}var Si=/^(?:(?:private|protected|abstract)\\s+)*(?:class|module|struct|enum|lib|annotation|macro|while|until|begin|union)\\b/,Oi=/\\bdo(?:\\s*\\|[^|]*\\|)?\\s*$/,Pi=/^(?:(?:private|protected)\\s+)?def\\s+([A-Za-z_][\\w?!=]*(?:\\.[\\w?!=]+)?)/,Li=/^(?:(?:private|protected|abstract)\\s+)*(class|module|struct)\\s+([A-Z][\\w:]*)/;function tn(e){let{startsInside:t}=qt(e),n=[],r=[],i=[];return e.split(`\n`).forEach((s,o)=>{if(t.has(o))return;let l=s.replace(/#.*$/,\"\").trim();if(!l)return;let f=s.indexOf(l);/^(?:if|unless)\\b/.test(l)&&!/\\bend\\s*$/.test(l)&&i.push({kind:\"if\"}),/^case\\b/.test(l)&&i.push({kind:\"case\"});let u=Li.exec(l);u&&!/\\bend\\s*$/.test(l)&&i.push({kind:u[1],name:u[2],line:o,column:s.indexOf(u[2])}),!u&&Si.test(l)&&i.push({kind:\"other\"});let h=Pi.exec(l),g=/^[^(]*(?:\\([^)]*\\))?\\s*=\\s/.test(l.replace(/^(?:(?:private|protected)\\s+)?def\\s+/,\"\"));if(h&&!g&&i.push({kind:\"def\",name:h[1],line:o,column:s.indexOf(h[1])}),!h&&Oi.test(l)&&!/^(?:if|unless|case|while|until)\\b/.test(l)&&i.push({kind:\"other\"}),/^(?:else|elsif)\\b/.test(l)&&i[i.length-1]?.kind===\"if\"&&n.push({line:o,column:f,length:l.startsWith(\"elsif\")?5:4}),/^end\\b/.test(l)){let v=i.pop();v?.name&&r.push({...v,endLine:o,lines:o-v.line+1})}}),{elses:n,blocks:r}}var Ei={java:\"java\",javascript:\"javascript\",javascriptreact:\"javascript\",jsx:\"javascript\",typescript:\"typescript\",typescriptreact:\"typescript\",tsx:\"typescript\",go:\"go\",golang:\"go\",crystal:\"crystal\",kotlin:\"kotlin\"},Ti={\".js\":\"javascript\",\".mjs\":\"javascript\",\".cjs\":\"javascript\",\".jsx\":\"javascript\",\".ts\":\"typescript\",\".mts\":\"typescript\",\".cts\":\"typescript\",\".tsx\":\"typescript\",\".java\":\"java\",\".kt\":\"kotlin\",\".kts\":\"kotlin\",\".go\":\"go\",\".cr\":\"crystal\"},Ci=new Set([\"javascriptreact\",\"typescriptreact\",\"jsx\",\"tsx\"]),Ni=new Set([\".jsx\",\".tsx\"]),Ii={java:{name:\"java\",family:\"java\",structural:!0,semicolons:!1,indentDefault:4},javascript:{name:\"javascript\",family:\"js\",structural:!0,semicolons:!0,indentDefault:4},typescript:{name:\"typescript\",family:\"js\",structural:!0,semicolons:!0,indentDefault:4},go:{name:\"go\",family:\"go\",structural:!0,semicolons:!1,indentDefault:\"tab\"},kotlin:{name:\"kotlin\",family:\"kotlin\",structural:!1,semicolons:!1,indentDefault:4},crystal:{name:\"crystal\",family:\"crystal\",structural:!1,semicolons:!1,indentDefault:2}};function nn(e){let t=String(e??\"\").split(/[\\\\/]/).pop()??\"\",n=t.lastIndexOf(\".\");return n<=0?\"\":t.slice(n).toLowerCase()}function F({path:e=null,languageId:t=null}={}){let n=nn(e),r=Ei[String(t??\"\").toLowerCase()]??Ti[n];if(!r)return null;let i=Ci.has(String(t??\"\").toLowerCase())||Ni.has(n);return{...Ii[r],jsx:i}}var xi=new Set([\".js\",\".jsx\",\".ts\",\".tsx\",\".mjs\",\".cjs\",\".mts\",\".cts\",\".json\",\".jsonc\",\".json5\",\".css\",\".scss\",\".less\",\".html\",\".vue\",\".md\",\".markdown\",\".mdx\",\".yaml\",\".yml\",\".graphql\",\".gql\",\".hbs\",\".handlebars\"]);function rn(e){return xi.has(nn(e))}var ji=new Set([\"(\",\"=\",\"=>\",\"?\",\":\",\"&&\",\"||\",\",\",\"[\",\"{\",\"??\"]);function ge(e){if(e.language.name!==\"javascript\")return!1;let{sig:t,text:n}=e;for(let r=0;r<t.length-1;r++){if(!c(t[r],\"<\"))continue;let i=t[r-1],s=!i||i.type===d.PUNCT&&ji.has(i.value)||i.type===d.WORD&&i.value===\"return\",o=t[r+1],a=o.type===d.WORD&&o.start===t[r].end,l=c(o,\">\")&&o.start===t[r].end;if(s&&(a||l)&&/<\\/|\\/>/.test(n.slice(t[r].start)))return!0}return!1}var Ri=[Bt,Xt,Re,Ae,Ie,Mt],Ai=[Re,Ae,Ie];function Wi(e,t,n){let r=H(e),i=Oe({language:t,lineStarts:r},n),{elses:s,blocks:o}=tn(e),a=(l,f)=>r[l]+f;for(let l of s)i.report(\"PL-CR-002\",{start:a(l.line,l.column),end:a(l.line,l.column+l.length),message:\"Avoid `else`: Pureline prefers a guard that returns early.\",suggestion:\"Handle the unusual case first (`return` or `return if ...`) and keep the happy path flat.\",severity:\"info\"});for(let l of o){let f=[\"class\",\"module\",\"struct\"].includes(l.kind),u=f?200:50;l.lines<=u||i.report(f?\"PL-STRUCT-001\":\"PL-FN-001\",{start:a(l.line,l.column),end:a(l.line,l.column+l.name.length),message:`\\`${l.name}\\` is ${l.lines} lines long.`,suggestion:f?\"Classes above roughly 200 lines should be reviewed for several responsibilities.\":\"Functions over 50 lines are usually split.\",severity:f?\"info\":\"warn\"})}return e.split(`\n`).forEach((l,f)=>{let u=/^\\s*#(?!\\{)(.*)$/.exec(l);!u||!ke(`#${u[1]}`)||i.report(\"PL-DOC-001\",{start:a(f,l.indexOf(\"#\")),end:a(f,l.length),message:\"This comment restates what the code already says.\",suggestion:\"Say why something unusual is necessary, or delete the comment.\",severity:\"hint\"})}),i.diagnostics}function on(e,t,n){let r=F({languageId:t});if(!r||r.name===\"kotlin\")return[];let i=String(e).replace(/\\r\\n/g,`\n`);if(r.family===\"crystal\")return sn(Wi(i,r,n));let s=M(i,r),o=Oe(s,n);if(Pt(o),s.balanced){let a=r.jsx||ge(s);for(let l of a?Ai:Ri)try{l(o)}catch{}}return sn(o.diagnostics)}function sn(e){return e.sort((t,n)=>t.line-n.line||t.column-n.column)}function $i(e){return e.text.length-(e.end-e.start)}function Di(e,t){if(e.start===e.end||t.start===t.end){let n=e.start===e.end?e:t,r=n===e?t:e;return r.start<n.start&&n.start<r.end}return e.start<t.end&&t.start<e.end}function Fi(e){return[...e].sort((t,n)=>t.start-n.start||t.end-n.end||(t.tie??0)-(n.tie??0))}function _i(e){let t=[];for(let n of e)t.some(i=>i.edits.some(s=>n.edits.some(o=>Di(s,o))))||t.push(n);return t}function Bi(e,t){let n=_i(t),r=Fi(n.flatMap(a=>a.edits)),i=\"\",s=0;for(let a of r)i+=e.slice(s,a.start)+a.text,s=a.end;return i+=e.slice(s),{text:i,applied:n,map:(a,l=\"left\")=>{let f=0;for(let u of r){let h=u.start===u.end;if(u.end<a||u.end===a&&(!h||l===\"right\")){f+=$i(u);continue}if(u.start>=a)break;return u.start+f+(l===\"right\"?u.text.length:0)}return a+f}}}function Mi(e,t){return t?t.from===t.to?e.start<=t.from&&t.from<=e.end:e.start<t.to&&t.from<e.end:!0}function We(e,t,n){let r=t.filter(o=>Mi(o,n));if(!r.length)return{text:e,range:n,count:0};let i=n;n&&(i={from:Math.min(n.from,...r.map(o=>o.start)),to:Math.max(n.to,...r.map(o=>o.end))});let s=Bi(e,r);return i?{text:s.text,range:{from:s.map(i.from,\"left\"),to:s.map(i.to,\"right\")},count:s.applied.length}:{text:s.text,range:null,count:s.applied.length}}var Ui=new Set([\".\",\"?.\",\"+\",\"-\",\"*\",\"/\",\"%\",\"&&\",\"||\",\"??\",\"?\",\":\",\"=\",\"==\",\"===\",\"!=\",\"!==\",\"<=\",\">=\",\"&\",\"|\",\"^\",\"->\",\"=>\",\"**\"]),Ji=new Set([\"*\",\"&\",\"<-\"]),zi=new Set([\"+\",\"-\",\"*\",\"/\",\"%\",\"&&\",\"||\",\"??\",\"?\",\":\",\"=>\",\"->\",\".\",\"?.\",\"&\",\"|\",\"^\",\"**\",\"<<\",\">>\"]);function $e(e){return e.type===d.PUNCT&&(e.value===\")\"||e.value===\"]\"||e.value===\"}\")}function Gi(e){return e.type===d.PUNCT&&(e.value===\"(\"||e.value===\"[\"||e.value===\"{\")}function Vi(e){let t=new Map;for(let n of e.tokens)n.type===d.WS||n.type===d.NEWLINE||(t.has(n.line)||t.set(n.line,[]),t.get(n.line).push(n));return t}function Ki(e){return!e||e.type!==d.PUNCT?!1:zi.has(e.value)||e.value.endsWith(\"=\")}function an(e,t){if(t.type!==d.WORD)return!1;if(t.value===\"case\")return!0;if(t.value!==\"default\")return!1;let n=e.sig[t.si+1];return c(n,\":\")||c(n,\"->\")}function Yi(e,t,n){let{sig:r,match:i,language:s}=e,o=r[t.si-1];if(s.family!==\"go\"){if(!c(o,\")\")||i[t.si-1]===-1)return!1;let l=r[i[t.si-1]-1];return!!l&&l.type===d.WORD&&l.value===\"switch\"}let a=(n.get(t.line)??[]).find(l=>l.type!==d.COMMENT);return!!a&&a.type===d.WORD&&(a.value===\"switch\"||a.value===\"select\")}function Hi(e,t){if(!t||e.language.family===\"go\")return!1;if(t.type===d.WORD)return t.value===\"else\"||t.value===\"do\";if(!c(t,\")\")||e.match[t.si]===-1)return!1;let n=e.match[t.si],r=e.sig[n-1];return!r||r.type!==d.WORD||![\"if\",\"for\",\"while\"].includes(r.value)?!1:!(r.value===\"while\"&&c(e.sig[n-2],\"}\"))}function Xi(e,t,n,r){return t.type===d.WORD&&t.value===\"instanceof\"?!0:Hi(e,n)?!c(t,\"{\"):t.type===d.PUNCT&&Ui.has(t.value)?!(e.language.family===\"go\"&&Ji.has(t.value)):Ki(n)?n.value===\":\"?!(r&&r.type===d.WORD&&(r.value===\"case\"||r.value===\"default\")):!0:!1}function Zi(e){return e.type===d.PUNCT&&(e.value===\"?\"||e.value===\":\")}function re(e){return e.filter(t=>t.type!==d.COMMENT)}function ln(e){let t=re(e);return t.length===2&&t[0].type===d.WORD&&![\"case\",\"default\"].includes(t[0].value)&&c(t[1],\":\")}function Qi(e,t,n,{level:r,kind:i,line:s,go:o,byLine:a}){let l=n.value===\"{\"&&Yi(e,n,a)?\"switch\":\"plain\",f=n.value===\"{\"&&t.lastClosed&&t.lastClosed.line<s&&c(e.sig[n.si-1],\")\"),u=o&&n.value===\"{\"&&i!==\"normal\",h=r;return f&&(h=t.lastClosed.open),u&&(h=t.statementLevel),{open:h,content:h+1,kind:l,inCase:!1,line:s}}function qi(e,t,n,r){let i=new Array(t).fill(null),s=[],o=e.language.family===\"go\",a={previousLast:null,previousFirst:null,previous:null,previousLabel:!1,lastClosed:null,statementLevel:0,labelLevel:null,afterLabel:!1},l=g=>{for(let v=g;v<t;v++){let k=r.get(v);if(!(!k?.length||n.has(v))&&!(k[0].type===d.COMMENT&&!re(k).length))return k[0].type===d.COMMENT?null:k[0]}return null},f=g=>a.previousLabel?!1:Xi(e,g,a.previousLast,a.previousFirst),u=(g,v,k)=>{let S=l(k+1),L=g?.kind===\"switch\",O=L&&S&&an(e,S),T=L&&!O&&g.inCase&&!o?v+1:v;return O&&o&&(T=g.open),S&&!$e(S)&&!L&&f(S)?v+1:T},h=(g,v,k,S)=>{if($e(k))return{level:g?g.open:0,kind:\"normal\"};let L=g?.kind===\"switch\";if(L&&an(e,k)){g.inCase=!0;let p=o?g.open:v,y=[\":\",\"->\"].includes(re(S).at(-1).value);return a.labelLevel=y?null:p,a.afterLabel=y,{level:p,kind:\"normal\"}}if(a.labelLevel!==null){let p=a.labelLevel+1,y=re(S).at(-1).value===\":\";return a.labelLevel=y?null:a.labelLevel,a.afterLabel=y,{level:p,kind:\"normal\"}}let O=v;if(L&&g.inCase&&!o&&(O=v+1),o&&ln(S))return{level:Math.max(O-1,0),kind:\"normal\"};if(!f(k))return{level:O,kind:\"normal\"};let T=Zi(k);return O+=1,T&&a.previous?.kind===\"continuation\"&&(O=a.previous.level+1),T&&a.previous?.kind===\"ternary\"&&(O=a.previous.level),{level:O,kind:T?\"ternary\":\"continuation\"}};for(let g=0;g<t;g++){let v=r.get(g)??[],k=s[s.length-1],S=k?k.content:0,L=n.has(g)?null:v[0],O=S,T=\"normal\";L&&L.type===d.COMMENT&&(O=u(k,S,g)),L&&L.type!==d.COMMENT&&({level:O,kind:T}=h(k,S,L,v)),i[g]=n.has(g)?null:O,T===\"normal\"&&(a.statementLevel=O);for(let y of v)Gi(y)&&s.push(Qi(e,a,y,{level:O,kind:T,line:g,go:o,byLine:r})),$e(y)&&(a.lastClosed=s.pop()??null);let p=re(v);p.length&&(a.previousLast=p[p.length-1],a.previousFirst=p[0],a.previous={kind:T,level:O},a.previousLabel=ln(v)||a.afterLabel,a.afterLabel=!1)}return i}function cn(e){return/^[ \\t]*/.exec(e)[0]}function es(e,t,n,r){let i=e.trimStart();if(i===\"\")return\"\";if(r&&i.startsWith(\"*\"))return`${t} ${i}`.trimEnd();let s=e.startsWith(n)?e.slice(n.length):i;return`${t}${s}`.trimEnd()}function ts(e,t){let n=new Map;for(let[r,i]of Ct(e)){let s=i.value.split(`\n`).length-1,o=t.slice(r+1,r+s+1).map(l=>l.trim()).filter(Boolean),a=o.length>0&&o.every(l=>l.startsWith(\"*\"));for(let l=1;l<=s;l++)n.set(r+l,{start:r,javadoc:a})}return n}function un(e,t,n){let r=e.split(`\n`),i=M(e,t),{startsInside:s,endsInside:o}=Tt(i),a=Vi(i),l=ts(i,r),f=n.indent&&i.balanced?qi(i,r.length,s,a):null,u=new Array(r.length).fill(null),h=[],g=0;return r.forEach((v,k)=>{let S=y=>n.trim&&!o.has(k)?y.trimEnd():y;if(s.has(k)){g=0,h.push({text:S(v)});return}let L=l.get(k);if(L){g=0;let y=u[L.start],w=cn(r[L.start]),P=y===null?S(v):es(v,y,w,L.javadoc);h.push({text:P});return}if(v.trim()===\"\"){g++;let y=n.collapse&&g>1;h.push({text:y?null:\"\"});return}g=0;let T=f?f[k]:null,p=T===null?cn(v):n.unit.repeat(T);u[k]=T===null?null:p,h.push({text:S(`${p}${v.trimStart()}`)})}),h}var ns=5;function rs(e){let t=(e.match(/\\r\\n/g)??[]).length,n=(e.match(/\\n/g)??[]).length-t;return t>n?\"crlf\":\"lf\"}function fn(e,t){return t-(e.slice(0,t).match(/\\r\\n/g)??[]).length}function is(e,t){let n=[];V(t,\"PL-CF-003\")&&V(t,e.name===\"java\"?\"PL-CF-003\":\"PL-JS-001\")&&n.push($t);let i=e.name===\"go\"?\"PL-GO-002\":\"PL-CF-002\";return V(t,i)&&n.push(Ft),e.semicolons&&t.semicolons&&V(t,\"PL-JS-002\")&&n.push(me),n}function dn(e,t){let n=H(e),r=fe(n,t.from),i=t.to>t.from&&e[t.to-1]===`\n`?t.to-1:t.to;return{from:r,to:Math.max(r,fe(n,i))}}function ss(e,t){let n=H(e),r=Math.min(t.to,n.length-1),i=r+1<n.length?n[r+1]-1:e.length;return{from:n[Math.min(t.from,n.length-1)],to:i}}function pn(e,t,n,r,i){let s={unit:tt(n),indent:i&&t.family!==\"crystal\",trim:n.trimTrailingWhitespace,collapse:!0},o=t.family===\"crystal\"?en(e,s):un(e,t,s),a=e.split(`\n`),l=[],f=null,u=null;return o.forEach((h,g)=>{let k=!r||g>=r.from&&g<=r.to?h.text:a[g];g===r?.from&&(f=l.length),k!==null&&l.push(k),g===r?.to&&(u=Math.max(l.length-1,f??0))}),{text:l.join(`\n`),lines:r?{from:f,to:u}:null}}function os(e,t){if(!t.finalNewline)return e;let n=e.replace(/\\n+$/,\"\");return n.trim()===\"\"?\"\":`${n}\n`}function hn(e,t,n,r,i){let s=e,o=r,a=M(s,t),l=t.jsx||ge(a),f=t.family!==\"crystal\"&&a.balanced&&!l;if(t.family!==\"crystal\"&&!a.balanced&&i.add(\"Brackets do not balance \\u2014 only whitespace was fixed.\"),l&&i.add(\"JSX detected \\u2014 only whitespace was fixed (structural Pureline fixes skip JSX files).\"),f&&t.structural)for(let v of is(t,n)){let k=M(s,t);if(!k.balanced)break;let S=We(s,v(k),o);s=S.text,o=S.range}let u=o?dn(s,o):null,h=pn(s,t,n,u,f);if(s=h.text,u=h.lines,f&&t.structural&&V(n,\"PL-FMT-001\")){let v=M(s,t),k=n.indent.style===\"tab\"?4:n.indent.size,S=pe(v,n.printWidth,k),L=u?ss(s,u):null,O=We(s,S,L);s=O.text,O.count>0&&(u=O.range?dn(s,O.range):null,h=pn(s,t,n,u,f),s=h.text,u=h.lines)}return{text:s,lines:u}}function mn(e,t,n,r={}){let i=new Set,s=F({languageId:t,path:r.path??null});if(!s)return{text:e,notes:[`Pureline does not handle the language \"${t}\".`]};let o=rs(e),a=e.replace(/\\r\\n/g,`\n`),l=r.range?{from:fn(e,r.range.from),to:fn(e,r.range.to)}:null;if(l){let h=hn(a,s,n,l,i),g=o===\"crlf\"?`\\r\n`:`\n`;return{text:h.text.replace(/\\n/g,g),notes:[...i]}}for(let h=0;h<ns;h++){let g=hn(a,s,n,null,h===0?i:new Set).text;if(g===a)break;a=g}a=os(a,n);let u=(n.endOfLine===\"keep\"?o:n.endOfLine)===\"crlf\"?`\\r\n`:`\n`;return{text:u===`\n`?a:a.replace(/\\n/g,u),notes:[...i]}}import as from\"node:fs/promises\";import gn from\"node:path\";var ls=3e4,cs=3e4;async function yn(e){try{return(await as.stat(e)).isFile()}catch{return!1}}async function wn(e,{filePath:t,folder:n,setting:r,stop:i}){let s=String(r??\"\").trim();if(s&&await yn(s))return{bin:s,source:\"setting\"};let o=e.platform===\"win32\"?\"prettier.cmd\":\"prettier\";for(let a of te(n??gn.dirname(t??\"/\"),i)){let l=gn.join(a,\"node_modules\",\".bin\",o);if(await yn(l))return{bin:l,source:\"local\"}}return await us(e,\"prettier\")?{bin:\"prettier\",source:\"path\"}:null}async function us(e,t){return await Fe(e,t)!==null}var De=new WeakMap;function bn(e){return De.has(e)||De.set(e,new Map),De.get(e)}async function Fe(e,t){let n=bn(e),r=n.get(t);if(r&&(r.version!==null||Date.now()-r.at<cs))return r.version;let i=null;try{let s=await e.exec(t,[\"--version\"],{timeoutMs:1e4});s.code===0&&(i=s.stdout.trim().split(/\\s+/)[0]||null)}catch{i=null}return n.set(t,{version:i,at:Date.now()}),i}function kn(e){bn(e).clear()}function vn(e){return String(e).split(`\n`).map(t=>t.trim()).find(Boolean)??\"\"}async function Sn(e,{bin:t,filePath:n,folder:r,text:i,range:s}){let o=[\"--stdin-filepath\",n];s&&o.push(\"--range-start\",String(s.from),\"--range-end\",String(s.to));let a;try{a=await e.exec(t,o,{cwd:r,input:i,timeoutMs:ls})}catch(l){return{text:null,note:`Prettier could not be started: ${l.message}`}}return a.timedOut?{text:null,note:\"Prettier took too long and was stopped.\"}:a.code!==0?{text:null,note:`Prettier failed (exit ${a.code}): ${vn(a.stderr)||\"no message\"}`}:a.stderr.trim()?{text:null,note:`Prettier reported: ${vn(a.stderr)}`}:{text:a.stdout}}var ds=\"1.1\",ps=new Set([\"javascript\",\"javascriptreact\",\"typescript\",\"typescriptreact\",\"json\",\"jsonc\",\"json5\",\"css\",\"scss\",\"less\",\"html\",\"vue\",\"markdown\",\"mdx\",\"yaml\",\"graphql\",\"handlebars\"]),hs=new Set([\"auto\",\"pureline\",\"prettier\"]),ms=1500,gs='A Prettier config was found but Prettier is not installed (set \"prettierPath\", run `npm i -D prettier` or install it globally) \\u2014 Pureline formats instead.';async function ys(e){try{return await fs.readFile(e,\"utf8\")}catch{return null}}function On(e){return e.split(U.sep).join(\"/\")}function vs(e,t){return e.split(/[\\\\/]/).includes(\"node_modules\")?!0:!t||!ue(t.folder,e)?!1:dt(t.entries,On(U.relative(t.folder,e)))}function Pn(e,t){let n=new Set,r=()=>t()??{},i=new Map,s=new Map;function o(p){e.log?.(p);let y=i.get(p)??0;Date.now()-y<6e4||(i.set(p,Date.now()),e.ui?.notify?.(p,\"warning\"))}async function a(p,y){if(!p?.prettier)return{options:{},parsed:null};let{file:w,name:P,packageJson:I}=p.prettier,D=await ys(w),x=le(P,D??\"\",I),E=On(U.relative(U.dirname(w),y));return{options:ct(x,E),parsed:x}}async function l(p,y,w){let P=y?await gt(y,w):{config:{},files:[],notes:[]};return{engine:\"pureline\",source:y?\".pureline\":\"defaults\",partial:P.config,chain:P,ignored:yt(P.files,p.path),notes:[...P.notes]}}async function f(p,y,w,P,I){let{options:D,parsed:x}=await a(y,p.path),E=await vt(w,P),N=vs(p.path,E),j=await wn(e,{filePath:p.path,folder:w,setting:r().prettierPath,stop:P}),R={configFile:y?.prettier?.file??null,options:D,parsed:x,ignoreFile:E?.folder??null,ignored:N,folder:w};return j?{engine:\"prettier\",binary:j,version:await Fe(e,j.bin),notes:[],...R}:u(I,R)}function u(p,y){return p?{engine:\"pureline\",source:\"prettier-fallback\",partial:ut(y.options),chain:{config:{},files:[],notes:[]},ignored:y.ignored,notes:[],fallbackNote:gs,configFile:y.configFile}:null}async function h(p,y){let w=F(p),P=String(p.languageId??\"\").toLowerCase(),I=!!p.path&&(rn(p.path)||ps.has(P));if(!w&&!I)return null;let D=String(r().engine??\"auto\"),x=hs.has(D)?D:\"auto\",E=p.path?U.dirname(p.path):y,N=mt(p.path,y)??(p.path?null:y),j=A=>A?{...A,language:w}:null;if(!E)return w?j(await l(p,null,null)):null;if(x===\"prettier\"&&I){let A=await ne(E,N,\"prettier\");return j(await f(p,A,E,N,w))}if(!w){if(x===\"pureline\")return null;let A=await ne(E,N,\"prettier\");return A?j(await f(p,A,E,N,null)):null}if(x===\"pureline\"){let A=await ne(E,N,\"pureline\");return j(await l(p,A?.folder??null,N))}let R=await ne(E,N,I?\"auto\":\"pureline\");return R?R.pureline?j(await l(p,R.folder,N)):j(await f(p,R,E,N,w)):j(await l(p,null,N))}function g(p,y){let w=r(),P=[p.path,p.languageId,y,w.engine,w.prettierPath].join(\"\\0\"),I=s.get(P);if(I&&Date.now()-I.at<ms)return I.promise;let D=h(p,y).catch(x=>(e.log?.(`Could not choose an engine: ${x.message}`),null));return s.set(P,{at:Date.now(),promise:D}),s.size>200&&s.clear(),D}function v(p,y){let w=nt(p.language.name,y,r());return et(p.partial,p.language.name,w)}function k(p){return p.engine===\"prettier\"?p.version?`Prettier ${p.version}`:\"Prettier\":`Pureline ${ds} (${{\".pureline\":\".pureline\",defaults:\"defaults\",\"prettier-fallback\":\"Prettier options\"}[p.source]})`}async function S(p,y){try{let w=await e.exec(\"gofmt\",[],{input:p,cwd:y,timeoutMs:2e4});if(w.code===0&&w.stdout)return{text:w.stdout};if(w.code!==0&&w.stderr.trim())return{text:null,note:`gofmt: ${w.stderr.trim().split(`\n`)[0]}`}}catch{}return{text:null}}async function L(p,y){try{let w=await e.exec(\"crystal\",[\"tool\",\"format\",\"--no-color\",\"-\"],{input:p,cwd:y,timeoutMs:3e4});if(w.code===0&&w.stdout)return{text:w.stdout};if(w.code!==0&&w.stderr.trim())return{text:null,note:`crystal tool format: ${w.stderr.trim().split(`\n`)[0]}`}}catch{}return{text:null}}async function O(p,y){let w=y.language,P=[...y.notes],I=p.workspace??U.dirname(p.path??\"/\");y.fallbackNote&&!n.has(I)&&(n.add(I),P.push(y.fallbackNote));let D=v(y,p.options),x=p.path?U.dirname(p.path):p.workspace??void 0,E=p.text,N=!1;if(w.name===\"go\"&&!p.range){let W=await S(E,x);W.note&&P.push(W.note),W.text!==null&&(E=W.text,N=!0)}if(w.name===\"crystal\"&&!p.range){let W=await L(E,x);W.note&&P.push(W.note),W.text!==null&&(E=W.text)}let j=mn(E,p.languageId??w.name,D,{range:p.range,path:p.path});P.push(...j.notes);let R=j.text;if(N&&R!==E){let W=await S(R,x);W.text!==null&&(R=W.text)}let A={text:R,engine:k(y)};return P.length?{...A,notes:P}:A}async function T(p,y){let w=await Sn(e,{bin:y.binary.bin,filePath:p.path,folder:U.dirname(p.path),text:p.text,range:p.range});return w.text===null?(o(w.note),null):{text:w.text,engine:k(y)}}return{decide:g,purelineConfig:v,engineLabel:k,async supportsFormat(p,y){return await g(p,y)!==null},async format(p){let y=await g(p,p.workspace);return!y||y.ignored?null:y.engine===\"prettier\"?T(p,y):O(p,y)},async supportsCheck(p,y){let w=F(p);if(!w||w.name===\"kotlin\"||String(r().checkOnType)===\"false\")return!1;let P=await g(p,y);return P!==null&&P.engine===\"pureline\"&&!P.ignored},async check(p){if(String(r().checkOnType)===\"false\")return[];let y=await g(p,p.workspace);if(!y||y.engine!==\"pureline\"||y.ignored)return[];let w=v(y,{});return on(p.text,p.languageId??y.language.name,w)},forget(){s.clear(),kn(e)}}}var Ln={off:\"off\",hint:\"hint\",info:\"info\",warn:\"warning\",error:\"error\"};function C(e,t){return`- **${e}:** ${t}`}function ws(e){return e.style===\"tab\"?\"tabs\":`${e.size} spaces`}function bs(e,t){return oe.filter(n=>n.languages.includes(t)&&(n.checked||n.fixable)).map(n=>{let r=q(e,n.id),i=n.fixable?\"fix + check\":\"check\";return`| ${n.id} | ${n.title} | ${Ln[r]??r} | ${r===\"off\"?\"\\u2014\":i} |`})}function ks(e){let{config:t,decision:n,language:r}=e,i=[\"## Resolved options\",\"\",C(\"Indentation\",ws(t.indent)),C(\"Line endings\",t.endOfLine),C(\"Print width\",t.printWidth),C(\"Semicolons\",t.semicolons?\"yes\":\"no\"),C(\"Final newline\",t.finalNewline?\"yes\":\"no\"),C(\"Trim trailing whitespace\",t.trimTrailingWhitespace?\"yes\":\"no\"),\"\",`## Active rules for ${r.name}`,\"\",\"| Rule | What | Level | Action |\",\"| --- | --- | --- | --- |\",...bs(t,r.name)],s=n.chain.files.filter(o=>o.ignore.length);if(s.length){i.push(\"\",\"## Ignored files\",\"\");for(let o of s)i.push(`- \\`${o.file}\\`: ${o.ignore.map(a=>`\\`${a}\\``).join(\", \")}`)}return i}function Ss(e){let{decision:t}=e,n=[\"## Prettier\",\"\"];n.push(C(\"Program\",`\\`${t.binary.bin}\\` (${t.binary.source}${t.version?`, version ${t.version}`:\"\"})`)),n.push(C(\"Config\",t.configFile?`\\`${t.configFile}\\``:\"none \\u2014 Prettier defaults\")),t.ignoreFile&&n.push(C(\".prettierignore\",`\\`${t.ignoreFile}\\``)),t.ignored&&n.push(C(\"This file\",\"ignored by Prettier \\u2014 it is not formatted\"));let r=Object.entries(t.options??{});if(t.parsed&&!t.parsed.readable&&n.push(\"\",\"The config is a script or a shared config \\u2014 Prettier resolves it itself, so no options are listed here.\"),r.length){n.push(\"\",\"### Options read from the config\",\"\");for(let[i,s]of r)n.push(`- \\`${i}\\`: \\`${JSON.stringify(s)}\\``)}return n}function En(e){let{file:t,decision:n}=e,r=[\"# Formatter: active configuration\",\"\"];if(r.push(C(\"File\",t.path?`\\`${t.path}\\``:\"not saved yet\")),r.push(C(\"Language\",t.languageId??\"unknown\")),!n)return r.push(C(\"Engine\",\"none\"),\"\",\"No formatter in this extension handles the file: Pureline knows Java, JavaScript, TypeScript, Go, Crystal and Kotlin, and Prettier only runs when a Prettier config exists (or the engine setting forces it).\"),r.join(`\n`);r.push(C(\"Engine\",e.label));let i={\".pureline\":\"a `.pureline` file was found\",defaults:\"no config file was found, so the Pureline defaults apply (editor options and the `defaultIndent` setting)\",\"prettier-fallback\":\"a Prettier config exists but Prettier is not installed\"};if(n.engine===\"pureline\"&&r.push(C(\"Why\",i[n.source])),n.engine===\"prettier\"&&r.push(C(\"Why\",\"a Prettier config was found (or Prettier is forced by the engine setting)\")),n.ignored&&r.push(C(\"This file\",\"ignored \\u2014 it is not formatted\")),n.engine===\"pureline\"&&n.chain.files.length){r.push(\"\",\"## `.pureline` files (nearest first)\",\"\");for(let s of n.chain.files)r.push(`- \\`${s.file}\\``)}if(r.push(\"\"),r.push(...n.engine===\"pureline\"?ks(e):Ss(e)),n.notes?.length){r.push(\"\",\"## Notes\",\"\");for(let s of n.notes)r.push(`- ${s}`)}return r.join(`\n`)}function Tn(){let e=[\"# Pureline 1.1 rule catalog\",\"\",'Rules are switched in a `.pureline` file: `\"rules\": { \"PL-CF-002\": \"error\", \"PL-FMT-001\": \"off\" }`.',\"A rule that is `off` is neither fixed nor reported. **Fix** means the formatter rewrites code for it when you format.\",\"\",\"| Rule | What | Languages | Default | Fix | Check |\",\"| --- | --- | --- | --- | --- | --- |\"];for(let t of oe){let n=t.languages.length===5?\"all\":t.languages.join(\", \");e.push(`| ${t.id} | ${t.title} | ${n} | ${Ln[t.severity]} | ${t.fixable?\"yes\":\"\\u2014\"} | ${t.checked?\"yes\":\"review\"} |`)}return e.join(`\n`)}var Os=20,Ps=new Set([\".pureline\",\".prettierrc\",\".prettierignore\",\"package.json\"]);function Ls(e){let t=Nn.basename(e);return Ps.has(t)||/^\\.?prettier(?:rc|\\.config)/.test(t)}function Es(e){return e.engine===\"prettier\"?\"Prettier\":e.source===\".pureline\"?\"Pureline \\xB7 .pureline\":e.source===\"prettier-fallback\"?\"Pureline \\xB7 Prettier options\":\"Pureline\"}async function Ts(e){let t=e.workspace.root();if(!t){e.ui.notify(\"Open a folder first: the .pureline file belongs in the project root.\",\"warning\");return}let n=Nn.join(t,ce),r=await Cn.access(n).then(()=>!0,()=>!1);r||(await Cn.writeFile(n,rt(),\"utf8\"),e.ui.notify(\".pureline created in the project root.\",\"success\")),r&&e.ui.notify(\"There already is a .pureline in the project root.\",\"info\"),e.ui.openFile(n)}function Ra(e){let t=Pn(e,()=>e.settings.all()),n=()=>e.workspace.root(),r=()=>{let o=e.events.last(\"activeFile\");return o?{path:o.path??null,languageId:o.languageId??null}:null};(!e.formatters||!e.diagnostics)&&e.log(\"This Lumen has no formatter API; the extension needs Lumen 0.7.0 or newer.\"),e.formatters?.register(\"pureline\",{supports:o=>t.supportsFormat(o,n()),format:o=>t.format(o)},{priority:50}),e.diagnostics?.register(\"pureline\",{supports:o=>t.supportsCheck(o,n()),check:o=>t.check(o)});let i=async()=>{let o=r();if(!(String(e.settings.get(\"showStatus\")??\"true\")!==\"false\")||!o?.path||!F(o)){e.statusBar.set(\"engine\",null);return}let l=await t.decide(o,n()).catch(()=>null);if(!l){e.statusBar.set(\"engine\",null);return}e.statusBar.set(\"engine\",{text:Es(l),tooltip:`Formatter: ${t.engineLabel(l)} \\u2014 click to show the configuration`,icon:\"wand-sparkles\",command:\"format.explain\",side:\"right\",priority:Os})},s=async()=>{let o=r();if(!o){e.ui.notify(\"Open a file first.\",\"info\");return}let a=await t.decide(o,n()),l=F(o),f=a?.engine===\"pureline\"?t.purelineConfig(a,{}):null,u=a?t.engineLabel(a):\"none\",h=En({file:o,workspace:n(),decision:a,config:f,language:l,label:u});e.ui.openDocument(\"Formatter: configuration\",h,\"markdown\")};return e.commands.register(\"format.explain\",s),e.commands.register(\"pureline.init\",()=>Ts(e)),e.commands.register(\"pureline.rules\",()=>e.ui.openDocument(\"Pureline rules\",Tn(),\"markdown\")),e.events.on(\"activeFile\",i),e.events.on(\"fileSaved\",o=>{Ls(o.path)&&t.forget(),i()}),e.settings.onDidChange(()=>{t.forget(),i()}),i(),()=>e.statusBar.set(\"engine\",null)}export{Ra as activate};\n"
  },
  "addon": {
    "schema": 1,
    "languages": [],
    "themes": [],
    "commands": [],
    "events": [],
    "templates": [],
    "projectKinds": [],
    "snippets": [],
    "id": "addon.formatter",
    "name": "Formatter",
    "version": "1.0.0",
    "description": "Formats and checks code in the Pureline style (Java, JavaScript, TypeScript, Go, Crystal) and uses Prettier when a project is configured for it. Ships with program code.",
    "author": "ezTxmMC",
    "icon": "Fm",
    "color": "#6c8cff",
    "category": "tool"
  }
}
