import*as c from"path";import{lintDocument as g,getTotals as v,getLineColLocation as h,Source as y,getCodeframe as C}from"@redocly/openapi-core";import{slash as p}from"../../../utils/path/slash.js";import{getUniqueProblemsCount as P}from"./shared-utils.js";const b=20;async function j(a,r,t,o){const e=c.resolve(t.fs.cwd,a.relativePath),s=r.resolvedConfig.apis??{},l=Object.keys(s).find(n=>c.resolve(r.configPath?c.dirname(r.configPath):t.fs.cwd,s[n].root)===e),m={config:r.forAlias(l),base:c.dirname(e),document:{source:new y(e,a.content),parsed:a.parsed},externalRefResolver:o},f=await g(m),i=P(f);return{...v(f),uniqueErrors:i.errors,uniqueWarnings:i.warnings,problems:O(f,t.fs.cwd).filter(n=>!n.ignored)}}function E(a){const r=new Set,t={};for(const[o,e]of Object.entries(a)){const s=t[o]=t[o]||new Set,l=[e],m=e.resolvedConfig?.apis??{};for(const f of Object.keys(m)){const i=e.forAlias(f);i&&i!==e&&l.push(i)}for(const f of l){const i=Object.values(f.rules).flatMap(n=>Object.entries(n));for(const[n,u]of i)if(!(u==="off"||u?.severity==="off"))if(n==="assertions"){if(!Array.isArray(u))continue;for(const d of u)!d||d.severity==="off"||(s.add(d.assertionId),r.add(d.assertionId))}else r.add(n),s.add(n)}}return{perLevel:Object.fromEntries(Object.entries(t).map(([o,e])=>[o,Array.from(e)])),all:Array.from(r)}}function O(a,r){const t={};return a.map(o=>{const e=t[o.ruleId]||0;t[o.ruleId]=e+1;const s=o.location[0];if(e>b)return{...o,codeframe:`Code frame skipped due to too many errors of this type. Only first ${b} errors are shown.`,location:{...s,source:{absoluteRef:p(c.relative(r,s.source.absoluteRef))}},from:void 0};const l=h(s);return{...o,codeframe:C(l,!1),location:{...s,source:{absoluteRef:p(c.relative(r,s.source.absoluteRef))}},from:void 0}})}export{E as getAllRuleNames,j as lintDefinition};
