@fabriziosalmi/slopless 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/rules/VBC-006-B.yaml +34 -0
- package/rules/VBC-017-B.yaml +30 -0
package/README.md
CHANGED
|
@@ -6,12 +6,13 @@ Slopless is a static analysis tool designed to identify and mitigate unstructure
|
|
|
6
6
|
|
|
7
7
|
## Architecture and Capabilities
|
|
8
8
|
|
|
9
|
-
- **Rule Engine**:
|
|
9
|
+
- **Rule Engine**: 150 rigorous rules spanning security, maintainability, accessibility, and documentation integrity. Every rule ships executable examples — a snippet it must flag and one it must leave alone — run on every commit.
|
|
10
10
|
- **AST Inspection**: Deep structural validation to identify excessive cyclomatic complexity, parameter limits, and empty control flow blocks.
|
|
11
11
|
- **Deep Semantic Validation**: Opt-in TypeScript TypeChecker (`--type-check`) for resolving inherited types, identifying floating promises, and validating structural intent beyond AST boundaries.
|
|
12
12
|
- **Heuristic Auto-Fixes**: Autonomous modification of known anti-patterns (e.g., `var` to `let`) using `--fix`.
|
|
13
13
|
- **Concurrency Pooling**: Fault-tolerant AST parsing distributed across CPU-bound boundaries to guarantee stability on massive monorepos without OOM crashes.
|
|
14
|
-
- **Lexical Scoping**:
|
|
14
|
+
- **Lexical Scoping**: Every string, comment and regular expression literal is mapped before a rule reads a byte — with the TypeScript scanner where it can, and a declarative tokeniser for Python, Go, Rust, shell, Java, C, C++, C#, Kotlin, Swift and Ruby. Each rule declares what it looks at (`code`, `strings`, `comments`, `regex`, `all`). A rule about `eval()` stays quiet inside a comment; a rule about insecure URLs does not read the pattern that validates them; a Python docstring is documentation rather than a string value.
|
|
15
|
+
- **Exceptions That Say Why**: A rule can skip test code that lives inside the file it tests (`#[cfg(test)] mod tests`), skip documentation comments in languages that mandate them, and be excused by name on one line with `// slopless-disable-next-line VBC-001 -- reason`. A project can claim its own vocabulary, so `blacklist` in a firewall is the domain rather than a finding — and the run reports how many findings that excused.
|
|
15
16
|
- **Rule Precedence**: A specific rule declares the general ones it `supersedes`, so a single `// TODO: implement this` produces one finding, not four.
|
|
16
17
|
- **LSP IDE Integration**: Ships with `vscode-slopless` for real-time Squiggly-Line diagnostics inside VS Code and Cursor.
|
|
17
18
|
|
|
@@ -113,6 +114,42 @@ directive is read from the raw line, so `#`, `/* */` and `<!-- -->` work too, an
|
|
|
113
114
|
it covers every checker tier. Full rules in
|
|
114
115
|
[docs/configuration.md](docs/configuration.md).
|
|
115
116
|
|
|
117
|
+
## What reaches which language
|
|
118
|
+
|
|
119
|
+
Every run ends by saying how many rules applied to each language it read, because
|
|
120
|
+
a file nothing checked looks exactly like a file that came back clean. The same
|
|
121
|
+
count, written from the rules rather than from memory:
|
|
122
|
+
|
|
123
|
+
<!-- coverage:start -->
|
|
124
|
+
| language | rules |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| TypeScript (`.ts`) | 95 of 150 |
|
|
127
|
+
| JavaScript (`.js`) | 94 of 150 |
|
|
128
|
+
| TypeScript (JSX) (`.tsx`) | 39 of 150 |
|
|
129
|
+
| Python (`.py`) | 32 of 150 |
|
|
130
|
+
| Markdown (`.md`) | 26 of 150 |
|
|
131
|
+
| CSS (`.css`) | 23 of 150 |
|
|
132
|
+
| Go (`.go`) | 19 of 150 |
|
|
133
|
+
| Shell (`.sh`) | 16 of 150 |
|
|
134
|
+
| Java (`.java`) | 15 of 150 |
|
|
135
|
+
| Rust (`.rs`) | 15 of 150 |
|
|
136
|
+
| Ruby (`.rb`) | 14 of 150 |
|
|
137
|
+
| C# (`.cs`) | 13 of 150 |
|
|
138
|
+
| C and C++ (`.c`) | 12 of 150 |
|
|
139
|
+
| Kotlin (`.kt`) | 12 of 150 |
|
|
140
|
+
| Swift (`.swift`) | 12 of 150 |
|
|
141
|
+
<!-- coverage:end -->
|
|
142
|
+
|
|
143
|
+
The parsing tiers use the TypeScript compiler, so the AST, semantic-naming and
|
|
144
|
+
type checks are TypeScript and JavaScript only. Everywhere else a declarative
|
|
145
|
+
tokeniser finds the comments and strings, which is enough for `scan:` and for the
|
|
146
|
+
rules that matter there: unattributed TODOs, FIXMEs describing live defects,
|
|
147
|
+
placeholder text, generated prose, hardcoded secrets, insecure URLs.
|
|
148
|
+
|
|
149
|
+
That split is deliberate. `clippy` finds an unhandled `unwrap` better than a regex
|
|
150
|
+
ever will and has the types to prove it; `staticcheck` and `pylint` are the same.
|
|
151
|
+
None of them has an opinion about a section that says "coming soon".
|
|
152
|
+
|
|
116
153
|
## Rule Taxonomy
|
|
117
154
|
|
|
118
155
|
- **Core/Security**: Detection of exposed credentials, `eval()` usage, `innerHTML` assignments, SQL built by concatenation, command injection, prototype pollution, insecure file permissions (`chmod 777`), and hardcoded paths.
|
|
@@ -121,7 +158,7 @@ it covers every checker tier. Full rules in
|
|
|
121
158
|
- **Documentation**: Detection of generated filler content, non-inclusive language, and broken external references.
|
|
122
159
|
|
|
123
160
|
Full documentation at [fabriziosalmi.github.io/slopless](https://fabriziosalmi.github.io/slopless/):
|
|
124
|
-
[all
|
|
161
|
+
[all 150 rules](https://fabriziosalmi.github.io/slopless/rules/) ·
|
|
125
162
|
[configuration](https://fabriziosalmi.github.io/slopless/configuration) ·
|
|
126
163
|
[writing a rule](https://fabriziosalmi.github.io/slopless/writing-a-rule) ·
|
|
127
164
|
[the scanner bug story](https://fabriziosalmi.github.io/slopless/story)
|
package/dist/index.js
CHANGED
|
@@ -431,7 +431,7 @@ Project '${d.projectName}' (${hN[d.projectKind]}) ${o}
|
|
|
431
431
|
`,o++};this.projectService.externalProjects.forEach(u),this.projectService.configuredProjects.forEach(u),this.projectService.inferredProjects.forEach(u)}}this.logger.msg(s,"Err")}send(t){if(t.type==="event"&&!this.canUseEvents){this.logger.hasLevel(3)&&this.logger.info(`Session does not support events: ignored event: ${Hb(t)}`);return}this.writeMessage(t)}writeMessage(t){let n=yve(t,this.logger,this.byteLength,this.host.newLine);this.host.write(n)}event(t,n){this.send(vve(n,t))}doOutput(t,n,i,s,o,u){let d={seq:0,type:"response",command:n,request_seq:i,success:s,performanceData:o&&Kje(o)};if(s){let p;if(Ps(t))d.body=t,p=t.metadata,delete t.metadata;else if(typeof t=="object")if(t.metadata){let{metadata:x,...b}=t;d.body=b,p=x}else d.body=t;else d.body=t;p&&(d.metadata=p)}else O.assert(t===void 0);u&&(d.message=u),this.send(d)}semanticCheck(t,n){var i,s;let o=Fo();(i=kn)==null||i.push(kn.Phase.Session,"semanticCheck",{file:t,configFilePath:n.canonicalConfigFilePath});let u=$je(n,t)?Ql:n.getLanguageService().getSemanticDiagnostics(t).filter(d=>!!d.file);this.sendDiagnosticsEvent(t,n,u,"semanticDiag",o),(s=kn)==null||s.pop()}syntacticCheck(t,n){var i,s;let o=Fo();(i=kn)==null||i.push(kn.Phase.Session,"syntacticCheck",{file:t,configFilePath:n.canonicalConfigFilePath}),this.sendDiagnosticsEvent(t,n,n.getLanguageService().getSyntacticDiagnostics(t),"syntaxDiag",o),(s=kn)==null||s.pop()}suggestionCheck(t,n){var i,s;let o=Fo();(i=kn)==null||i.push(kn.Phase.Session,"suggestionCheck",{file:t,configFilePath:n.canonicalConfigFilePath}),this.sendDiagnosticsEvent(t,n,n.getLanguageService().getSuggestionDiagnostics(t),"suggestionDiag",o),(s=kn)==null||s.pop()}regionSemanticCheck(t,n,i){var s,o,u;let d=Fo();(s=kn)==null||s.push(kn.Phase.Session,"regionSemanticCheck",{file:t,configFilePath:n.canonicalConfigFilePath});let p;if(!this.shouldDoRegionCheck(t)||!(p=n.getLanguageService().getRegionSemanticDiagnostics(t,i))){(o=kn)==null||o.pop();return}this.sendDiagnosticsEvent(t,n,p.diagnostics,"regionSemanticDiag",d,p.spans),(u=kn)==null||u.pop()}shouldDoRegionCheck(t){var n;let i=(n=this.projectService.getScriptInfoForNormalizedPath(t))==null?void 0:n.textStorage.getLineInfo().getLineCount();return!!(i&&i>=this.regionDiagLineCountThreshold)}sendDiagnosticsEvent(t,n,i,s,o,u){try{let d=O.checkDefined(n.getScriptInfo(t)),p=Fo()-o,x={file:t,diagnostics:i.map(b=>zje(t,n,b)),spans:u==null?void 0:u.map(b=>Tg(b,d))};this.event(x,s),this.addDiagnosticsPerformanceData(t,s,p)}catch(d){this.logError(d,s)}}updateErrorCheck(t,n,i,s=!0){if(n.length===0)return;O.assert(!this.suppressDiagnosticEvents);let o=this.changeSeq,u=Math.min(i,200),d=0,p=()=>{if(d++,n.length>d)return t.delay("checkOne",u,b)},x=(T,E)=>{if(this.semanticCheck(T,E),this.changeSeq===o){if(this.getPreferences(T).disableSuggestions)return p();t.immediate("suggestionCheck",()=>{this.suggestionCheck(T,E),p()})}},b=()=>{if(this.changeSeq!==o)return;let T,E=n[d];if(zs(E)?E=this.toPendingErrorCheck(E):"ranges"in E&&(T=E.ranges,E=this.toPendingErrorCheck(E.file)),!E)return p();let{fileName:P,project:N}=E;if($d(N),!!N.containsFile(P,s)&&(this.syntacticCheck(P,N),this.changeSeq===o)){if(N.projectService.serverMode!==0)return p();if(T)return t.immediate("regionSemanticCheck",()=>{let F=this.projectService.getScriptInfoForNormalizedPath(P);F&&this.regionSemanticCheck(P,N,T.map(M=>this.getRange({file:P,...M},F))),this.changeSeq===o&&t.immediate("semanticCheck",()=>x(P,N))});t.immediate("semanticCheck",()=>x(P,N))}};n.length>d&&this.changeSeq===o&&t.delay("checkOne",i,b)}cleanProjects(t,n){if(n){this.logger.info(`cleaning ${t}`);for(let i of n)i.getLanguageService(!1).cleanupSemanticCache(),i.cleanupProgram()}}cleanup(){this.cleanProjects("inferred projects",this.projectService.inferredProjects),this.cleanProjects("configured projects",Es(this.projectService.configuredProjects.values())),this.cleanProjects("external projects",this.projectService.externalProjects),this.host.gc&&(this.logger.info("host.gc()"),this.host.gc())}getEncodedSyntacticClassifications(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t);return i.getEncodedSyntacticClassifications(n,t)}getEncodedSemanticClassifications(t){let{file:n,project:i}=this.getFileAndProject(t),s=t.format==="2020"?"2020":"original";return i.getLanguageService().getEncodedSemanticClassifications(n,t,s)}getProject(t){return t===void 0?void 0:this.projectService.findProject(t)}getConfigFileAndProject(t){let n=this.getProject(t.projectFileName),i=Po(t.file);return{configFile:n&&n.hasConfigFile(i)?i:void 0,project:n}}getConfigFileDiagnostics(t,n,i){let s=n.getAllProjectErrors(),o=n.getLanguageService().getCompilerOptionsDiagnostics(),u=Jn(os(s,o),d=>!!d.file&&d.file.fileName===t);return i?this.convertToDiagnosticsWithLinePositionFromDiagnosticFile(u):Nr(u,d=>G7(d,!1))}convertToDiagnosticsWithLinePositionFromDiagnosticFile(t){return t.map(n=>({message:yg(n.messageText,this.host.newLine),start:n.start,length:n.length,category:M2(n),code:n.code,source:n.source,startLocation:n.file&&y6(oa(n.file,n.start)),endLocation:n.file&&y6(oa(n.file,n.start+n.length)),reportsUnnecessary:n.reportsUnnecessary,reportsDeprecated:n.reportsDeprecated,relatedInformation:Nr(n.relatedInformation,GQ)}))}getCompilerOptionsDiagnostics(t){let n=this.getProject(t.projectFileName);return this.convertToDiagnosticsWithLinePosition(Jn(n.getLanguageService().getCompilerOptionsDiagnostics(),i=>!i.file),void 0)}convertToDiagnosticsWithLinePosition(t,n){return t.map(i=>({message:yg(i.messageText,this.host.newLine),start:i.start,length:i.length,category:M2(i),code:i.code,source:i.source,startLocation:n&&n.positionToLineOffset(i.start),endLocation:n&&n.positionToLineOffset(i.start+i.length),reportsUnnecessary:i.reportsUnnecessary,reportsDeprecated:i.reportsDeprecated,relatedInformation:Nr(i.relatedInformation,GQ)}))}getDiagnosticsWorker(t,n,i,s){let{project:o,file:u}=this.getFileAndProject(t);if(n&&$je(o,u))return Ql;let d=o.getScriptInfoForNormalizedPath(u),p=i(o,u);return s?this.convertToDiagnosticsWithLinePosition(p,d):p.map(x=>zje(u,o,x))}getDefinition(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=this.getPositionInFile(t,i),u=this.mapDefinitionInfoLocations(s.getLanguageService().getDefinitionAtPosition(i,o)||Ql,s);return n?this.mapDefinitionInfo(u,s):u.map(Wne.mapToOriginalLocation)}mapDefinitionInfoLocations(t,n){return t.map(i=>{let s=Gje(i,n);return s?{...s,containerKind:i.containerKind,containerName:i.containerName,kind:i.kind,name:i.name,failedAliasResolution:i.failedAliasResolution,...i.unverified&&{unverified:i.unverified}}:i})}getDefinitionAndBoundSpan(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=this.getPositionInFile(t,i),u=O.checkDefined(s.getScriptInfo(i)),d=s.getLanguageService().getDefinitionAndBoundSpan(i,o);if(!d||!d.definitions)return{definitions:Ql,textSpan:void 0};let p=this.mapDefinitionInfoLocations(d.definitions,s),{textSpan:x}=d;return n?{definitions:this.mapDefinitionInfo(p,s),textSpan:Tg(x,u)}:{definitions:p.map(Wne.mapToOriginalLocation),textSpan:x}}findSourceDefinition(t){var n;let{file:i,project:s}=this.getFileAndProject(t),o=this.getPositionInFile(t,i),u=s.getLanguageService().getDefinitionAtPosition(i,o),d=this.mapDefinitionInfoLocations(u||Ql,s).slice();if(this.projectService.serverMode===0&&(!St(d,P=>Po(P.fileName)!==i&&!P.isAmbient)||St(d,P=>!!P.failedAliasResolution))){let P=ZJ(j=>j.textSpan.start,oK(this.host.useCaseSensitiveFileNames));d==null||d.forEach(j=>P.add(j));let N=s.getNoDtsResolutionProject(i),F=N.getLanguageService(),M=(n=F.getDefinitionAtPosition(i,o,!0,!1))==null?void 0:n.filter(j=>Po(j.fileName)!==i);if(St(M))for(let j of M){if(j.unverified){let U=T(j,s.getLanguageService().getProgram(),F.getProgram());if(St(U)){for(let J of U)P.add(J);continue}}P.add(j)}else{let j=d.filter(U=>Po(U.fileName)!==i&&U.isAmbient);for(let U of St(j)?j:b()){let J=x(U.fileName,i,N);if(!J)continue;let q=this.projectService.getOrCreateScriptInfoNotOpenedByClient(J,N.currentDirectory,N.directoryStructureHost,!1);if(!q)continue;N.containsScriptInfo(q)||(N.addRoot(q),N.updateGraph());let H=F.getProgram(),ee=O.checkDefined(H.getSourceFile(J));for(let ie of E(U.name,ee,H))P.add(ie)}}d=Es(P.values())}return d=d.filter(P=>!P.isAmbient&&!P.failedAliasResolution),this.mapDefinitionInfo(d,s);function x(P,N,F){var M,j,U;let J=dM(P);if(J&&P.lastIndexOf(qh)===J.topLevelNodeModulesIndex){let q=P.substring(0,J.packageRootIndex),H=(M=s.getModuleResolutionCache())==null?void 0:M.getPackageJsonInfoCache(),ee=s.getCompilationSettings(),ie=T4(ys(q,s.getCurrentDirectory()),x4(H,s,ee));if(!ie)return;let X=PG(ie,{moduleResolution:2},s,s.getModuleResolutionCache()),Te=P.substring(J.topLevelPackageNameIndex+1,J.packageRootIndex),ue=k4(gO(Te)),Q=s.toPath(P);if(X&&St(X,ye=>s.toPath(ye)===Q))return(j=F.resolutionCache.resolveSingleModuleNameWithoutWatching(ue,N).resolvedModule)==null?void 0:j.resolvedFileName;{let ye=P.substring(J.packageRootIndex+1),ge=`${ue}/${N_(ye)}`;return(U=F.resolutionCache.resolveSingleModuleNameWithoutWatching(ge,N).resolvedModule)==null?void 0:U.resolvedFileName}}}function b(){let P=s.getLanguageService(),N=P.getProgram(),F=mf(N.getSourceFile(i),o);return(lo(F)||Ke(F))&&Zo(F.parent)&&Tce(F,M=>{var j;if(M===F)return;let U=(j=P.getDefinitionAtPosition(i,M.getStart(),!0,!1))==null?void 0:j.filter(J=>Po(J.fileName)!==i&&J.isAmbient).map(J=>({fileName:J.fileName,name:Xp(F)}));if(St(U))return U})||Ql}function T(P,N,F){var M;let j=F.getSourceFile(P.fileName);if(!j)return;let U=mf(N.getSourceFile(i),o),J=N.getTypeChecker().getSymbolAtLocation(U),q=J&&oc(J,277);if(!q)return;let H=((M=q.propertyName)==null?void 0:M.text)||q.name.text;return E(H,j,F)}function E(P,N,F){let M=Xo.Core.getTopMostDeclarationNamesInFile(P,N);return rs(M,j=>{let U=F.getTypeChecker().getSymbolAtLocation(j),J=bI(j);if(U&&J)return p6.createDefinitionInfo(J,F.getTypeChecker(),U,J,!0)})}}getEmitOutput(t){let{file:n,project:i}=this.getFileAndProject(t);if(!i.shouldEmitFile(i.getScriptInfo(n)))return{emitSkipped:!0,outputFiles:[],diagnostics:[]};let s=i.getLanguageService().getEmitOutput(n);return t.richResponse?{...s,diagnostics:t.includeLinePosition?this.convertToDiagnosticsWithLinePositionFromDiagnosticFile(s.diagnostics):s.diagnostics.map(o=>G7(o,!0))}:s}mapJSDocTagInfo(t,n,i){return t?t.map(s=>{var o;return{...s,text:i?this.mapDisplayParts(s.text,n):(o=s.text)==null?void 0:o.map(u=>u.text).join("")}}):[]}mapDisplayParts(t,n){return t?t.map(i=>i.kind!=="linkName"?i:{...i,target:this.toFileSpan(i.target.fileName,i.target.textSpan,n)}):[]}mapSignatureHelpItems(t,n,i){return t.map(s=>({...s,documentation:this.mapDisplayParts(s.documentation,n),parameters:s.parameters.map(o=>({...o,documentation:this.mapDisplayParts(o.documentation,n)})),tags:this.mapJSDocTagInfo(s.tags,n,i)}))}mapDefinitionInfo(t,n){return t.map(i=>({...this.toFileSpanWithContext(i.fileName,i.textSpan,i.contextSpan,n),...i.unverified&&{unverified:i.unverified}}))}static mapToOriginalLocation(t){return t.originalFileName?(O.assert(t.originalTextSpan!==void 0,"originalTextSpan should be present if originalFileName is"),{...t,fileName:t.originalFileName,textSpan:t.originalTextSpan,targetFileName:t.fileName,targetTextSpan:t.textSpan,contextSpan:t.originalContextSpan,targetContextSpan:t.contextSpan}):t}toFileSpan(t,n,i){let s=i.getLanguageService(),o=s.toLineColumnOffset(t,n.start),u=s.toLineColumnOffset(t,Pc(n));return{file:t,start:{line:o.line+1,offset:o.character+1},end:{line:u.line+1,offset:u.character+1}}}toFileSpanWithContext(t,n,i,s){let o=this.toFileSpan(t,n,s),u=i&&this.toFileSpan(t,i,s);return u?{...o,contextStart:u.start,contextEnd:u.end}:o}getTypeDefinition(t){let{file:n,project:i}=this.getFileAndProject(t),s=this.getPositionInFile(t,n),o=this.mapDefinitionInfoLocations(i.getLanguageService().getTypeDefinitionAtPosition(n,s)||Ql,i);return this.mapDefinitionInfo(o,i)}mapImplementationLocations(t,n){return t.map(i=>{let s=Gje(i,n);return s?{...s,kind:i.kind,displayParts:i.displayParts}:i})}getImplementation(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=this.getPositionInFile(t,i),u=this.mapImplementationLocations(s.getLanguageService().getImplementationAtPosition(i,o)||Ql,s);return n?u.map(({fileName:d,textSpan:p,contextSpan:x})=>this.toFileSpanWithContext(d,p,x,s)):u.map(Wne.mapToOriginalLocation)}getSyntacticDiagnosticsSync(t){let{configFile:n}=this.getConfigFileAndProject(t);return n?Ql:this.getDiagnosticsWorker(t,!1,(i,s)=>i.getLanguageService().getSyntacticDiagnostics(s),!!t.includeLinePosition)}getSemanticDiagnosticsSync(t){let{configFile:n,project:i}=this.getConfigFileAndProject(t);return n?this.getConfigFileDiagnostics(n,i,!!t.includeLinePosition):this.getDiagnosticsWorker(t,!0,(s,o)=>s.getLanguageService().getSemanticDiagnostics(o).filter(u=>!!u.file),!!t.includeLinePosition)}getSuggestionDiagnosticsSync(t){let{configFile:n}=this.getConfigFileAndProject(t);return n?Ql:this.getDiagnosticsWorker(t,!0,(i,s)=>i.getLanguageService().getSuggestionDiagnostics(s),!!t.includeLinePosition)}getJsxClosingTag(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.getPositionInFile(t,n),o=i.getJsxClosingTagAtPosition(n,s);return o===void 0?void 0:{newText:o.newText,caretOffset:0}}getLinkedEditingRange(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.getPositionInFile(t,n),o=i.getLinkedEditingRangeAtPosition(n,s),u=this.projectService.getScriptInfoForNormalizedPath(n);if(!(u===void 0||o===void 0))return g1t(o,u)}getDocumentHighlights(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=this.getPositionInFile(t,i),u=s.getLanguageService().getDocumentHighlights(i,o,t.filesToSearch);return u?n?u.map(({fileName:d,highlightSpans:p})=>{let x=s.getScriptInfo(d);return{file:d,highlightSpans:p.map(({textSpan:b,kind:T,contextSpan:E})=>({...Sve(b,E,x),kind:T}))}}):u:Ql}provideInlayHints(t){let{file:n,project:i}=this.getFileAndProject(t),s=this.projectService.getScriptInfoForNormalizedPath(n);return i.getLanguageService().provideInlayHints(n,t,this.getPreferences(n)).map(u=>{let{position:d,displayParts:p}=u;return{...u,position:s.positionToLineOffset(d),displayParts:p==null?void 0:p.map(({text:x,span:b,file:T})=>{if(b){O.assertIsDefined(T,"Target file should be defined together with its span.");let E=this.projectService.getScriptInfo(T);return{text:x,span:{start:E.positionToLineOffset(b.start),end:E.positionToLineOffset(b.start+b.length),file:T}}}else return{text:x}})}})}mapCode(t){var n;let i=this.getHostFormatOptions(),s=this.getHostPreferences(),{file:o,languageService:u}=this.getFileAndLanguageServiceForSyntacticOperation(t),d=this.projectService.getScriptInfoForNormalizedPath(o),p=(n=t.mapping.focusLocations)==null?void 0:n.map(b=>b.map(T=>{let E=d.lineOffsetToPosition(T.start.line,T.start.offset),P=d.lineOffsetToPosition(T.end.line,T.end.offset);return{start:E,length:P-E}})),x=u.mapCode(o,t.mapping.contents,p,i,s);return this.mapTextChangesToCodeEdits(x)}getCopilotRelatedInfo(){return{relatedFiles:[]}}setCompilerOptionsForInferredProjects(t){this.projectService.setCompilerOptionsForInferredProjects(t.options,t.projectRootPath)}getProjectInfo(t){return this.getProjectInfoWorker(t.file,t.projectFileName,t.needFileNameList,t.needDefaultConfiguredProjectInfo,!1)}getProjectInfoWorker(t,n,i,s,o){let{project:u}=this.getFileAndProjectWorker(t,n);return $d(u),{configFileName:u.getProjectName(),languageServiceDisabled:!u.languageServiceEnabled,fileNames:i?u.getFileNames(!1,o):void 0,configuredProjectInfo:s?this.getDefaultConfiguredProjectInfo(t):void 0}}getDefaultConfiguredProjectInfo(t){var n;let i=this.projectService.getScriptInfo(t);if(!i)return;let s=this.projectService.findDefaultConfiguredProjectWorker(i,3);if(!s)return;let o,u;return s.seenProjects.forEach((d,p)=>{p!==s.defaultProject&&(d!==3?(o??(o=[])).push(Po(p.getConfigFilePath())):(u??(u=[])).push(Po(p.getConfigFilePath())))}),(n=s.seenConfigs)==null||n.forEach(d=>(o??(o=[])).push(d)),{notMatchedByConfig:o,notInProject:u,defaultProject:s.defaultProject&&Po(s.defaultProject.getConfigFilePath())}}getRenameInfo(t){let{file:n,project:i}=this.getFileAndProject(t),s=this.getPositionInFile(t,n),o=this.getPreferences(n);return i.getLanguageService().getRenameInfo(n,s,o)}getProjects(t,n,i){let s,o;if(t.projectFileName){let u=this.getProject(t.projectFileName);u&&(s=[u])}else{let u=n?this.projectService.getScriptInfoEnsuringProjectsUptoDate(t.file):this.projectService.getScriptInfo(t.file);if(u)n||this.projectService.ensureDefaultProjectForFile(u);else return i?Ql:(this.projectService.logErrorForScriptInfoNotFound(t.file),Jy.ThrowNoProject());s=u.containingProjects,o=this.projectService.getSymlinkedProjects(u)}return s=Jn(s,u=>u.languageServiceEnabled&&!u.isOrphan()),!i&&(!s||!s.length)&&!o?(this.projectService.logErrorForScriptInfoNotFound(t.file??t.projectFileName),Jy.ThrowNoProject()):o?{projects:s,symLinkedProjects:o}:s}getDefaultProject(t){if(t.projectFileName){let i=this.getProject(t.projectFileName);if(i)return i;if(!t.file)return Jy.ThrowNoProject()}return this.projectService.getScriptInfo(t.file).getDefaultProject()}getRenameLocations(t,n){let i=Po(t.file),s=this.getPositionInFile(t,i),o=this.getProjects(t),u=this.getDefaultProject(t),d=this.getPreferences(i),p=this.mapRenameInfo(u.getLanguageService().getRenameInfo(i,s,d),O.checkDefined(this.projectService.getScriptInfo(i)));if(!p.canRename)return n?{info:p,locs:[]}:[];let x=u1t(o,u,{fileName:t.file,pos:s},!!t.findInStrings,!!t.findInComments,d,this.host.useCaseSensitiveFileNames);return n?{info:p,locs:this.toSpanGroups(x)}:x}mapRenameInfo(t,n){if(t.canRename){let{canRename:i,fileToRename:s,displayName:o,fullDisplayName:u,kind:d,kindModifiers:p,triggerSpan:x}=t;return{canRename:i,fileToRename:s,displayName:o,fullDisplayName:u,kind:d,kindModifiers:p,triggerSpan:Tg(x,n)}}else return t}toSpanGroups(t){let n=new Map;for(let{fileName:i,textSpan:s,contextSpan:o,originalContextSpan:u,originalTextSpan:d,originalFileName:p,...x}of t){let b=n.get(i);b||n.set(i,b={file:i,locs:[]});let T=O.checkDefined(this.projectService.getScriptInfo(i));b.locs.push({...Sve(s,o,T),...x})}return Es(n.values())}getReferences(t,n){let i=Po(t.file),s=this.getProjects(t),o=this.getPositionInFile(t,i),u=_1t(s,this.getDefaultProject(t),{fileName:t.file,pos:o},this.host.useCaseSensitiveFileNames,this.logger);if(!n)return u;let d=this.getPreferences(i),p=this.getDefaultProject(t),x=p.getScriptInfoForNormalizedPath(i),b=p.getLanguageService().getQuickInfoAtPosition(i,o),T=b?h7(b.displayParts):"",E=b&&b.textSpan,P=E?x.positionToLineOffset(E.start).offset:0,N=E?x.getSnapshot().getText(E.start,Pc(E)):"";return{refs:Ha(u,M=>M.references.map(j=>Qje(this.projectService,j,d))),symbolName:N,symbolStartOffset:P,symbolDisplayString:T}}getFileReferences(t,n){let i=this.getProjects(t),s=Po(t.file),o=this.getPreferences(s),u={fileName:s,pos:0},d=bve(i,this.getDefaultProject(t),u,u,Wje,b=>(this.logger.info(`Finding references to file ${s} in project ${b.getProjectName()}`),b.getLanguageService().getFileReferences(s))),p;if(Ps(d))p=d;else{p=[];let b=HQ(this.host.useCaseSensitiveFileNames);d.forEach(T=>{for(let E of T)b.has(E)||(p.push(E),b.add(E))})}return n?{refs:p.map(b=>Qje(this.projectService,b,o)),symbolName:`"${t.file}"`}:p}openClientFile(t,n,i,s){this.projectService.openClientFileWithNormalizedPath(t,n,i,!1,s)}getPosition(t,n){return t.position!==void 0?t.position:n.lineOffsetToPosition(t.line,t.offset)}getPositionInFile(t,n){let i=this.projectService.getScriptInfoForNormalizedPath(n);return this.getPosition(t,i)}getFileAndProject(t){return this.getFileAndProjectWorker(t.file,t.projectFileName)}getFileAndLanguageServiceForSyntacticOperation(t){let{file:n,project:i}=this.getFileAndProject(t);return{file:n,languageService:i.getLanguageService(!1)}}getFileAndProjectWorker(t,n){let i=Po(t),s=this.getProject(n)||this.projectService.ensureDefaultProjectForFile(i);return{file:i,project:s}}getOutliningSpans(t,n){let{file:i,languageService:s}=this.getFileAndLanguageServiceForSyntacticOperation(t),o=s.getOutliningSpans(i);if(n){let u=this.projectService.getScriptInfoForNormalizedPath(i);return o.map(d=>({textSpan:Tg(d.textSpan,u),hintSpan:Tg(d.hintSpan,u),bannerText:d.bannerText,autoCollapse:d.autoCollapse,kind:d.kind}))}else return o}getTodoComments(t){let{file:n,project:i}=this.getFileAndProject(t);return i.getLanguageService().getTodoComments(n,t.descriptors)}getDocCommentTemplate(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.getPositionInFile(t,n);return i.getDocCommentTemplateAtPosition(n,s,this.getPreferences(n),this.getFormatOptions(n))}getSpanOfEnclosingComment(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=t.onlyMultiLine,o=this.getPositionInFile(t,n);return i.getSpanOfEnclosingComment(n,o,s)}getIndentation(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.getPositionInFile(t,n),o=t.options?h6(t.options):this.getFormatOptions(n),u=i.getIndentationAtPosition(n,s,o);return{position:s,indentation:u}}getBreakpointStatement(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.getPositionInFile(t,n);return i.getBreakpointStatementAtPosition(n,s)}getNameOrDottedNameSpan(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.getPositionInFile(t,n);return i.getNameOrDottedNameSpan(n,s,s)}isValidBraceCompletion(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.getPositionInFile(t,n);return i.isValidBraceCompletionAtPosition(n,s,t.openingBrace.charCodeAt(0))}getQuickInfoWorker(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=this.projectService.getScriptInfoForNormalizedPath(i),u=this.getPreferences(i),d=s.getLanguageService().getQuickInfoAtPosition(i,this.getPosition(t,o),u.maximumHoverLength,t.verbosityLevel);if(!d)return;let p=!!u.displayPartsForJSDoc;if(n){let x=h7(d.displayParts);return{kind:d.kind,kindModifiers:d.kindModifiers,start:o.positionToLineOffset(d.textSpan.start),end:o.positionToLineOffset(Pc(d.textSpan)),displayString:x,documentation:p?this.mapDisplayParts(d.documentation,s):h7(d.documentation),tags:this.mapJSDocTagInfo(d.tags,s,p),canIncreaseVerbosityLevel:d.canIncreaseVerbosityLevel}}else return p?d:{...d,tags:this.mapJSDocTagInfo(d.tags,s,!1)}}getFormattingEditsForRange(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.projectService.getScriptInfoForNormalizedPath(n),o=s.lineOffsetToPosition(t.line,t.offset),u=s.lineOffsetToPosition(t.endLine,t.endOffset),d=i.getFormattingEditsForRange(n,o,u,this.getFormatOptions(n));if(d)return d.map(p=>this.convertTextChangeToCodeEdit(p,s))}getFormattingEditsForRangeFull(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=t.options?h6(t.options):this.getFormatOptions(n);return i.getFormattingEditsForRange(n,t.position,t.endPosition,s)}getFormattingEditsForDocumentFull(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=t.options?h6(t.options):this.getFormatOptions(n);return i.getFormattingEditsForDocument(n,s)}getFormattingEditsAfterKeystrokeFull(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=t.options?h6(t.options):this.getFormatOptions(n);return i.getFormattingEditsAfterKeystroke(n,t.position,t.key,s)}getFormattingEditsAfterKeystroke(t){let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(t),s=this.projectService.getScriptInfoForNormalizedPath(n),o=s.lineOffsetToPosition(t.line,t.offset),u=this.getFormatOptions(n),d=i.getFormattingEditsAfterKeystroke(n,o,t.key,u);if(t.key===`
|
|
432
432
|
`&&(!d||d.length===0||o1t(d,o))){let{lineText:p,absolutePosition:x}=s.textStorage.getAbsolutePositionAndLineText(t.line);if(p&&p.search("\\S")<0){let b=i.getIndentationAtPosition(n,o,u),T=0,E,P;for(E=0,P=p.length;E<P;E++)if(p.charAt(E)===" ")T++;else if(p.charAt(E)===" ")T+=u.tabSize;else break;if(b!==T){let N=x+E;d.push({span:al(x,N),newText:Fl.getIndentationString(b,u)})}}}if(d)return d.map(p=>({start:s.positionToLineOffset(p.span.start),end:s.positionToLineOffset(Pc(p.span)),newText:p.newText?p.newText:""}))}getCompletions(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=this.projectService.getScriptInfoForNormalizedPath(i),u=this.getPosition(t,o),d=s.getLanguageService().getCompletionsAtPosition(i,u,{...rve(this.getPreferences(i)),triggerCharacter:t.triggerCharacter,triggerKind:t.triggerKind,includeExternalModuleExports:t.includeExternalModuleExports,includeInsertTextCompletions:t.includeInsertTextCompletions},s.projectService.getFormatCodeOptions(i));if(d===void 0)return;if(n==="completions-full")return d;let p=t.prefix||"",x=rs(d.entries,T=>{if(d.isMemberCompletion||us(T.name.toLowerCase(),p.toLowerCase())){let E=T.replacementSpan?Tg(T.replacementSpan,o):void 0;return{...T,replacementSpan:E,hasAction:T.hasAction||void 0,symbol:void 0}}});return n==="completions"?(d.metadata&&(x.metadata=d.metadata),x):{...d,optionalReplacementSpan:d.optionalReplacementSpan&&Tg(d.optionalReplacementSpan,o),entries:x}}getCompletionEntryDetails(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=this.projectService.getScriptInfoForNormalizedPath(i),u=this.getPosition(t,o),d=s.projectService.getFormatCodeOptions(i),p=!!this.getPreferences(i).displayPartsForJSDoc,x=rs(t.entryNames,b=>{let{name:T,source:E,data:P}=typeof b=="string"?{name:b,source:void 0,data:void 0}:b;return s.getLanguageService().getCompletionEntryDetails(i,u,T,d,E,this.getPreferences(i),P?fa(P,S1t):void 0)});return n?p?x:x.map(b=>({...b,tags:this.mapJSDocTagInfo(b.tags,s,!1)})):x.map(b=>({...b,codeActions:Nr(b.codeActions,T=>this.mapCodeAction(T)),documentation:this.mapDisplayParts(b.documentation,s),tags:this.mapJSDocTagInfo(b.tags,s,p)}))}getCompileOnSaveAffectedFileList(t){let n=this.getProjects(t,!0,!0),i=this.projectService.getScriptInfo(t.file);return i?l1t(i,s=>this.projectService.getScriptInfoForPath(s),n,(s,o)=>{if(!s.compileOnSaveEnabled||!s.languageServiceEnabled||s.isOrphan())return;let u=s.getCompilationSettings();if(!(u.noEmit||uu(o.fileName)&&!a1t(u)))return{projectFileName:s.getProjectName(),fileNames:s.getCompileOnSaveAffectedFileList(o),projectUsesOutFile:!!u.outFile}}):Ql}emitFile(t){let{file:n,project:i}=this.getFileAndProject(t);if(i||Jy.ThrowNoProject(),!i.languageServiceEnabled)return t.richResponse?{emitSkipped:!0,diagnostics:[]}:!1;let s=i.getScriptInfo(n),{emitSkipped:o,diagnostics:u}=i.emitFile(s,(d,p,x)=>this.host.writeFile(d,p,x));return t.richResponse?{emitSkipped:o,diagnostics:t.includeLinePosition?this.convertToDiagnosticsWithLinePositionFromDiagnosticFile(u):u.map(d=>G7(d,!0))}:!o}getSignatureHelpItems(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=this.projectService.getScriptInfoForNormalizedPath(i),u=this.getPosition(t,o),d=s.getLanguageService().getSignatureHelpItems(i,u,t),p=!!this.getPreferences(i).displayPartsForJSDoc;if(d&&n){let x=d.applicableSpan;return{...d,applicableSpan:{start:o.positionToLineOffset(x.start),end:o.positionToLineOffset(x.start+x.length)},items:this.mapSignatureHelpItems(d.items,s,p)}}else return p||!d?d:{...d,items:d.items.map(x=>({...x,tags:this.mapJSDocTagInfo(x.tags,s,!1)}))}}toPendingErrorCheck(t){let n=Po(t),i=this.projectService.tryGetDefaultProjectForFile(n);return i&&{fileName:n,project:i}}getDiagnostics(t,n,i){this.suppressDiagnosticEvents||i.length>0&&this.updateErrorCheck(t,i,n)}change(t){let n=this.projectService.getScriptInfo(t.file);O.assert(!!n),n.textStorage.switchToScriptVersionCache();let i=n.lineOffsetToPosition(t.line,t.offset),s=n.lineOffsetToPosition(t.endLine,t.endOffset);i>=0&&(this.changeSeq++,this.projectService.applyChangesToFile(n,aie({span:{start:i,length:s-i},newText:t.insertString})))}reload(t){let n=Po(t.file),i=t.tmpfile===void 0?void 0:Po(t.tmpfile),s=this.projectService.getScriptInfoForNormalizedPath(n);s&&(this.changeSeq++,s.reloadFromFile(i))}saveToTmp(t,n){let i=this.projectService.getScriptInfo(t);i&&i.saveTo(n)}closeClientFile(t){if(!t)return;let n=ma(t);this.projectService.closeClientFile(n)}mapLocationNavigationBarItems(t,n){return Nr(t,i=>({text:i.text,kind:i.kind,kindModifiers:i.kindModifiers,spans:i.spans.map(s=>Tg(s,n)),childItems:this.mapLocationNavigationBarItems(i.childItems,n),indent:i.indent}))}getNavigationBarItems(t,n){let{file:i,languageService:s}=this.getFileAndLanguageServiceForSyntacticOperation(t),o=s.getNavigationBarItems(i);return o?n?this.mapLocationNavigationBarItems(o,this.projectService.getScriptInfoForNormalizedPath(i)):o:void 0}toLocationNavigationTree(t,n){return{text:t.text,kind:t.kind,kindModifiers:t.kindModifiers,spans:t.spans.map(i=>Tg(i,n)),nameSpan:t.nameSpan&&Tg(t.nameSpan,n),childItems:Nr(t.childItems,i=>this.toLocationNavigationTree(i,n))}}getNavigationTree(t,n){let{file:i,languageService:s}=this.getFileAndLanguageServiceForSyntacticOperation(t),o=s.getNavigationTree(i);return o?n?this.toLocationNavigationTree(o,this.projectService.getScriptInfoForNormalizedPath(i)):o:void 0}getNavigateToItems(t,n){let i=this.getFullNavigateToItems(t);return n?Ha(i,({project:s,navigateToItems:o})=>o.map(u=>{let d=s.getScriptInfo(u.fileName),p={name:u.name,kind:u.kind,kindModifiers:u.kindModifiers,isCaseSensitive:u.isCaseSensitive,matchKind:u.matchKind,file:u.fileName,start:d.positionToLineOffset(u.textSpan.start),end:d.positionToLineOffset(Pc(u.textSpan))};return u.kindModifiers&&u.kindModifiers!==""&&(p.kindModifiers=u.kindModifiers),u.containerName&&u.containerName.length>0&&(p.containerName=u.containerName),u.containerKind&&u.containerKind.length>0&&(p.containerKind=u.containerKind),p})):Ha(i,({navigateToItems:s})=>s)}getFullNavigateToItems(t){let{currentFileOnly:n,searchValue:i,maxResultCount:s,projectFileName:o}=t;if(n){O.assertIsDefined(t.file);let{file:E,project:P}=this.getFileAndProject(t);return[{project:P,navigateToItems:P.getLanguageService().getNavigateToItems(i,s,E)}]}let u=this.getHostPreferences(),d=[],p=new Map;if(!t.file&&!o)this.projectService.loadAncestorProjectTree(),this.projectService.forEachEnabledProject(E=>x(E));else{let E=this.getProjects(t);Uje(E,void 0,P=>x(P))}return d;function x(E){let P=E.getLanguageService().getNavigateToItems(i,s,void 0,E.isNonTsProject(),u.excludeLibrarySymbolsInNavTo),N=Jn(P,F=>b(F)&&!ZQ(yN(F),E));N.length&&d.push({project:E,navigateToItems:N})}function b(E){let P=E.name;if(!p.has(P))return p.set(P,[E]),!0;let N=p.get(P);for(let F of N)if(T(F,E))return!1;return N.push(E),!0}function T(E,P){return E===P?!0:!E||!P?!1:E.containerKind===P.containerKind&&E.containerName===P.containerName&&E.fileName===P.fileName&&E.isCaseSensitive===P.isCaseSensitive&&E.kind===P.kind&&E.kindModifiers===P.kindModifiers&&E.matchKind===P.matchKind&&E.name===P.name&&E.textSpan.start===P.textSpan.start&&E.textSpan.length===P.textSpan.length}}getSupportedCodeFixes(t){if(!t)return fX();if(t.file){let{file:i,project:s}=this.getFileAndProject(t);return s.getLanguageService().getSupportedCodeFixes(i)}let n=this.getProject(t.projectFileName);return n||Jy.ThrowNoProject(),n.getLanguageService().getSupportedCodeFixes()}isLocation(t){return t.line!==void 0}extractPositionOrRange(t,n){let i,s;return this.isLocation(t)?i=o(t):s=this.getRange(t,n),O.checkDefined(i===void 0?s:i);function o(u){return u.position!==void 0?u.position:n.lineOffsetToPosition(u.line,u.offset)}}getRange(t,n){let{startPosition:i,endPosition:s}=this.getStartAndEndPosition(t,n);return{pos:i,end:s}}getApplicableRefactors(t){let{file:n,project:i}=this.getFileAndProject(t),s=i.getScriptInfoForNormalizedPath(n);return i.getLanguageService().getApplicableRefactors(n,this.extractPositionOrRange(t,s),this.getPreferences(n),t.triggerReason,t.kind,t.includeInteractiveActions).map(u=>({...u,actions:u.actions.map(d=>({...d,range:d.range?{start:y6({line:d.range.start.line,character:d.range.start.offset}),end:y6({line:d.range.end.line,character:d.range.end.offset})}:void 0}))}))}getEditsForRefactor(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=s.getScriptInfoForNormalizedPath(i),u=s.getLanguageService().getEditsForRefactor(i,this.getFormatOptions(i),this.extractPositionOrRange(t,o),t.refactor,t.action,this.getPreferences(i),t.interactiveRefactorArguments);if(u===void 0)return{edits:[]};if(n){let{renameFilename:d,renameLocation:p,edits:x}=u,b;if(d!==void 0&&p!==void 0){let T=s.getScriptInfoForNormalizedPath(Po(d));b=xve(dw(T.getSnapshot()),d,p,x)}return{renameLocation:b,renameFilename:d,edits:this.mapTextChangesToCodeEdits(x),notApplicableReason:u.notApplicableReason}}return u}getMoveToRefactoringFileSuggestions(t){let{file:n,project:i}=this.getFileAndProject(t),s=i.getScriptInfoForNormalizedPath(n);return i.getLanguageService().getMoveToRefactoringFileSuggestions(n,this.extractPositionOrRange(t,s),this.getPreferences(n))}preparePasteEdits(t){let{file:n,project:i}=this.getFileAndProject(t);return i.getLanguageService().preparePasteEditsForFile(n,t.copiedTextSpan.map(s=>this.getRange({file:n,startLine:s.start.line,startOffset:s.start.offset,endLine:s.end.line,endOffset:s.end.offset},this.projectService.getScriptInfoForNormalizedPath(n))))}getPasteEdits(t){let{file:n,project:i}=this.getFileAndProject(t);if(gN(n))return;let s=t.copiedFrom?{file:t.copiedFrom.file,range:t.copiedFrom.spans.map(u=>this.getRange({file:t.copiedFrom.file,startLine:u.start.line,startOffset:u.start.offset,endLine:u.end.line,endOffset:u.end.offset},i.getScriptInfoForNormalizedPath(Po(t.copiedFrom.file))))}:void 0,o=i.getLanguageService().getPasteEdits({targetFile:n,pastedText:t.pastedText,pasteLocations:t.pasteLocations.map(u=>this.getRange({file:n,startLine:u.start.line,startOffset:u.start.offset,endLine:u.end.line,endOffset:u.end.offset},i.getScriptInfoForNormalizedPath(n))),copiedFrom:s,preferences:this.getPreferences(n)},this.getFormatOptions(n));return o&&this.mapPasteEditsAction(o)}organizeImports(t,n){O.assert(t.scope.type==="file");let{file:i,project:s}=this.getFileAndProject(t.scope.args),o=s.getLanguageService().organizeImports({fileName:i,mode:t.mode??(t.skipDestructiveCodeActions?"SortAndCombine":void 0),type:"file"},this.getFormatOptions(i),this.getPreferences(i));return n?this.mapTextChangesToCodeEdits(o):o}getEditsForFileRename(t,n){let i=Po(t.oldFilePath),s=Po(t.newFilePath),o=this.getHostFormatOptions(),u=this.getHostPreferences(),d=new Set,p=[];return this.projectService.loadAncestorProjectTree(),this.projectService.forEachEnabledProject(x=>{let b=x.getLanguageService().getEditsForFileRename(i,s,o,u),T=[];for(let E of b)d.has(E.fileName)||(p.push(E),T.push(E.fileName));for(let E of T)d.add(E)}),n?p.map(x=>this.mapTextChangeToCodeEdit(x)):p}getCodeFixes(t,n){let{file:i,project:s}=this.getFileAndProject(t),o=s.getScriptInfoForNormalizedPath(i),{startPosition:u,endPosition:d}=this.getStartAndEndPosition(t,o),p;try{p=s.getLanguageService().getCodeFixesAtPosition(i,u,d,t.errorCodes,this.getFormatOptions(i),this.getPreferences(i))}catch(x){let b=x instanceof Error?x:new Error(x),T=s.getLanguageService(),E=[...T.getSyntacticDiagnostics(i),...T.getSemanticDiagnostics(i),...T.getSuggestionDiagnostics(i)].filter(N=>a3(u,d-u,N.start,N.length)).map(N=>N.code),P=t.errorCodes.find(N=>!E.includes(N));throw P!==void 0&&(b.message+=`
|
|
433
433
|
Additional information: BADCLIENT: Bad error code, ${P} not found in range ${u}..${d} (found: ${E.join(", ")})`),b}return n?p.map(x=>this.mapCodeFixAction(x)):p}getCombinedCodeFix({scope:t,fixId:n},i){O.assert(t.type==="file");let{file:s,project:o}=this.getFileAndProject(t.args),u=o.getLanguageService().getCombinedCodeFix({type:"file",fileName:s},n,this.getFormatOptions(s),this.getPreferences(s));return i?{changes:this.mapTextChangesToCodeEdits(u.changes),commands:u.commands}:u}applyCodeActionCommand(t){let n=t.command;for(let i of Qk(n)){let{file:s,project:o}=this.getFileAndProject(i);o.getLanguageService().applyCodeActionCommand(i,this.getFormatOptions(s)).then(u=>{},u=>{})}return{}}getStartAndEndPosition(t,n){let i,s;return t.startPosition!==void 0?i=t.startPosition:(i=n.lineOffsetToPosition(t.startLine,t.startOffset),t.startPosition=i),t.endPosition!==void 0?s=t.endPosition:(s=n.lineOffsetToPosition(t.endLine,t.endOffset),t.endPosition=s),{startPosition:i,endPosition:s}}mapCodeAction({description:t,changes:n,commands:i}){return{description:t,changes:this.mapTextChangesToCodeEdits(n),commands:i}}mapCodeFixAction({fixName:t,description:n,changes:i,commands:s,fixId:o,fixAllDescription:u}){return{fixName:t,description:n,changes:this.mapTextChangesToCodeEdits(i),commands:s,fixId:o,fixAllDescription:u}}mapPasteEditsAction({edits:t,fixId:n}){return{edits:this.mapTextChangesToCodeEdits(t),fixId:n}}mapTextChangesToCodeEdits(t){return t.map(n=>this.mapTextChangeToCodeEdit(n))}mapTextChangeToCodeEdit(t){let n=this.projectService.getScriptInfoOrConfig(t.fileName);return!!t.isNewFile==!!n&&(n||this.projectService.logErrorForScriptInfoNotFound(t.fileName),O.fail("Expected isNewFile for (only) new files. "+JSON.stringify({isNewFile:!!t.isNewFile,hasScriptInfo:!!n}))),n?{fileName:t.fileName,textChanges:t.textChanges.map(i=>m1t(i,n))}:y1t(t)}convertTextChangeToCodeEdit(t,n){return{start:n.positionToLineOffset(t.span.start),end:n.positionToLineOffset(t.span.start+t.span.length),newText:t.newText?t.newText:""}}getBraceMatching(t,n){let{file:i,languageService:s}=this.getFileAndLanguageServiceForSyntacticOperation(t),o=this.projectService.getScriptInfoForNormalizedPath(i),u=this.getPosition(t,o),d=s.getBraceMatchingAtPosition(i,u);return d?n?d.map(p=>Tg(p,o)):d:void 0}getDiagnosticsForProject(t,n,i){if(this.suppressDiagnosticEvents)return;let{fileNames:s,languageServiceDisabled:o}=this.getProjectInfoWorker(i,void 0,!0,void 0,!0);if(o)return;let u=s.filter(F=>!F.includes("lib.d.ts"));if(u.length===0)return;let d=[],p=[],x=[],b=[],T=Po(i),E=this.projectService.ensureDefaultProjectForFile(T);for(let F of u)this.getCanonicalFileName(F)===this.getCanonicalFileName(i)?d.push(F):this.projectService.getScriptInfo(F).isScriptOpen()?p.push(F):uu(F)?b.push(F):x.push(F);let N=[...d,...p,...x,...b].map(F=>({fileName:F,project:E}));this.updateErrorCheck(t,N,n,!1)}configurePlugin(t){this.projectService.configurePlugin(t)}getSmartSelectionRange(t,n){let{locations:i}=t,{file:s,languageService:o}=this.getFileAndLanguageServiceForSyntacticOperation(t),u=O.checkDefined(this.projectService.getScriptInfo(s));return Nr(i,d=>{let p=this.getPosition(d,u),x=o.getSmartSelectionRange(s,p);return n?this.mapSelectionRange(x,u):x})}toggleLineComment(t,n){let{file:i,languageService:s}=this.getFileAndLanguageServiceForSyntacticOperation(t),o=this.projectService.getScriptInfo(i),u=this.getRange(t,o),d=s.toggleLineComment(i,u);if(n){let p=this.projectService.getScriptInfoForNormalizedPath(i);return d.map(x=>this.convertTextChangeToCodeEdit(x,p))}return d}toggleMultilineComment(t,n){let{file:i,languageService:s}=this.getFileAndLanguageServiceForSyntacticOperation(t),o=this.projectService.getScriptInfoForNormalizedPath(i),u=this.getRange(t,o),d=s.toggleMultilineComment(i,u);if(n){let p=this.projectService.getScriptInfoForNormalizedPath(i);return d.map(x=>this.convertTextChangeToCodeEdit(x,p))}return d}commentSelection(t,n){let{file:i,languageService:s}=this.getFileAndLanguageServiceForSyntacticOperation(t),o=this.projectService.getScriptInfoForNormalizedPath(i),u=this.getRange(t,o),d=s.commentSelection(i,u);if(n){let p=this.projectService.getScriptInfoForNormalizedPath(i);return d.map(x=>this.convertTextChangeToCodeEdit(x,p))}return d}uncommentSelection(t,n){let{file:i,languageService:s}=this.getFileAndLanguageServiceForSyntacticOperation(t),o=this.projectService.getScriptInfoForNormalizedPath(i),u=this.getRange(t,o),d=s.uncommentSelection(i,u);if(n){let p=this.projectService.getScriptInfoForNormalizedPath(i);return d.map(x=>this.convertTextChangeToCodeEdit(x,p))}return d}mapSelectionRange(t,n){let i={textSpan:Tg(t.textSpan,n)};return t.parent&&(i.parent=this.mapSelectionRange(t.parent,n)),i}getScriptInfoFromProjectService(t){let n=Po(t),i=this.projectService.getScriptInfoForNormalizedPath(n);return i||(this.projectService.logErrorForScriptInfoNotFound(n),Jy.ThrowNoProject())}toProtocolCallHierarchyItem(t){let n=this.getScriptInfoFromProjectService(t.file);return{name:t.name,kind:t.kind,kindModifiers:t.kindModifiers,file:t.file,containerName:t.containerName,span:Tg(t.span,n),selectionSpan:Tg(t.selectionSpan,n)}}toProtocolCallHierarchyIncomingCall(t){let n=this.getScriptInfoFromProjectService(t.from.file);return{from:this.toProtocolCallHierarchyItem(t.from),fromSpans:t.fromSpans.map(i=>Tg(i,n))}}toProtocolCallHierarchyOutgoingCall(t,n){return{to:this.toProtocolCallHierarchyItem(t.to),fromSpans:t.fromSpans.map(i=>Tg(i,n))}}prepareCallHierarchy(t){let{file:n,project:i}=this.getFileAndProject(t),s=this.projectService.getScriptInfoForNormalizedPath(n);if(s){let o=this.getPosition(t,s),u=i.getLanguageService().prepareCallHierarchy(n,o);return u&&xK(u,d=>this.toProtocolCallHierarchyItem(d))}}provideCallHierarchyIncomingCalls(t){let{file:n,project:i}=this.getFileAndProject(t),s=this.getScriptInfoFromProjectService(n);return i.getLanguageService().provideCallHierarchyIncomingCalls(n,this.getPosition(t,s)).map(u=>this.toProtocolCallHierarchyIncomingCall(u))}provideCallHierarchyOutgoingCalls(t){let{file:n,project:i}=this.getFileAndProject(t),s=this.getScriptInfoFromProjectService(n);return i.getLanguageService().provideCallHierarchyOutgoingCalls(n,this.getPosition(t,s)).map(u=>this.toProtocolCallHierarchyOutgoingCall(u,s))}getCanonicalFileName(t){let n=this.host.useCaseSensitiveFileNames?t:jv(t);return ma(n)}exit(){}notRequired(t){return t&&this.doOutput(void 0,t.command,t.seq,!0,this.performanceData),{responseRequired:!1,performanceData:this.performanceData}}requiredResponse(t){return{response:t,responseRequired:!0,performanceData:this.performanceData}}addProtocolHandler(t,n){if(this.handlers.has(t))throw new Error(`Protocol handler already exists for command "${t}"`);this.handlers.set(t,n)}setCurrentRequest(t){O.assert(this.currentRequestId===void 0),this.currentRequestId=t,this.cancellationToken.setRequest(t)}resetCurrentRequest(t){O.assert(this.currentRequestId===t),this.currentRequestId=void 0,this.cancellationToken.resetRequest(t)}executeWithRequestId(t,n,i){let s=this.performanceData;try{return this.performanceData=i,this.setCurrentRequest(t),n()}finally{this.resetCurrentRequest(t),this.performanceData=s}}executeCommand(t){let n=this.handlers.get(t.command);if(n){let i=this.executeWithRequestId(t.seq,()=>n(t),void 0);return this.projectService.enableRequestedPlugins(),i}else return this.logger.msg(`Unrecognized JSON command:${Hb(t)}`,"Err"),this.doOutput(void 0,"unknown",t.seq,!1,void 0,`Unrecognized JSON command: ${t.command}`),{responseRequired:!1}}onMessage(t){var n,i,s,o,u,d,p;this.gcTimer.scheduleCollect();let x,b=this.performanceData;this.logger.hasLevel(2)&&(x=this.hrtime(),this.logger.hasLevel(3)&&this.logger.info(`request:${J4(this.toStringMessage(t))}`));let T,E;try{T=this.parseMessage(t),E=T.arguments&&T.arguments.file?T.arguments:void 0,(n=kn)==null||n.instant(kn.Phase.Session,"request",{seq:T.seq,command:T.command}),(i=kn)==null||i.push(kn.Phase.Session,"executeCommand",{seq:T.seq,command:T.command},!0);let{response:P,responseRequired:N,performanceData:F}=this.executeCommand(T);if((s=kn)==null||s.pop(),this.logger.hasLevel(2)){let M=s1t(this.hrtime(x)).toFixed(4);N?this.logger.perftrc(`${T.seq}::${T.command}: elapsed time (in milliseconds) ${M}`):this.logger.perftrc(`${T.seq}::${T.command}: async elapsed time (in milliseconds) ${M}`)}(o=kn)==null||o.instant(kn.Phase.Session,"response",{seq:T.seq,command:T.command,success:!!P}),P?this.doOutput(P,T.command,T.seq,!0,F):N&&this.doOutput(void 0,T.command,T.seq,!1,F,"No content available.")}catch(P){if((u=kn)==null||u.popAll(),P instanceof jP){(d=kn)==null||d.instant(kn.Phase.Session,"commandCanceled",{seq:T==null?void 0:T.seq,command:T==null?void 0:T.command}),this.doOutput({canceled:!0},T.command,T.seq,!0,this.performanceData);return}this.logErrorWorker(P,this.toStringMessage(t),E),(p=kn)==null||p.instant(kn.Phase.Session,"commandError",{seq:T==null?void 0:T.seq,command:T==null?void 0:T.command,message:P.message}),this.doOutput(void 0,T?T.command:"unknown",T?T.seq:0,!1,this.performanceData,"Error processing request. "+P.message+`
|
|
434
|
-
`+P.stack)}finally{this.performanceData=b}}parseMessage(t){return JSON.parse(t)}toStringMessage(t){return t}getFormatOptions(t){return this.projectService.getFormatCodeOptions(t)}getPreferences(t){return this.projectService.getPreferences(t)}getHostFormatOptions(){return this.projectService.getHostFormatCodeOptions()}getHostPreferences(){return this.projectService.getHostPreferences()}};function Kje(e){let t=e.diagnosticsDuration&&Es(e.diagnosticsDuration,([n,i])=>({...i,file:n}));return{...e,diagnosticsDuration:t}}function Tg(e,t){return{start:t.positionToLineOffset(e.start),end:t.positionToLineOffset(Pc(e))}}function Sve(e,t,n){let i=Tg(e,n),s=t&&Tg(t,n);return s?{...i,contextStart:s.start,contextEnd:s.end}:i}function m1t(e,t){return{start:Xje(t,e.span.start),end:Xje(t,Pc(e.span)),newText:e.newText}}function Xje(e,t){return dve(e)?h1t(e.getLineAndCharacterOfPosition(t)):e.positionToLineOffset(t)}function g1t(e,t){let n=e.ranges.map(i=>({start:t.positionToLineOffset(i.start),end:t.positionToLineOffset(i.start+i.length)}));return e.wordPattern?{ranges:n,wordPattern:e.wordPattern}:{ranges:n}}function h1t(e){return{line:e.line+1,offset:e.character+1}}function y1t(e){O.assert(e.textChanges.length===1);let t=Za(e.textChanges);return O.assert(t.span.start===0&&t.span.length===0),{fileName:e.fileName,textChanges:[{start:{line:0,offset:0},end:{line:0,offset:0},newText:t.newText}]}}function xve(e,t,n,i){let s=v1t(e,t,i),{line:o,character:u}=OE(sC(s),n);return{line:o+1,offset:u+1}}function v1t(e,t,n){for(let{fileName:i,textChanges:s}of n)if(i===t)for(let o=s.length-1;o>=0;o--){let{newText:u,span:{start:d,length:p}}=s[o];e=e.slice(0,d)+u+e.slice(d+p)}return e}function Qje(e,{fileName:t,textSpan:n,contextSpan:i,isWriteAccess:s,isDefinition:o},{disableLineTextInReferences:u}){let d=O.checkDefined(e.getScriptInfo(t)),p=Sve(n,i,d),x=u?void 0:b1t(d,p);return{file:t,...p,lineText:x,isWriteAccess:s,isDefinition:o}}function b1t(e,t){let n=e.lineToTextSpan(t.start.line-1);return e.getSnapshot().getText(n.start,Pc(n)).replace(/\r|\n/g,"")}function S1t(e){return e===void 0||e&&typeof e=="object"&&typeof e.exportName=="string"&&(e.fileName===void 0||typeof e.fileName=="string")&&(e.ambientModuleName===void 0||typeof e.ambientModuleName=="string"&&(e.isPackageJsonImport===void 0||typeof e.isPackageJsonImport=="boolean"))}var v6=4,Tve=(e=>(e[e.PreStart=0]="PreStart",e[e.Start=1]="Start",e[e.Entire=2]="Entire",e[e.Mid=3]="Mid",e[e.End=4]="End",e[e.PostEnd=5]="PostEnd",e))(Tve||{}),x1t=class{constructor(){this.goSubtree=!0,this.lineIndex=new H7,this.endBranch=[],this.state=2,this.initialText="",this.trailingText="",this.lineIndex.root=new b6,this.startPath=[this.lineIndex.root],this.stack=[this.lineIndex.root]}get done(){return!1}insertLines(e,t){t&&(this.trailingText=""),e?e=this.initialText+e+this.trailingText:e=this.initialText+this.trailingText;let i=H7.linesFromText(e).lines;i.length>1&&i[i.length-1]===""&&i.pop();let s,o;for(let d=this.endBranch.length-1;d>=0;d--)this.endBranch[d].updateCounts(),this.endBranch[d].charCount()===0&&(o=this.endBranch[d],d>0?s=this.endBranch[d-1]:s=this.branchNode);o&&s.remove(o);let u=this.startPath[this.startPath.length-1];if(i.length>0)if(u.text=i[0],i.length>1){let d=new Array(i.length-1),p=u;for(let T=1;T<i.length;T++)d[T-1]=new K$(i[T]);let x=this.startPath.length-2;for(;x>=0;){let T=this.startPath[x];d=T.insertAt(p,d),x--,p=T}let b=d.length;for(;b>0;){let T=new b6;T.add(this.lineIndex.root),d=T.insertAt(this.lineIndex.root,d),b=d.length,this.lineIndex.root=T}this.lineIndex.root.updateCounts()}else for(let d=this.startPath.length-2;d>=0;d--)this.startPath[d].updateCounts();else{this.startPath[this.startPath.length-2].remove(u);for(let p=this.startPath.length-2;p>=0;p--)this.startPath[p].updateCounts()}return this.lineIndex}post(e,t,n){n===this.lineCollectionAtBranch&&(this.state=4),this.stack.pop()}pre(e,t,n,i,s){let o=this.stack[this.stack.length-1];this.state===2&&s===1&&(this.state=1,this.branchNode=o,this.lineCollectionAtBranch=n);let u;function d(p){return p.isLeaf()?new K$(""):new b6}switch(s){case 0:this.goSubtree=!1,this.state!==4&&o.add(n);break;case 1:this.state===4?this.goSubtree=!1:(u=d(n),o.add(u),this.startPath.push(u));break;case 2:this.state!==4?(u=d(n),o.add(u),this.startPath.push(u)):n.isLeaf()||(u=d(n),o.add(u),this.endBranch.push(u));break;case 3:this.goSubtree=!1;break;case 4:this.state!==4?this.goSubtree=!1:n.isLeaf()||(u=d(n),o.add(u),this.endBranch.push(u));break;case 5:this.goSubtree=!1,this.state!==1&&o.add(n);break}this.goSubtree&&this.stack.push(u)}leaf(e,t,n){this.state===1?this.initialText=n.text.substring(0,e):this.state===2?(this.initialText=n.text.substring(0,e),this.trailingText=n.text.substring(e+t)):this.trailingText=n.text.substring(e+t)}},T1t=class{constructor(e,t,n){this.pos=e,this.deleteLen=t,this.insertedText=n}getTextChangeRange(){return o3(Ou(this.pos,this.deleteLen),this.insertedText?this.insertedText.length:0)}},KQ=class qk{constructor(){this.changes=[],this.versions=new Array(qk.maxVersions),this.minVersion=0,this.currentVersion=0}versionToIndex(t){if(!(t<this.minVersion||t>this.currentVersion))return t%qk.maxVersions}currentVersionToIndex(){return this.currentVersion%qk.maxVersions}edit(t,n,i){this.changes.push(new T1t(t,n,i)),(this.changes.length>qk.changeNumberThreshold||n>qk.changeLengthThreshold||i&&i.length>qk.changeLengthThreshold)&&this.getSnapshot()}getSnapshot(){return this._getSnapshot()}_getSnapshot(){let t=this.versions[this.currentVersionToIndex()];if(this.changes.length>0){let n=t.index;for(let i of this.changes)n=n.edit(i.pos,i.deleteLen,i.insertedText);t=new Yje(this.currentVersion+1,this,n,this.changes),this.currentVersion=t.version,this.versions[this.currentVersionToIndex()]=t,this.changes=[],this.currentVersion-this.minVersion>=qk.maxVersions&&(this.minVersion=this.currentVersion-qk.maxVersions+1)}return t}getSnapshotVersion(){return this._getSnapshot().version}getAbsolutePositionAndLineText(t){return this._getSnapshot().index.lineNumberToInfo(t)}lineOffsetToPosition(t,n){return this._getSnapshot().index.absolutePositionOfStartOfLine(t)+(n-1)}positionToLineOffset(t){return this._getSnapshot().index.positionToLineOffset(t)}lineToTextSpan(t){let n=this._getSnapshot().index,{lineText:i,absolutePosition:s}=n.lineNumberToInfo(t+1),o=i!==void 0?i.length:n.absolutePositionOfStartOfLine(t+2)-s;return Ou(s,o)}getTextChangesBetweenVersions(t,n){if(t<n)if(t>=this.minVersion){let i=[];for(let s=t+1;s<=n;s++){let o=this.versions[this.versionToIndex(s)];for(let u of o.changesSincePreviousVersion)i.push(u.getTextChangeRange())}return aae(i)}else return;else return T9}getLineCount(){return this._getSnapshot().index.getLineCount()}static fromString(t){let n=new qk,i=new Yje(0,n,new H7);n.versions[n.currentVersion]=i;let s=H7.linesFromText(t);return i.index.load(s.lines),n}};KQ.changeNumberThreshold=8,KQ.changeLengthThreshold=256,KQ.maxVersions=8;var XQ=KQ,Yje=class hQe{constructor(t,n,i,s=Ql){this.version=t,this.cache=n,this.index=i,this.changesSincePreviousVersion=s}getText(t,n){return this.index.getText(t,n-t)}getLength(){return this.index.getLength()}getChangeRange(t){if(t instanceof hQe&&this.cache===t.cache)return this.version<=t.version?T9:this.cache.getTextChangesBetweenVersions(t.version,this.version)}},H7=class DEe{constructor(){this.checkEdits=!1}absolutePositionOfStartOfLine(t){return this.lineNumberToInfo(t).absolutePosition}positionToLineOffset(t){let{oneBasedLine:n,zeroBasedColumn:i}=this.root.charOffsetToLineInfo(1,t);return{line:n,offset:i+1}}positionToColumnAndLineText(t){return this.root.charOffsetToLineInfo(1,t)}getLineCount(){return this.root.lineCount()}lineNumberToInfo(t){let n=this.getLineCount();if(t<=n){let{position:i,leaf:s}=this.root.lineNumberToInfo(t,0);return{absolutePosition:i,lineText:s&&s.text}}else return{absolutePosition:this.root.charCount(),lineText:void 0}}load(t){if(t.length>0){let n=[];for(let i=0;i<t.length;i++)n[i]=new K$(t[i]);this.root=DEe.buildTreeFromBottom(n)}else this.root=new b6}walk(t,n,i){this.root.walk(t,n,i)}getText(t,n){let i="";return n>0&&t<this.root.charCount()&&this.walk(t,n,{goSubtree:!0,done:!1,leaf:(s,o,u)=>{i=i.concat(u.text.substring(s,s+o))}}),i}getLength(){return this.root.charCount()}every(t,n,i){i||(i=this.root.charCount());let s={goSubtree:!0,done:!1,leaf(o,u,d){t(d,o,u)||(this.done=!0)}};return this.walk(n,i-n,s),!s.done}edit(t,n,i){if(this.root.charCount()===0)return O.assert(n===0),i!==void 0?(this.load(DEe.linesFromText(i).lines),this):void 0;{let s;if(this.checkEdits){let d=this.getText(0,this.root.charCount());s=d.slice(0,t)+i+d.slice(t+n)}let o=new x1t,u=!1;if(t>=this.root.charCount()){t=this.root.charCount()-1;let d=this.getText(t,1);i?i=d+i:i=d,n=0,u=!0}else if(n>0){let d=t+n,{zeroBasedColumn:p,lineText:x}=this.positionToColumnAndLineText(d);p===0&&(n+=x.length,i=i?i+x:x)}if(this.root.walk(t,n,o),o.insertLines(i,u),this.checkEdits){let d=o.lineIndex.getText(0,o.lineIndex.getLength());O.assert(s===d,"buffer edit mismatch")}return o.lineIndex}}static buildTreeFromBottom(t){if(t.length<v6)return new b6(t);let n=new Array(Math.ceil(t.length/v6)),i=0;for(let s=0;s<n.length;s++){let o=Math.min(i+v6,t.length);n[s]=new b6(t.slice(i,o)),i=o}return this.buildTreeFromBottom(n)}static linesFromText(t){let n=sC(t);if(n.length===0)return{lines:[],lineMap:n};let i=new Array(n.length),s=n.length-1;for(let u=0;u<s;u++)i[u]=t.substring(n[u],n[u+1]);let o=t.substring(n[s]);return o.length>0?i[s]=o:i.pop(),{lines:i,lineMap:n}}},b6=class PEe{constructor(t=[]){this.children=t,this.totalChars=0,this.totalLines=0,t.length&&this.updateCounts()}isLeaf(){return!1}updateCounts(){this.totalChars=0,this.totalLines=0;for(let t of this.children)this.totalChars+=t.charCount(),this.totalLines+=t.lineCount()}execWalk(t,n,i,s,o){return i.pre&&i.pre(t,n,this.children[s],this,o),i.goSubtree?(this.children[s].walk(t,n,i),i.post&&i.post(t,n,this.children[s],this,o)):i.goSubtree=!0,i.done}skipChild(t,n,i,s,o){s.pre&&!s.done&&(s.pre(t,n,this.children[i],this,o),s.goSubtree=!0)}walk(t,n,i){if(this.children.length===0)return;let s=0,o=this.children[s].charCount(),u=t;for(;u>=o;)this.skipChild(u,n,s,i,0),u-=o,s++,o=this.children[s].charCount();if(u+n<=o){if(this.execWalk(u,n,i,s,2))return}else{if(this.execWalk(u,o-u,i,s,1))return;let d=n-(o-u);for(s++,o=this.children[s].charCount();d>o;){if(this.execWalk(0,o,i,s,3))return;d-=o,s++,o=this.children[s].charCount()}if(d>0&&this.execWalk(0,d,i,s,4))return}if(i.pre){let d=this.children.length;if(s<d-1)for(let p=s+1;p<d;p++)this.skipChild(0,0,p,i,5)}}charOffsetToLineInfo(t,n){if(this.children.length===0)return{oneBasedLine:t,zeroBasedColumn:n,lineText:void 0};for(let o of this.children){if(o.charCount()>n)return o.isLeaf()?{oneBasedLine:t,zeroBasedColumn:n,lineText:o.text}:o.charOffsetToLineInfo(t,n);n-=o.charCount(),t+=o.lineCount()}let i=this.lineCount();if(i===0)return{oneBasedLine:1,zeroBasedColumn:0,lineText:void 0};let s=O.checkDefined(this.lineNumberToInfo(i,0).leaf);return{oneBasedLine:i,zeroBasedColumn:s.charCount(),lineText:void 0}}lineNumberToInfo(t,n){for(let i of this.children){let s=i.lineCount();if(s>=t)return i.isLeaf()?{position:n,leaf:i}:i.lineNumberToInfo(t,n);t-=s,n+=i.charCount()}return{position:n,leaf:void 0}}splitAfter(t){let n,i=this.children.length;t++;let s=t;if(t<i){for(n=new PEe;t<i;)n.add(this.children[t]),t++;n.updateCounts()}return this.children.length=s,n}remove(t){let n=this.findChildIndex(t),i=this.children.length;if(n<i-1)for(let s=n;s<i-1;s++)this.children[s]=this.children[s+1];this.children.pop()}findChildIndex(t){let n=this.children.indexOf(t);return O.assert(n!==-1),n}insertAt(t,n){let i=this.findChildIndex(t),s=this.children.length,o=n.length;if(s<v6&&i===s-1&&o===1)return this.add(n[0]),this.updateCounts(),[];{let u=this.splitAfter(i),d=0;for(i++;i<v6&&d<o;)this.children[i]=n[d],i++,d++;let p=[],x=0;if(d<o){x=Math.ceil((o-d)/v6),p=new Array(x);let b=0;for(let E=0;E<x;E++)p[E]=new PEe;let T=p[0];for(;d<o;)T.add(n[d]),d++,T.children.length===v6&&(b++,T=p[b]);for(let E=p.length-1;E>=0;E--)p[E].children.length===0&&p.pop()}u&&p.push(u),this.updateCounts();for(let b=0;b<x;b++)p[b].updateCounts();return p}}add(t){this.children.push(t),O.assert(this.children.length<=v6)}charCount(){return this.totalChars}lineCount(){return this.totalLines}},K$=class{constructor(e){this.text=e}isLeaf(){return!0}walk(e,t,n){n.leaf(e,t,this)}charCount(){return this.text.length}lineCount(){return 1}},e$e=class yQe{constructor(t,n,i,s,o,u){this.telemetryEnabled=t,this.logger=n,this.host=i,this.globalTypingsCacheLocation=s,this.event=o,this.maxActiveRequestCount=u,this.activeRequestCount=0,this.requestQueue=VA(),this.requestMap=new Map,this.requestedRegistry=!1,this.packageInstallId=0}isKnownTypesPackageName(t){var n;return k1.validatePackageName(t)!==k1.NameValidationResult.Ok?!1:(this.requestedRegistry||(this.requestedRegistry=!0,this.installer.send({kind:"typesRegistry"})),!!((n=this.typesRegistryCache)!=null&&n.has(t)))}installPackage(t){this.packageInstallId++;let n={kind:"installPackage",...t,id:this.packageInstallId},i=new Promise((s,o)=>{(this.packageInstalledPromise??(this.packageInstalledPromise=new Map)).set(this.packageInstallId,{resolve:s,reject:o})});return this.installer.send(n),i}attach(t){this.projectService=t,this.installer=this.createInstallerProcess()}onProjectClosed(t){this.installer.send({projectName:t.getProjectName(),kind:"closeProject"})}enqueueInstallTypingsRequest(t,n,i){let s=I0e(t,n,i);this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Scheduling throttled operation:${Hb(s)}`),this.activeRequestCount<this.maxActiveRequestCount?this.scheduleRequest(s):(this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Deferring request for: ${s.projectName}`),this.requestQueue.enqueue(s),this.requestMap.set(s.projectName,s))}handleMessage(t){var n,i;switch(this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Received response:${Hb(t)}`),t.kind){case SZ:this.typesRegistryCache=new Map(Object.entries(t.typesRegistry));break;case mj:{let s=(n=this.packageInstalledPromise)==null?void 0:n.get(t.id);O.assertIsDefined(s,"Should find the promise for package install"),(i=this.packageInstalledPromise)==null||i.delete(t.id),t.success?s.resolve({successMessage:t.message}):s.reject(t.message),this.projectService.updateTypingsForProject(t),this.event(t,"setTypings");break}case Mpe:{let s={message:t.message};this.event(s,"typesInstallerInitializationFailed");break}case xZ:{let s={eventId:t.eventId,packages:t.packagesToInstall};this.event(s,"beginInstallTypes");break}case TZ:{if(this.telemetryEnabled){let u={telemetryEventName:"typingsInstalled",payload:{installedPackages:t.packagesToInstall.join(","),installSuccess:t.installSuccess,typingsInstallerVersion:t.typingsInstallerVersion}};this.event(u,"telemetry")}let s={eventId:t.eventId,packages:t.packagesToInstall,success:t.installSuccess};this.event(s,"endInstallTypes");break}case dj:{this.projectService.updateTypingsForProject(t);break}case pj:{for(this.activeRequestCount>0?this.activeRequestCount--:O.fail("TIAdapter:: Received too many responses");!this.requestQueue.isEmpty();){let s=this.requestQueue.dequeue();if(this.requestMap.get(s.projectName)===s){this.requestMap.delete(s.projectName),this.scheduleRequest(s);break}this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Skipping defunct request for: ${s.projectName}`)}this.projectService.updateTypingsForProject(t),this.event(t,"setTypings");break}case UO:this.projectService.watchTypingLocations(t);break;default:}}scheduleRequest(t){this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Scheduling request for: ${t.projectName}`),this.activeRequestCount++,this.host.setTimeout(()=>{this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Sending request:${Hb(t)}`),this.installer.send(t)},yQe.requestDelayMillis,`${t.projectName}::${t.kind}`)}};e$e.requestDelayMillis=100;var t$e=e$e,r$e={};v(r$e,{ActionInvalidate:()=>dj,ActionPackageInstalled:()=>mj,ActionSet:()=>pj,ActionWatchTypingLocations:()=>UO,Arguments:()=>kZ,AutoImportProviderProject:()=>X0e,AuxiliaryProject:()=>Z0e,CharRangeSection:()=>Tve,CloseFileWatcherEvent:()=>$Q,CommandNames:()=>Bje,ConfigFileDiagEvent:()=>FQ,ConfiguredProject:()=>Q0e,ConfiguredProjectLoadKind:()=>ive,CreateDirectoryWatcherEvent:()=>jQ,CreateFileWatcherEvent:()=>RQ,Errors:()=>Jy,EventBeginInstallTypes:()=>xZ,EventEndInstallTypes:()=>TZ,EventInitializationFailed:()=>Mpe,EventTypesRegistry:()=>SZ,ExternalProject:()=>DQ,GcTimer:()=>R0e,InferredProject:()=>H0e,LargeFileReferencedEvent:()=>OQ,LineIndex:()=>H7,LineLeaf:()=>K$,LineNode:()=>b6,LogLevel:()=>D0e,Msg:()=>P0e,OpenFileInfoTelemetryEvent:()=>Y0e,Project:()=>Dw,ProjectInfoTelemetryEvent:()=>MQ,ProjectKind:()=>hN,ProjectLanguageServiceStateEvent:()=>LQ,ProjectLoadingFinishEvent:()=>AQ,ProjectLoadingStartEvent:()=>NQ,ProjectService:()=>pve,ProjectsUpdatedInBackgroundEvent:()=>G$,ScriptInfo:()=>B0e,ScriptVersionCache:()=>XQ,Session:()=>Zje,TextStorage:()=>z0e,ThrottledOperations:()=>M0e,TypingsInstallerAdapter:()=>t$e,allFilesAreJsOrDts:()=>V0e,allRootFilesAreJsOrDts:()=>W0e,asNormalizedPath:()=>pje,convertCompilerOptions:()=>H$,convertFormatOptions:()=>h6,convertScriptKindName:()=>BQ,convertTypeAcquisition:()=>tve,convertUserPreferences:()=>rve,convertWatchOptions:()=>q7,countEachFileTypes:()=>J7,createInstallTypingsRequest:()=>I0e,createModuleSpecifierCache:()=>gve,createNormalizedPathMap:()=>dje,createPackageJsonCache:()=>hve,createSortedArray:()=>L0e,emptyArray:()=>Ql,findArgument:()=>dAe,formatDiagnosticToProtocol:()=>G7,formatMessage:()=>yve,getBaseConfigFileName:()=>EQ,getDetailWatchInfo:()=>VQ,getLocationInNewDocument:()=>xve,hasArgument:()=>pAe,hasNoTypeScriptSource:()=>q0e,indent:()=>J4,isBackgroundProject:()=>W7,isConfigFile:()=>dve,isConfiguredProject:()=>H0,isDynamicFileName:()=>gN,isExternalProject:()=>U7,isInferredProject:()=>g6,isInferredProjectName:()=>N0e,isProjectDeferredClose:()=>V7,makeAutoImportProviderProjectName:()=>O0e,makeAuxiliaryProjectName:()=>F0e,makeInferredProjectName:()=>A0e,maxFileSize:()=>IQ,maxProgramSizeForNonTsFiles:()=>PQ,normalizedPathToPath:()=>m6,nowString:()=>mAe,nullCancellationToken:()=>jje,nullTypingsInstaller:()=>Z$,protocol:()=>j0e,scriptInfoIsContainedByBackgroundProject:()=>J0e,scriptInfoIsContainedByDeferredClosedProject:()=>U0e,stringifyIndented:()=>Hb,toEvent:()=>vve,toNormalizedPath:()=>Po,tryConvertScriptKindName:()=>zQ,typingsInstaller:()=>E0e,updateProjectIfDirty:()=>$d}),typeof console<"u"&&(O.loggingHost={log(e,t){switch(e){case 1:return console.error(t);case 2:return console.warn(t);case 3:return console.log(t);case 4:return console.log(t)}}})})({get exports(){return _Qe},set exports(c){_Qe=c,typeof Vne<"u"&&Vne.exports&&(Vne.exports=c)}})});var KQe=_xe((pJt,pLt)=>{pLt.exports={name:"@fabriziosalmi/slopless",version:"1.8.0",description:"",main:"dist/index.js",bin:{slopless:"dist/index.js"},files:["dist","rules"],scripts:{test:"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage",build:"tsup","docs:dev":"npm run docs:gen && vitepress dev docs","docs:gen":"ts-node scripts/generate-rule-docs.ts","docs:build":"npm run docs:gen && vitepress build docs","docs:preview":"vitepress preview docs","verify:bundle":"node scripts/verify-bundle.js","verify:action":"bash scripts/run-action-locally.sh . 'src/**/*.ts'","release:prep":"npm run docs:gen && npm run build && npm test && npm run verify:bundle",version:"node scripts/check-changelog.js && npm run docs:gen && npm run build && git add dist docs README.md"},keywords:["linter","static-analysis","anti-vibecoding","sarif"],author:"Fabrizio Salmi",license:"MIT",repository:{type:"git",url:"git+https://github.com/fabriziosalmi/slopless.git"},homepage:"https://fabriziosalmi.github.io/slopless/",bugs:{url:"https://github.com/fabriziosalmi/slopless/issues"},type:"commonjs",devDependencies:{"@types/glob":"^9.0.0","@types/js-yaml":"^4.0.9","@types/node":"^26.4.0","@vitest/coverage-v8":"^4.0.18",commander:"^15.0.0",glob:"^13.0.6",ignore:"^7.0.5","js-yaml":"^5.4.1",minimatch:"^10.2.6","ts-node":"^10.9.2",tsup:"^8.5.1",typescript:"^5.9.3",vitepress:"^1.6.4",vitest:"^4.1.11",zod:"^4.3.6"},allowScripts:{esbuild:!0,fsevents:!0},publishConfig:{access:"public"}}});var bLt={};Fk(bLt,{UsageError:()=>LJ,applyIgnoreRules:()=>eYe,selectRules:()=>tYe});module.exports=mIt(bLt);var iP=class extends Error{constructor(l,m,h){super(h),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=m,this.exitCode=l,this.nestedError=void 0}},_A=class extends iP{constructor(l){super(1,"commander.invalidArgument",l),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var wB=class{constructor(l,m){switch(this.description=m||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,l[0]){case"<":this.required=!0,this._name=l.slice(1,-1);break;case"[":this.required=!1,this._name=l.slice(1,-1);break;default:this.required=!0,this._name=l;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(l,m){return m===this.defaultValue||!Array.isArray(m)?[l]:(m.push(l),m)}default(l,m){return this.defaultValue=l,this.defaultValueDescription=m,this}argParser(l){return this.parseArg=l,this}choices(l){return this.argChoices=l.slice(),this.parseArg=(m,h)=>{if(!this.argChoices.includes(m))throw new _A(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(m,h):m},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function ate(c){let l=c.name()+(c.variadic===!0?"...":"");return c.required?"<"+l+">":"["+l+"]"}var YVe=require("events"),cte=Iu(require("child_process"),1),Lk=Iu(require("path"),1),DB=Iu(require("fs"),1),Vu=Iu(require("process"),1),eqe=require("util");var ZVe=require("util"),EB=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(l){this.helpWidth=this.helpWidth??l.helpWidth??80}visibleCommands(l){let m=l.commands.filter(f=>!f._hidden),h=l._getHelpCommand();return h&&!h._hidden&&m.push(h),this.sortSubcommands&&m.sort((f,v)=>f.name().localeCompare(v.name())),m}compareOptions(l,m){let h=f=>f.short?f.short.replace(/^-/,""):f.long.replace(/^--/,"");return h(l).localeCompare(h(m))}visibleOptions(l){let m=l.options.filter(f=>!f.hidden),h=l._getHelpOption();if(h&&!h.hidden){let f=h.short&&l._findOption(h.short),v=h.long&&l._findOption(h.long);!f&&!v?m.push(h):h.long&&!v?m.push(l.createOption(h.long,h.description)):h.short&&!f&&m.push(l.createOption(h.short,h.description))}return this.sortOptions&&m.sort(this.compareOptions),m}visibleGlobalOptions(l){if(!this.showGlobalOptions)return[];let m=[];for(let h=l.parent;h;h=h.parent){let f=h.options.filter(v=>!v.hidden);m.push(...f)}return this.sortOptions&&m.sort(this.compareOptions),m}visibleArguments(l){return l._argsDescription&&l.registeredArguments.forEach(m=>{m.description=m.description||l._argsDescription[m.name()]||""}),l.registeredArguments.find(m=>m.description)?l.registeredArguments:[]}subcommandTerm(l){let m=l.registeredArguments.map(h=>ate(h)).join(" ");return l._name+(l._aliases[0]?"|"+l._aliases[0]:"")+(l.options.length?" [options]":"")+(m?" "+m:"")}optionTerm(l){return l.flags}argumentTerm(l){return l.name()}longestSubcommandTermLength(l,m){return m.visibleCommands(l).reduce((h,f)=>Math.max(h,this.displayWidth(m.styleSubcommandTerm(m.subcommandTerm(f)))),0)}longestOptionTermLength(l,m){return m.visibleOptions(l).reduce((h,f)=>Math.max(h,this.displayWidth(m.styleOptionTerm(m.optionTerm(f)))),0)}longestGlobalOptionTermLength(l,m){return m.visibleGlobalOptions(l).reduce((h,f)=>Math.max(h,this.displayWidth(m.styleOptionTerm(m.optionTerm(f)))),0)}longestArgumentTermLength(l,m){return m.visibleArguments(l).reduce((h,f)=>Math.max(h,this.displayWidth(m.styleArgumentTerm(m.argumentTerm(f)))),0)}commandUsage(l){let m=l._name;l._aliases[0]&&(m=m+"|"+l._aliases[0]);let h="";for(let f=l.parent;f;f=f.parent)h=f.name()+" "+h;return h+m+" "+l.usage()}commandDescription(l){return l.description()}subcommandDescription(l){return l.summary()||l.description()}optionDescription(l){let m=[];if(l.argChoices&&m.push(`choices: ${l.argChoices.map(h=>JSON.stringify(h)).join(", ")}`),l.defaultValue!==void 0&&(l.required||l.optional||l.isBoolean()&&typeof l.defaultValue=="boolean")&&m.push(`default: ${l.defaultValueDescription||JSON.stringify(l.defaultValue)}`),l.presetArg!==void 0&&l.optional&&m.push(`preset: ${JSON.stringify(l.presetArg)}`),l.envVar!==void 0&&m.push(`env: ${l.envVar}`),m.length>0){let h=`(${m.join(", ")})`;return l.description?`${l.description} ${h}`:h}return l.description}argumentDescription(l){let m=[];if(l.argChoices&&m.push(`choices: ${l.argChoices.map(h=>JSON.stringify(h)).join(", ")}`),l.defaultValue!==void 0&&m.push(`default: ${l.defaultValueDescription||JSON.stringify(l.defaultValue)}`),m.length>0){let h=`(${m.join(", ")})`;return l.description?`${l.description} ${h}`:h}return l.description}formatItemList(l,m,h){return m.length===0?[]:[h.styleTitle(l),...m,""]}groupItems(l,m,h){let f=new Map;return l.forEach(v=>{let D=h(v);f.has(D)||f.set(D,[])}),m.forEach(v=>{let D=h(v);f.has(D)||f.set(D,[]),f.get(D).push(v)}),f}formatHelp(l,m){let h=m.padWidth(l,m),f=m.helpWidth??80;function v(Ne,se){return m.formatItem(Ne,h,se,m)}let D=[`${m.styleTitle("Usage:")} ${m.styleUsage(m.commandUsage(l))}`,""],$=m.commandDescription(l);$.length>0&&(D=D.concat([m.boxWrap(m.styleCommandDescription($),f),""]));let te=m.visibleArguments(l).map(Ne=>v(m.styleArgumentTerm(m.argumentTerm(Ne)),m.styleArgumentDescription(m.argumentDescription(Ne))));if(D=D.concat(this.formatItemList("Arguments:",te,m)),this.groupItems(l.options,m.visibleOptions(l),Ne=>Ne.helpGroupHeading??"Options:").forEach((Ne,se)=>{let ft=Ne.map(Ze=>v(m.styleOptionTerm(m.optionTerm(Ze)),m.styleOptionDescription(m.optionDescription(Ze))));D=D.concat(this.formatItemList(se,ft,m))}),m.showGlobalOptions){let Ne=m.visibleGlobalOptions(l).map(se=>v(m.styleOptionTerm(m.optionTerm(se)),m.styleOptionDescription(m.optionDescription(se))));D=D.concat(this.formatItemList("Global Options:",Ne,m))}return this.groupItems(l.commands,m.visibleCommands(l),Ne=>Ne.helpGroup()||"Commands:").forEach((Ne,se)=>{let ft=Ne.map(Ze=>v(m.styleSubcommandTerm(m.subcommandTerm(Ze)),m.styleSubcommandDescription(m.subcommandDescription(Ze))));D=D.concat(this.formatItemList(se,ft,m))}),D.join(`
|
|
434
|
+
`+P.stack)}finally{this.performanceData=b}}parseMessage(t){return JSON.parse(t)}toStringMessage(t){return t}getFormatOptions(t){return this.projectService.getFormatCodeOptions(t)}getPreferences(t){return this.projectService.getPreferences(t)}getHostFormatOptions(){return this.projectService.getHostFormatCodeOptions()}getHostPreferences(){return this.projectService.getHostPreferences()}};function Kje(e){let t=e.diagnosticsDuration&&Es(e.diagnosticsDuration,([n,i])=>({...i,file:n}));return{...e,diagnosticsDuration:t}}function Tg(e,t){return{start:t.positionToLineOffset(e.start),end:t.positionToLineOffset(Pc(e))}}function Sve(e,t,n){let i=Tg(e,n),s=t&&Tg(t,n);return s?{...i,contextStart:s.start,contextEnd:s.end}:i}function m1t(e,t){return{start:Xje(t,e.span.start),end:Xje(t,Pc(e.span)),newText:e.newText}}function Xje(e,t){return dve(e)?h1t(e.getLineAndCharacterOfPosition(t)):e.positionToLineOffset(t)}function g1t(e,t){let n=e.ranges.map(i=>({start:t.positionToLineOffset(i.start),end:t.positionToLineOffset(i.start+i.length)}));return e.wordPattern?{ranges:n,wordPattern:e.wordPattern}:{ranges:n}}function h1t(e){return{line:e.line+1,offset:e.character+1}}function y1t(e){O.assert(e.textChanges.length===1);let t=Za(e.textChanges);return O.assert(t.span.start===0&&t.span.length===0),{fileName:e.fileName,textChanges:[{start:{line:0,offset:0},end:{line:0,offset:0},newText:t.newText}]}}function xve(e,t,n,i){let s=v1t(e,t,i),{line:o,character:u}=OE(sC(s),n);return{line:o+1,offset:u+1}}function v1t(e,t,n){for(let{fileName:i,textChanges:s}of n)if(i===t)for(let o=s.length-1;o>=0;o--){let{newText:u,span:{start:d,length:p}}=s[o];e=e.slice(0,d)+u+e.slice(d+p)}return e}function Qje(e,{fileName:t,textSpan:n,contextSpan:i,isWriteAccess:s,isDefinition:o},{disableLineTextInReferences:u}){let d=O.checkDefined(e.getScriptInfo(t)),p=Sve(n,i,d),x=u?void 0:b1t(d,p);return{file:t,...p,lineText:x,isWriteAccess:s,isDefinition:o}}function b1t(e,t){let n=e.lineToTextSpan(t.start.line-1);return e.getSnapshot().getText(n.start,Pc(n)).replace(/\r|\n/g,"")}function S1t(e){return e===void 0||e&&typeof e=="object"&&typeof e.exportName=="string"&&(e.fileName===void 0||typeof e.fileName=="string")&&(e.ambientModuleName===void 0||typeof e.ambientModuleName=="string"&&(e.isPackageJsonImport===void 0||typeof e.isPackageJsonImport=="boolean"))}var v6=4,Tve=(e=>(e[e.PreStart=0]="PreStart",e[e.Start=1]="Start",e[e.Entire=2]="Entire",e[e.Mid=3]="Mid",e[e.End=4]="End",e[e.PostEnd=5]="PostEnd",e))(Tve||{}),x1t=class{constructor(){this.goSubtree=!0,this.lineIndex=new H7,this.endBranch=[],this.state=2,this.initialText="",this.trailingText="",this.lineIndex.root=new b6,this.startPath=[this.lineIndex.root],this.stack=[this.lineIndex.root]}get done(){return!1}insertLines(e,t){t&&(this.trailingText=""),e?e=this.initialText+e+this.trailingText:e=this.initialText+this.trailingText;let i=H7.linesFromText(e).lines;i.length>1&&i[i.length-1]===""&&i.pop();let s,o;for(let d=this.endBranch.length-1;d>=0;d--)this.endBranch[d].updateCounts(),this.endBranch[d].charCount()===0&&(o=this.endBranch[d],d>0?s=this.endBranch[d-1]:s=this.branchNode);o&&s.remove(o);let u=this.startPath[this.startPath.length-1];if(i.length>0)if(u.text=i[0],i.length>1){let d=new Array(i.length-1),p=u;for(let T=1;T<i.length;T++)d[T-1]=new K$(i[T]);let x=this.startPath.length-2;for(;x>=0;){let T=this.startPath[x];d=T.insertAt(p,d),x--,p=T}let b=d.length;for(;b>0;){let T=new b6;T.add(this.lineIndex.root),d=T.insertAt(this.lineIndex.root,d),b=d.length,this.lineIndex.root=T}this.lineIndex.root.updateCounts()}else for(let d=this.startPath.length-2;d>=0;d--)this.startPath[d].updateCounts();else{this.startPath[this.startPath.length-2].remove(u);for(let p=this.startPath.length-2;p>=0;p--)this.startPath[p].updateCounts()}return this.lineIndex}post(e,t,n){n===this.lineCollectionAtBranch&&(this.state=4),this.stack.pop()}pre(e,t,n,i,s){let o=this.stack[this.stack.length-1];this.state===2&&s===1&&(this.state=1,this.branchNode=o,this.lineCollectionAtBranch=n);let u;function d(p){return p.isLeaf()?new K$(""):new b6}switch(s){case 0:this.goSubtree=!1,this.state!==4&&o.add(n);break;case 1:this.state===4?this.goSubtree=!1:(u=d(n),o.add(u),this.startPath.push(u));break;case 2:this.state!==4?(u=d(n),o.add(u),this.startPath.push(u)):n.isLeaf()||(u=d(n),o.add(u),this.endBranch.push(u));break;case 3:this.goSubtree=!1;break;case 4:this.state!==4?this.goSubtree=!1:n.isLeaf()||(u=d(n),o.add(u),this.endBranch.push(u));break;case 5:this.goSubtree=!1,this.state!==1&&o.add(n);break}this.goSubtree&&this.stack.push(u)}leaf(e,t,n){this.state===1?this.initialText=n.text.substring(0,e):this.state===2?(this.initialText=n.text.substring(0,e),this.trailingText=n.text.substring(e+t)):this.trailingText=n.text.substring(e+t)}},T1t=class{constructor(e,t,n){this.pos=e,this.deleteLen=t,this.insertedText=n}getTextChangeRange(){return o3(Ou(this.pos,this.deleteLen),this.insertedText?this.insertedText.length:0)}},KQ=class qk{constructor(){this.changes=[],this.versions=new Array(qk.maxVersions),this.minVersion=0,this.currentVersion=0}versionToIndex(t){if(!(t<this.minVersion||t>this.currentVersion))return t%qk.maxVersions}currentVersionToIndex(){return this.currentVersion%qk.maxVersions}edit(t,n,i){this.changes.push(new T1t(t,n,i)),(this.changes.length>qk.changeNumberThreshold||n>qk.changeLengthThreshold||i&&i.length>qk.changeLengthThreshold)&&this.getSnapshot()}getSnapshot(){return this._getSnapshot()}_getSnapshot(){let t=this.versions[this.currentVersionToIndex()];if(this.changes.length>0){let n=t.index;for(let i of this.changes)n=n.edit(i.pos,i.deleteLen,i.insertedText);t=new Yje(this.currentVersion+1,this,n,this.changes),this.currentVersion=t.version,this.versions[this.currentVersionToIndex()]=t,this.changes=[],this.currentVersion-this.minVersion>=qk.maxVersions&&(this.minVersion=this.currentVersion-qk.maxVersions+1)}return t}getSnapshotVersion(){return this._getSnapshot().version}getAbsolutePositionAndLineText(t){return this._getSnapshot().index.lineNumberToInfo(t)}lineOffsetToPosition(t,n){return this._getSnapshot().index.absolutePositionOfStartOfLine(t)+(n-1)}positionToLineOffset(t){return this._getSnapshot().index.positionToLineOffset(t)}lineToTextSpan(t){let n=this._getSnapshot().index,{lineText:i,absolutePosition:s}=n.lineNumberToInfo(t+1),o=i!==void 0?i.length:n.absolutePositionOfStartOfLine(t+2)-s;return Ou(s,o)}getTextChangesBetweenVersions(t,n){if(t<n)if(t>=this.minVersion){let i=[];for(let s=t+1;s<=n;s++){let o=this.versions[this.versionToIndex(s)];for(let u of o.changesSincePreviousVersion)i.push(u.getTextChangeRange())}return aae(i)}else return;else return T9}getLineCount(){return this._getSnapshot().index.getLineCount()}static fromString(t){let n=new qk,i=new Yje(0,n,new H7);n.versions[n.currentVersion]=i;let s=H7.linesFromText(t);return i.index.load(s.lines),n}};KQ.changeNumberThreshold=8,KQ.changeLengthThreshold=256,KQ.maxVersions=8;var XQ=KQ,Yje=class hQe{constructor(t,n,i,s=Ql){this.version=t,this.cache=n,this.index=i,this.changesSincePreviousVersion=s}getText(t,n){return this.index.getText(t,n-t)}getLength(){return this.index.getLength()}getChangeRange(t){if(t instanceof hQe&&this.cache===t.cache)return this.version<=t.version?T9:this.cache.getTextChangesBetweenVersions(t.version,this.version)}},H7=class DEe{constructor(){this.checkEdits=!1}absolutePositionOfStartOfLine(t){return this.lineNumberToInfo(t).absolutePosition}positionToLineOffset(t){let{oneBasedLine:n,zeroBasedColumn:i}=this.root.charOffsetToLineInfo(1,t);return{line:n,offset:i+1}}positionToColumnAndLineText(t){return this.root.charOffsetToLineInfo(1,t)}getLineCount(){return this.root.lineCount()}lineNumberToInfo(t){let n=this.getLineCount();if(t<=n){let{position:i,leaf:s}=this.root.lineNumberToInfo(t,0);return{absolutePosition:i,lineText:s&&s.text}}else return{absolutePosition:this.root.charCount(),lineText:void 0}}load(t){if(t.length>0){let n=[];for(let i=0;i<t.length;i++)n[i]=new K$(t[i]);this.root=DEe.buildTreeFromBottom(n)}else this.root=new b6}walk(t,n,i){this.root.walk(t,n,i)}getText(t,n){let i="";return n>0&&t<this.root.charCount()&&this.walk(t,n,{goSubtree:!0,done:!1,leaf:(s,o,u)=>{i=i.concat(u.text.substring(s,s+o))}}),i}getLength(){return this.root.charCount()}every(t,n,i){i||(i=this.root.charCount());let s={goSubtree:!0,done:!1,leaf(o,u,d){t(d,o,u)||(this.done=!0)}};return this.walk(n,i-n,s),!s.done}edit(t,n,i){if(this.root.charCount()===0)return O.assert(n===0),i!==void 0?(this.load(DEe.linesFromText(i).lines),this):void 0;{let s;if(this.checkEdits){let d=this.getText(0,this.root.charCount());s=d.slice(0,t)+i+d.slice(t+n)}let o=new x1t,u=!1;if(t>=this.root.charCount()){t=this.root.charCount()-1;let d=this.getText(t,1);i?i=d+i:i=d,n=0,u=!0}else if(n>0){let d=t+n,{zeroBasedColumn:p,lineText:x}=this.positionToColumnAndLineText(d);p===0&&(n+=x.length,i=i?i+x:x)}if(this.root.walk(t,n,o),o.insertLines(i,u),this.checkEdits){let d=o.lineIndex.getText(0,o.lineIndex.getLength());O.assert(s===d,"buffer edit mismatch")}return o.lineIndex}}static buildTreeFromBottom(t){if(t.length<v6)return new b6(t);let n=new Array(Math.ceil(t.length/v6)),i=0;for(let s=0;s<n.length;s++){let o=Math.min(i+v6,t.length);n[s]=new b6(t.slice(i,o)),i=o}return this.buildTreeFromBottom(n)}static linesFromText(t){let n=sC(t);if(n.length===0)return{lines:[],lineMap:n};let i=new Array(n.length),s=n.length-1;for(let u=0;u<s;u++)i[u]=t.substring(n[u],n[u+1]);let o=t.substring(n[s]);return o.length>0?i[s]=o:i.pop(),{lines:i,lineMap:n}}},b6=class PEe{constructor(t=[]){this.children=t,this.totalChars=0,this.totalLines=0,t.length&&this.updateCounts()}isLeaf(){return!1}updateCounts(){this.totalChars=0,this.totalLines=0;for(let t of this.children)this.totalChars+=t.charCount(),this.totalLines+=t.lineCount()}execWalk(t,n,i,s,o){return i.pre&&i.pre(t,n,this.children[s],this,o),i.goSubtree?(this.children[s].walk(t,n,i),i.post&&i.post(t,n,this.children[s],this,o)):i.goSubtree=!0,i.done}skipChild(t,n,i,s,o){s.pre&&!s.done&&(s.pre(t,n,this.children[i],this,o),s.goSubtree=!0)}walk(t,n,i){if(this.children.length===0)return;let s=0,o=this.children[s].charCount(),u=t;for(;u>=o;)this.skipChild(u,n,s,i,0),u-=o,s++,o=this.children[s].charCount();if(u+n<=o){if(this.execWalk(u,n,i,s,2))return}else{if(this.execWalk(u,o-u,i,s,1))return;let d=n-(o-u);for(s++,o=this.children[s].charCount();d>o;){if(this.execWalk(0,o,i,s,3))return;d-=o,s++,o=this.children[s].charCount()}if(d>0&&this.execWalk(0,d,i,s,4))return}if(i.pre){let d=this.children.length;if(s<d-1)for(let p=s+1;p<d;p++)this.skipChild(0,0,p,i,5)}}charOffsetToLineInfo(t,n){if(this.children.length===0)return{oneBasedLine:t,zeroBasedColumn:n,lineText:void 0};for(let o of this.children){if(o.charCount()>n)return o.isLeaf()?{oneBasedLine:t,zeroBasedColumn:n,lineText:o.text}:o.charOffsetToLineInfo(t,n);n-=o.charCount(),t+=o.lineCount()}let i=this.lineCount();if(i===0)return{oneBasedLine:1,zeroBasedColumn:0,lineText:void 0};let s=O.checkDefined(this.lineNumberToInfo(i,0).leaf);return{oneBasedLine:i,zeroBasedColumn:s.charCount(),lineText:void 0}}lineNumberToInfo(t,n){for(let i of this.children){let s=i.lineCount();if(s>=t)return i.isLeaf()?{position:n,leaf:i}:i.lineNumberToInfo(t,n);t-=s,n+=i.charCount()}return{position:n,leaf:void 0}}splitAfter(t){let n,i=this.children.length;t++;let s=t;if(t<i){for(n=new PEe;t<i;)n.add(this.children[t]),t++;n.updateCounts()}return this.children.length=s,n}remove(t){let n=this.findChildIndex(t),i=this.children.length;if(n<i-1)for(let s=n;s<i-1;s++)this.children[s]=this.children[s+1];this.children.pop()}findChildIndex(t){let n=this.children.indexOf(t);return O.assert(n!==-1),n}insertAt(t,n){let i=this.findChildIndex(t),s=this.children.length,o=n.length;if(s<v6&&i===s-1&&o===1)return this.add(n[0]),this.updateCounts(),[];{let u=this.splitAfter(i),d=0;for(i++;i<v6&&d<o;)this.children[i]=n[d],i++,d++;let p=[],x=0;if(d<o){x=Math.ceil((o-d)/v6),p=new Array(x);let b=0;for(let E=0;E<x;E++)p[E]=new PEe;let T=p[0];for(;d<o;)T.add(n[d]),d++,T.children.length===v6&&(b++,T=p[b]);for(let E=p.length-1;E>=0;E--)p[E].children.length===0&&p.pop()}u&&p.push(u),this.updateCounts();for(let b=0;b<x;b++)p[b].updateCounts();return p}}add(t){this.children.push(t),O.assert(this.children.length<=v6)}charCount(){return this.totalChars}lineCount(){return this.totalLines}},K$=class{constructor(e){this.text=e}isLeaf(){return!0}walk(e,t,n){n.leaf(e,t,this)}charCount(){return this.text.length}lineCount(){return 1}},e$e=class yQe{constructor(t,n,i,s,o,u){this.telemetryEnabled=t,this.logger=n,this.host=i,this.globalTypingsCacheLocation=s,this.event=o,this.maxActiveRequestCount=u,this.activeRequestCount=0,this.requestQueue=VA(),this.requestMap=new Map,this.requestedRegistry=!1,this.packageInstallId=0}isKnownTypesPackageName(t){var n;return k1.validatePackageName(t)!==k1.NameValidationResult.Ok?!1:(this.requestedRegistry||(this.requestedRegistry=!0,this.installer.send({kind:"typesRegistry"})),!!((n=this.typesRegistryCache)!=null&&n.has(t)))}installPackage(t){this.packageInstallId++;let n={kind:"installPackage",...t,id:this.packageInstallId},i=new Promise((s,o)=>{(this.packageInstalledPromise??(this.packageInstalledPromise=new Map)).set(this.packageInstallId,{resolve:s,reject:o})});return this.installer.send(n),i}attach(t){this.projectService=t,this.installer=this.createInstallerProcess()}onProjectClosed(t){this.installer.send({projectName:t.getProjectName(),kind:"closeProject"})}enqueueInstallTypingsRequest(t,n,i){let s=I0e(t,n,i);this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Scheduling throttled operation:${Hb(s)}`),this.activeRequestCount<this.maxActiveRequestCount?this.scheduleRequest(s):(this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Deferring request for: ${s.projectName}`),this.requestQueue.enqueue(s),this.requestMap.set(s.projectName,s))}handleMessage(t){var n,i;switch(this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Received response:${Hb(t)}`),t.kind){case SZ:this.typesRegistryCache=new Map(Object.entries(t.typesRegistry));break;case mj:{let s=(n=this.packageInstalledPromise)==null?void 0:n.get(t.id);O.assertIsDefined(s,"Should find the promise for package install"),(i=this.packageInstalledPromise)==null||i.delete(t.id),t.success?s.resolve({successMessage:t.message}):s.reject(t.message),this.projectService.updateTypingsForProject(t),this.event(t,"setTypings");break}case Mpe:{let s={message:t.message};this.event(s,"typesInstallerInitializationFailed");break}case xZ:{let s={eventId:t.eventId,packages:t.packagesToInstall};this.event(s,"beginInstallTypes");break}case TZ:{if(this.telemetryEnabled){let u={telemetryEventName:"typingsInstalled",payload:{installedPackages:t.packagesToInstall.join(","),installSuccess:t.installSuccess,typingsInstallerVersion:t.typingsInstallerVersion}};this.event(u,"telemetry")}let s={eventId:t.eventId,packages:t.packagesToInstall,success:t.installSuccess};this.event(s,"endInstallTypes");break}case dj:{this.projectService.updateTypingsForProject(t);break}case pj:{for(this.activeRequestCount>0?this.activeRequestCount--:O.fail("TIAdapter:: Received too many responses");!this.requestQueue.isEmpty();){let s=this.requestQueue.dequeue();if(this.requestMap.get(s.projectName)===s){this.requestMap.delete(s.projectName),this.scheduleRequest(s);break}this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Skipping defunct request for: ${s.projectName}`)}this.projectService.updateTypingsForProject(t),this.event(t,"setTypings");break}case UO:this.projectService.watchTypingLocations(t);break;default:}}scheduleRequest(t){this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Scheduling request for: ${t.projectName}`),this.activeRequestCount++,this.host.setTimeout(()=>{this.logger.hasLevel(3)&&this.logger.info(`TIAdapter:: Sending request:${Hb(t)}`),this.installer.send(t)},yQe.requestDelayMillis,`${t.projectName}::${t.kind}`)}};e$e.requestDelayMillis=100;var t$e=e$e,r$e={};v(r$e,{ActionInvalidate:()=>dj,ActionPackageInstalled:()=>mj,ActionSet:()=>pj,ActionWatchTypingLocations:()=>UO,Arguments:()=>kZ,AutoImportProviderProject:()=>X0e,AuxiliaryProject:()=>Z0e,CharRangeSection:()=>Tve,CloseFileWatcherEvent:()=>$Q,CommandNames:()=>Bje,ConfigFileDiagEvent:()=>FQ,ConfiguredProject:()=>Q0e,ConfiguredProjectLoadKind:()=>ive,CreateDirectoryWatcherEvent:()=>jQ,CreateFileWatcherEvent:()=>RQ,Errors:()=>Jy,EventBeginInstallTypes:()=>xZ,EventEndInstallTypes:()=>TZ,EventInitializationFailed:()=>Mpe,EventTypesRegistry:()=>SZ,ExternalProject:()=>DQ,GcTimer:()=>R0e,InferredProject:()=>H0e,LargeFileReferencedEvent:()=>OQ,LineIndex:()=>H7,LineLeaf:()=>K$,LineNode:()=>b6,LogLevel:()=>D0e,Msg:()=>P0e,OpenFileInfoTelemetryEvent:()=>Y0e,Project:()=>Dw,ProjectInfoTelemetryEvent:()=>MQ,ProjectKind:()=>hN,ProjectLanguageServiceStateEvent:()=>LQ,ProjectLoadingFinishEvent:()=>AQ,ProjectLoadingStartEvent:()=>NQ,ProjectService:()=>pve,ProjectsUpdatedInBackgroundEvent:()=>G$,ScriptInfo:()=>B0e,ScriptVersionCache:()=>XQ,Session:()=>Zje,TextStorage:()=>z0e,ThrottledOperations:()=>M0e,TypingsInstallerAdapter:()=>t$e,allFilesAreJsOrDts:()=>V0e,allRootFilesAreJsOrDts:()=>W0e,asNormalizedPath:()=>pje,convertCompilerOptions:()=>H$,convertFormatOptions:()=>h6,convertScriptKindName:()=>BQ,convertTypeAcquisition:()=>tve,convertUserPreferences:()=>rve,convertWatchOptions:()=>q7,countEachFileTypes:()=>J7,createInstallTypingsRequest:()=>I0e,createModuleSpecifierCache:()=>gve,createNormalizedPathMap:()=>dje,createPackageJsonCache:()=>hve,createSortedArray:()=>L0e,emptyArray:()=>Ql,findArgument:()=>dAe,formatDiagnosticToProtocol:()=>G7,formatMessage:()=>yve,getBaseConfigFileName:()=>EQ,getDetailWatchInfo:()=>VQ,getLocationInNewDocument:()=>xve,hasArgument:()=>pAe,hasNoTypeScriptSource:()=>q0e,indent:()=>J4,isBackgroundProject:()=>W7,isConfigFile:()=>dve,isConfiguredProject:()=>H0,isDynamicFileName:()=>gN,isExternalProject:()=>U7,isInferredProject:()=>g6,isInferredProjectName:()=>N0e,isProjectDeferredClose:()=>V7,makeAutoImportProviderProjectName:()=>O0e,makeAuxiliaryProjectName:()=>F0e,makeInferredProjectName:()=>A0e,maxFileSize:()=>IQ,maxProgramSizeForNonTsFiles:()=>PQ,normalizedPathToPath:()=>m6,nowString:()=>mAe,nullCancellationToken:()=>jje,nullTypingsInstaller:()=>Z$,protocol:()=>j0e,scriptInfoIsContainedByBackgroundProject:()=>J0e,scriptInfoIsContainedByDeferredClosedProject:()=>U0e,stringifyIndented:()=>Hb,toEvent:()=>vve,toNormalizedPath:()=>Po,tryConvertScriptKindName:()=>zQ,typingsInstaller:()=>E0e,updateProjectIfDirty:()=>$d}),typeof console<"u"&&(O.loggingHost={log(e,t){switch(e){case 1:return console.error(t);case 2:return console.warn(t);case 3:return console.log(t);case 4:return console.log(t)}}})})({get exports(){return _Qe},set exports(c){_Qe=c,typeof Vne<"u"&&Vne.exports&&(Vne.exports=c)}})});var KQe=_xe((pJt,pLt)=>{pLt.exports={name:"@fabriziosalmi/slopless",version:"1.9.0",description:"",main:"dist/index.js",bin:{slopless:"dist/index.js"},files:["dist","rules"],scripts:{test:"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage",build:"tsup","docs:dev":"npm run docs:gen && vitepress dev docs","docs:gen":"ts-node scripts/generate-rule-docs.ts","docs:build":"npm run docs:gen && vitepress build docs","docs:preview":"vitepress preview docs","verify:bundle":"node scripts/verify-bundle.js","verify:action":"bash scripts/run-action-locally.sh . 'src/**/*.ts'","release:prep":"npm run docs:gen && npm run build && npm test && npm run verify:bundle",version:"node scripts/check-changelog.js && npm run docs:gen && npm run build && git add dist docs README.md"},keywords:["linter","static-analysis","anti-vibecoding","sarif"],author:"Fabrizio Salmi",license:"MIT",repository:{type:"git",url:"git+https://github.com/fabriziosalmi/slopless.git"},homepage:"https://fabriziosalmi.github.io/slopless/",bugs:{url:"https://github.com/fabriziosalmi/slopless/issues"},type:"commonjs",devDependencies:{"@types/glob":"^9.0.0","@types/js-yaml":"^4.0.9","@types/node":"^26.4.0","@vitest/coverage-v8":"^4.0.18",commander:"^15.0.0",glob:"^13.0.6",ignore:"^7.0.5","js-yaml":"^5.4.1",minimatch:"^10.2.6","ts-node":"^10.9.2",tsup:"^8.5.1",typescript:"^5.9.3",vitepress:"^1.6.4",vitest:"^4.1.11",zod:"^4.3.6"},allowScripts:{esbuild:!0,fsevents:!0},publishConfig:{access:"public"}}});var bLt={};Fk(bLt,{UsageError:()=>LJ,applyIgnoreRules:()=>eYe,selectRules:()=>tYe});module.exports=mIt(bLt);var iP=class extends Error{constructor(l,m,h){super(h),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=m,this.exitCode=l,this.nestedError=void 0}},_A=class extends iP{constructor(l){super(1,"commander.invalidArgument",l),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var wB=class{constructor(l,m){switch(this.description=m||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,l[0]){case"<":this.required=!0,this._name=l.slice(1,-1);break;case"[":this.required=!1,this._name=l.slice(1,-1);break;default:this.required=!0,this._name=l;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(l,m){return m===this.defaultValue||!Array.isArray(m)?[l]:(m.push(l),m)}default(l,m){return this.defaultValue=l,this.defaultValueDescription=m,this}argParser(l){return this.parseArg=l,this}choices(l){return this.argChoices=l.slice(),this.parseArg=(m,h)=>{if(!this.argChoices.includes(m))throw new _A(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(m,h):m},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function ate(c){let l=c.name()+(c.variadic===!0?"...":"");return c.required?"<"+l+">":"["+l+"]"}var YVe=require("events"),cte=Iu(require("child_process"),1),Lk=Iu(require("path"),1),DB=Iu(require("fs"),1),Vu=Iu(require("process"),1),eqe=require("util");var ZVe=require("util"),EB=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(l){this.helpWidth=this.helpWidth??l.helpWidth??80}visibleCommands(l){let m=l.commands.filter(f=>!f._hidden),h=l._getHelpCommand();return h&&!h._hidden&&m.push(h),this.sortSubcommands&&m.sort((f,v)=>f.name().localeCompare(v.name())),m}compareOptions(l,m){let h=f=>f.short?f.short.replace(/^-/,""):f.long.replace(/^--/,"");return h(l).localeCompare(h(m))}visibleOptions(l){let m=l.options.filter(f=>!f.hidden),h=l._getHelpOption();if(h&&!h.hidden){let f=h.short&&l._findOption(h.short),v=h.long&&l._findOption(h.long);!f&&!v?m.push(h):h.long&&!v?m.push(l.createOption(h.long,h.description)):h.short&&!f&&m.push(l.createOption(h.short,h.description))}return this.sortOptions&&m.sort(this.compareOptions),m}visibleGlobalOptions(l){if(!this.showGlobalOptions)return[];let m=[];for(let h=l.parent;h;h=h.parent){let f=h.options.filter(v=>!v.hidden);m.push(...f)}return this.sortOptions&&m.sort(this.compareOptions),m}visibleArguments(l){return l._argsDescription&&l.registeredArguments.forEach(m=>{m.description=m.description||l._argsDescription[m.name()]||""}),l.registeredArguments.find(m=>m.description)?l.registeredArguments:[]}subcommandTerm(l){let m=l.registeredArguments.map(h=>ate(h)).join(" ");return l._name+(l._aliases[0]?"|"+l._aliases[0]:"")+(l.options.length?" [options]":"")+(m?" "+m:"")}optionTerm(l){return l.flags}argumentTerm(l){return l.name()}longestSubcommandTermLength(l,m){return m.visibleCommands(l).reduce((h,f)=>Math.max(h,this.displayWidth(m.styleSubcommandTerm(m.subcommandTerm(f)))),0)}longestOptionTermLength(l,m){return m.visibleOptions(l).reduce((h,f)=>Math.max(h,this.displayWidth(m.styleOptionTerm(m.optionTerm(f)))),0)}longestGlobalOptionTermLength(l,m){return m.visibleGlobalOptions(l).reduce((h,f)=>Math.max(h,this.displayWidth(m.styleOptionTerm(m.optionTerm(f)))),0)}longestArgumentTermLength(l,m){return m.visibleArguments(l).reduce((h,f)=>Math.max(h,this.displayWidth(m.styleArgumentTerm(m.argumentTerm(f)))),0)}commandUsage(l){let m=l._name;l._aliases[0]&&(m=m+"|"+l._aliases[0]);let h="";for(let f=l.parent;f;f=f.parent)h=f.name()+" "+h;return h+m+" "+l.usage()}commandDescription(l){return l.description()}subcommandDescription(l){return l.summary()||l.description()}optionDescription(l){let m=[];if(l.argChoices&&m.push(`choices: ${l.argChoices.map(h=>JSON.stringify(h)).join(", ")}`),l.defaultValue!==void 0&&(l.required||l.optional||l.isBoolean()&&typeof l.defaultValue=="boolean")&&m.push(`default: ${l.defaultValueDescription||JSON.stringify(l.defaultValue)}`),l.presetArg!==void 0&&l.optional&&m.push(`preset: ${JSON.stringify(l.presetArg)}`),l.envVar!==void 0&&m.push(`env: ${l.envVar}`),m.length>0){let h=`(${m.join(", ")})`;return l.description?`${l.description} ${h}`:h}return l.description}argumentDescription(l){let m=[];if(l.argChoices&&m.push(`choices: ${l.argChoices.map(h=>JSON.stringify(h)).join(", ")}`),l.defaultValue!==void 0&&m.push(`default: ${l.defaultValueDescription||JSON.stringify(l.defaultValue)}`),m.length>0){let h=`(${m.join(", ")})`;return l.description?`${l.description} ${h}`:h}return l.description}formatItemList(l,m,h){return m.length===0?[]:[h.styleTitle(l),...m,""]}groupItems(l,m,h){let f=new Map;return l.forEach(v=>{let D=h(v);f.has(D)||f.set(D,[])}),m.forEach(v=>{let D=h(v);f.has(D)||f.set(D,[]),f.get(D).push(v)}),f}formatHelp(l,m){let h=m.padWidth(l,m),f=m.helpWidth??80;function v(Ne,se){return m.formatItem(Ne,h,se,m)}let D=[`${m.styleTitle("Usage:")} ${m.styleUsage(m.commandUsage(l))}`,""],$=m.commandDescription(l);$.length>0&&(D=D.concat([m.boxWrap(m.styleCommandDescription($),f),""]));let te=m.visibleArguments(l).map(Ne=>v(m.styleArgumentTerm(m.argumentTerm(Ne)),m.styleArgumentDescription(m.argumentDescription(Ne))));if(D=D.concat(this.formatItemList("Arguments:",te,m)),this.groupItems(l.options,m.visibleOptions(l),Ne=>Ne.helpGroupHeading??"Options:").forEach((Ne,se)=>{let ft=Ne.map(Ze=>v(m.styleOptionTerm(m.optionTerm(Ze)),m.styleOptionDescription(m.optionDescription(Ze))));D=D.concat(this.formatItemList(se,ft,m))}),m.showGlobalOptions){let Ne=m.visibleGlobalOptions(l).map(se=>v(m.styleOptionTerm(m.optionTerm(se)),m.styleOptionDescription(m.optionDescription(se))));D=D.concat(this.formatItemList("Global Options:",Ne,m))}return this.groupItems(l.commands,m.visibleCommands(l),Ne=>Ne.helpGroup()||"Commands:").forEach((Ne,se)=>{let ft=Ne.map(Ze=>v(m.styleSubcommandTerm(m.subcommandTerm(Ze)),m.styleSubcommandDescription(m.subcommandDescription(Ze))));D=D.concat(this.formatItemList(se,ft,m))}),D.join(`
|
|
435
435
|
`)}displayWidth(l){return(0,ZVe.stripVTControlCharacters)(l).length}styleTitle(l){return l}styleUsage(l){return l.split(" ").map(m=>m==="[options]"?this.styleOptionText(m):m==="[command]"?this.styleSubcommandText(m):m[0]==="["||m[0]==="<"?this.styleArgumentText(m):this.styleCommandText(m)).join(" ")}styleCommandDescription(l){return this.styleDescriptionText(l)}styleOptionDescription(l){return this.styleDescriptionText(l)}styleSubcommandDescription(l){return this.styleDescriptionText(l)}styleArgumentDescription(l){return this.styleDescriptionText(l)}styleDescriptionText(l){return l}styleOptionTerm(l){return this.styleOptionText(l)}styleSubcommandTerm(l){return l.split(" ").map(m=>m==="[options]"?this.styleOptionText(m):m[0]==="["||m[0]==="<"?this.styleArgumentText(m):this.styleSubcommandText(m)).join(" ")}styleArgumentTerm(l){return this.styleArgumentText(l)}styleOptionText(l){return l}styleArgumentText(l){return l}styleSubcommandText(l){return l}styleCommandText(l){return l}padWidth(l,m){return Math.max(m.longestOptionTermLength(l,m),m.longestGlobalOptionTermLength(l,m),m.longestSubcommandTermLength(l,m),m.longestArgumentTermLength(l,m))}preformatted(l){return/\n[^\S\r\n]/.test(l)}formatItem(l,m,h,f){let D=" ".repeat(2);if(!h)return D+l;let $=l.padEnd(m+l.length-f.displayWidth(l)),te=2,he=(this.helpWidth??80)-m-te-2,Ne;return he<this.minWidthToWrap||f.preformatted(h)?Ne=h:Ne=f.boxWrap(h,he).replace(/\n/g,`
|
|
436
436
|
`+" ".repeat(m+te)),D+$+" ".repeat(te)+Ne.replace(/\n/g,`
|
|
437
437
|
${D}`)}boxWrap(l,m){if(m<this.minWidthToWrap)return l;let h=l.split(/\r\n|\n/),f=/[\s]*[^\s]+/g,v=[];return h.forEach(D=>{let $=D.match(f);if($===null){v.push("");return}let te=[$.shift()],fe=this.displayWidth(te[0]);$.forEach(he=>{let Ne=this.displayWidth(he);if(fe+Ne<=m){te.push(he),fe+=Ne;return}v.push(te.join(""));let se=he.trimStart();te=[se],fe=this.displayWidth(se)}),v.push(te.join(""))}),v.join(`
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
id: VBC-006-B
|
|
2
|
+
name: merge-conflict-markers
|
|
3
|
+
severity: error
|
|
4
|
+
category: correctness
|
|
5
|
+
tags:
|
|
6
|
+
- correctness
|
|
7
|
+
- git
|
|
8
|
+
match:
|
|
9
|
+
# Anchored to the line start and requiring exactly seven characters, because
|
|
10
|
+
# that is what git writes. Read as text rather than through the scanner: a
|
|
11
|
+
# file with conflict markers in it does not parse, so there is no scope to ask.
|
|
12
|
+
regex: '^(?:<{7}|={7}|>{7})(?: |$)'
|
|
13
|
+
flags: m
|
|
14
|
+
scan: all
|
|
15
|
+
exclude_files:
|
|
16
|
+
- '**/*.md'
|
|
17
|
+
- '**/*.txt'
|
|
18
|
+
- '**/*.mdx'
|
|
19
|
+
message: >-
|
|
20
|
+
Merge conflict marker at line {line}. Git wrote this and nobody finished the merge, so
|
|
21
|
+
the file holds both sides of a change and compiles as neither.
|
|
22
|
+
tests:
|
|
23
|
+
fire:
|
|
24
|
+
- |
|
|
25
|
+
const a = 1;
|
|
26
|
+
<<<<<<< HEAD
|
|
27
|
+
const b = 2;
|
|
28
|
+
=======
|
|
29
|
+
const b = 3;
|
|
30
|
+
>>>>>>> feature/x
|
|
31
|
+
quiet:
|
|
32
|
+
- const arrow = a >>> b;
|
|
33
|
+
- '// ======= section ======='
|
|
34
|
+
- const shifted = value >>> 2;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
id: VBC-017-B
|
|
2
|
+
name: focused-test-committed
|
|
3
|
+
severity: error
|
|
4
|
+
category: correctness
|
|
5
|
+
tags:
|
|
6
|
+
- correctness
|
|
7
|
+
- testing
|
|
8
|
+
match:
|
|
9
|
+
# `.only` is the dangerous one: the suite still passes, having run one test.
|
|
10
|
+
# A skipped test is at least visibly skipped.
|
|
11
|
+
regex: \b(?:describe|it|test|context|suite)\.only\s*\(|^\s*(?:fdescribe|fit)\s*\(
|
|
12
|
+
flags: m
|
|
13
|
+
scan: code
|
|
14
|
+
file_types:
|
|
15
|
+
- js
|
|
16
|
+
- jsx
|
|
17
|
+
- ts
|
|
18
|
+
- tsx
|
|
19
|
+
message: >-
|
|
20
|
+
Focused test at line {line}. Committed, it runs this test and silently skips every other
|
|
21
|
+
one in the file, and the suite still reports green.
|
|
22
|
+
tests:
|
|
23
|
+
fire:
|
|
24
|
+
- describe.only("the parser", () => {});
|
|
25
|
+
- it.only("returns the cached value", async () => {});
|
|
26
|
+
- ' fdescribe("suite", () => {});'
|
|
27
|
+
quiet:
|
|
28
|
+
- describe("the parser", () => {});
|
|
29
|
+
- const only = items.only;
|
|
30
|
+
- expect(list.only).toBe(true);
|