dts-linter 0.0.0-beta5 → 0.0.0-beta6
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/dist/dts-linter.js +5 -5
- package/package.json +1 -1
package/dist/dts-linter.js
CHANGED
|
@@ -87,7 +87,7 @@ Options:
|
|
|
87
87
|
|
|
88
88
|
Example:
|
|
89
89
|
dts-linter --files file1.dts --files file2.dtsi --format --diagnostics`,at;try{let{values:t}=(0,uh.parseArgs)({options:{files:{type:"string",multiple:!0},cwd:{type:"string"},includes:{type:"string",multiple:!0},bindings:{type:"string",multiple:!0},logLevel:{type:"string"},format:{type:"boolean"},formatFixAll:{type:"boolean"},processIncludes:{type:"boolean"},diagnostics:{type:"boolean"},diagnosticsFull:{type:"boolean"},outFile:{type:"string"},help:{type:"boolean"}},strict:!0}),e=Cg.safeParse(t);e.success||(console.log(kc),process.exit(1)),at=e.data}catch{console.log(kc),process.exit(1)}at.help&&(console.log("Invalid arguments"),console.log(kc),process.exit(0));var oi=at.cwd??process.cwd(),fh=at.files.filter(t=>t).map(t=>(0,dh.resolve)(oi,t)),Pg=at.includes,xg=at.bindings,Dg=at.logLevel,hh=at.formatFixAll,ih=at.format||hh,Pc=at.diagnosticsFull,sh=at.diagnostics||Pc,Eg=at.processIncludes,Sc=at.outFile,oh=0,Og=fh.length,ai=new Map,ws=[],mn=new Map;Ng().catch(t=>{console.error("Error validating files:",t),process.exit(1)});async function Ng(){let t=ah.default.spawn(vg,["--stdio"],{stdio:["pipe","pipe","pipe"]});t.stderr.on("data",u=>{console.error("LSP stderr:",u.toString())});let e=(0,ch.createMessageConnection)(new Ss.StreamMessageReader(t.stdout),new Ss.StreamMessageWriter(t.stdin));Dg==="verbose"&&e.onNotification("window/logMessage",u=>{let y={1:"ERROR",2:"WARN",3:"INFO",4:"LOG"}[u.type]||"LOG";console.log(`[LSP ${y}] ${u.message}`)}),e.onRequest("workspace/workspaceFolders",()=>[{uri:`file://${oi}`,name:"root"}]),e.listen(),e.sendNotification("workspace/didChangeConfiguration",{settings:{devicetree:{defaultIncludePaths:Pg,defaultBindingType:"Zephyr",defaultZephyrBindings:xg,cwd:oi,autoChangeContext:!0,allowAdhocContexts:!0,defaultLockRenameEdits:[]}}});let n=[{uri:bc(oi),name:"root"}];await e.sendRequest("initialize",{processId:process.pid,rootUri:bc(oi),capabilities:{},workspaceFolders:n}),await e.sendNotification("initialized");let r=new Set,i=new Set,s=Array.from(new Set(fh)).sort((u,l)=>{let y=g=>g.endsWith(".dts")?0:g.endsWith(".dtsi")?1:2;return y(u)-y(l)});for(let u of s){oh++;let l=Fn.default.readFileSync(u,"utf8"),y={uri:bc(u),languageId:"devicetree",version:0,text:l};e.sendNotification("textDocument/didOpen",{textDocument:y});let g=await Ig(e),k=[...Cc(g.mainDtsPath),...g.overlays.flatMap(Cc)].filter(O=>!O.endsWith(".h")&&(0,Fn.existsSync)(O)&&(Eg||s.includes(O))),P=O=>O===u,Y=(O,F)=>O?`[${oh}/${Og}]`:`[${F}/${k.length-1}]`.padEnd((k.length-1).toString().length*2+3," ");ih&&await Promise.all(k.map(async(O,F)=>{let j=P(O),H=Y(j,F);try{await Mg(e,O,j,H,g)}catch(ae){console.log(`${Rs()}${ot("error",O,"Formatting",void 0,void 0,void 0,H)}`),console.log(ae instanceof Error?ae.message:JSON.stringify(ae)),console.log(ks())}r.add(O)})),sh&&await Promise.all(k.map(async(O,F)=>{let j=P(O);if(u.endsWith(".dts")||!Pc){let H=await qg(e,O,j,Y(j,F));H?.length&&(mn.has(O)||mn.set(O,[]),mn.get(O)?.push({context:g,message:H.map(ae=>`${ae.message}: ${JSON.stringify(ae.range.start)}-${JSON.stringify(ae.range.end)}`).join(`
|
|
90
|
-
`)}))}else wc.add(O),console.log(`${
|
|
90
|
+
`)}))}else wc.add(O),console.log(`${ot("warn",O,"Diagnostics","Check can only be done on full context!",void 0,void 0,`${j?"":" "}${Y(j,F)} `)}`);r.add(O)})),e.sendNotification("textDocument/didClose",{textDocument:{uri:`file://${u}`}}),await Ag(e),hh&&k.filter(O=>!i.has(O)).forEach(O=>{let F=ai.get(O);if(F){let j=_c(Fn.default.readFileSync(O,"utf8"),F);j?(i.add(O),Fn.default.writeFileSync(O,j,"utf8")):console.log(`${ot("error",O,"Formatting","Failed to apply changes to file")}`)}})}Sc&&Fn.default.writeFileSync(Sc,Array.from(ai.values()).join(`
|
|
91
91
|
|
|
92
92
|
`)),console.log("Processed",r.size,"files"),e.dispose(),t.kill(),ih&&(ws.length?console.log(`${ot("error",void 0,"Formatting",`${ws.length} of ${r.size} Failed formatting checks`)}`):console.log(`${Rc()} All files passed formatting`)),sh&&(console.log("Diagnostic issues summary"),mn.size&&(console.log(Array.from(mn.entries()).flatMap(([u,l])=>`${Rs()}File: ${u}
|
|
93
93
|
${l.flatMap(y=>`Board File: ${y.context.mainDtsPath.file}
|
|
@@ -96,8 +96,8 @@ Example:
|
|
|
96
96
|
`)}
|
|
97
97
|
${ks()}`).join(`
|
|
98
98
|
`)),console.log(`
|
|
99
|
-
${ot("error",void 0,"Diagnostics",`${mn.size} of ${r.size} file failed diagnostic checks`)}`)),wc.size&&console.log(`${ot("warn",void 0,"Diagnostics",`${wc.size} of ${r.size} Skipped diagnostic checks`)}`),ph.size===r.size&&!mn.size&&console.log(`${Rc()} All files passed diagnostic checks`)),process.exit(ws.length||mn?1:0)}var Cc=t=>[t.file,...t.includes.flatMap(e=>Cc(e))],Mg=async(t,e,n,r,i)=>{let s={textDocument:{uri:`file://${e}`},options:{tabSize:8,insertSpaces:!1,trimTrailingWhitespace:!0}},u=await t.sendRequest("devicetree/formattingDiff",s),l=n?"":" ";if(u)return console.log(`${Rs()}${
|
|
100
|
-
`,"\\n"),{line:y.lineStart,col:y.colStart},{line:y.lineEnd,col:y.colEnd})}`)}),console.log(ks()),u;console.log(`${
|
|
99
|
+
${ot("error",void 0,"Diagnostics",`${mn.size} of ${r.size} file failed diagnostic checks`)}`)),wc.size&&console.log(`${ot("warn",void 0,"Diagnostics",`${wc.size} of ${r.size} Skipped diagnostic checks`)}`),ph.size===r.size&&!mn.size&&console.log(`${Rc()} All files passed diagnostic checks`)),process.exit(ws.length||mn?1:0)}var Cc=t=>[t.file,...t.includes.flatMap(e=>Cc(e))],Mg=async(t,e,n,r,i)=>{let s={textDocument:{uri:`file://${e}`},options:{tabSize:8,insertSpaces:!1,trimTrailingWhitespace:!0}},u=await t.sendRequest("devicetree/formattingDiff",s),l=n?"":" ";if(u)return console.log(`${Rs()}${ot("error",e,"Formating","not correctly formatted.",void 0,void 0,`${l}${r} `)}`),ai.has(e)?ai.get(e)!==u&&Sc&&console.log(`${l} ${ot("warn",e,"Conflicting Diff","Multiple diffs for the same file. This diff will not be in the generated file!")}`):(ws.push({file:e,context:i}),ai.set(e,u)),jg(u).forEach(y=>{console.log(`${ot("error",e,"Fix",y.replacement.replaceAll(" ","\\t").replaceAll(`
|
|
100
|
+
`,"\\n"),{line:y.lineStart,col:y.colStart},{line:y.lineEnd,col:y.colEnd},`${l}${r} `)}`)}),console.log(ks()),u;console.log(`${ot("info",e,"Formaing","Correctly formatted",void 0,void 0,`${l}${r} `)}`)};function jg(t){let e=si(t),n=[];for(let r of e)for(let i of r.hunks){let s=i.oldStart,u=i.newStart,l=null,y=()=>{if(!l)return;let{oldLines:g,newLines:k,line:P}=l;if(g.length===1&&k.length===1){let Y=g[0],O=k[0],F=gc(Y,O),j=1;for(let H of F)if(H.added)n.push({lineStart:P,colStart:j,lineEnd:P,colEnd:j,replacement:H.value});else if(H.removed){let ae=j;j+=H.value.length,n.push({lineStart:P,colStart:ae,lineEnd:P,colEnd:j,replacement:""})}else j+=H.value.length}else g.length&&k.length?n.push({lineStart:P,colStart:1,lineEnd:P+g.length-1,colEnd:g[g.length-1].length+1,replacement:k.join(`
|
|
101
101
|
`)}):g.length?n.push({lineStart:P,colStart:1,lineEnd:P+g.length-1,colEnd:g[g.length-1].length+1,replacement:""}):k.length&&n.push({lineStart:P,colStart:1,lineEnd:P,colEnd:1,replacement:k.join(`
|
|
102
|
-
`)});l=null};for(let g of i.lines){let k=g[0],P=g.slice(1);k===" "?(y(),s++,u++):k==="-"?(l||(l={oldLines:[],newLines:[],line:s}),l.oldLines.push(P),s++):k==="+"&&(l||(l={oldLines:[],newLines:[],line:u}),l.newLines.push(P),u++)}y()}return n}var ph=new Set,wc=new Set,qg=async(t,e,n,r)=>{ph.add(e);let i=(await t.sendRequest("devicetree/diagnosticIssues",{uri:`file://${e}`,full:Pc})??[]).filter(u=>u.severity===Tc.DiagnosticSeverity.Error||u.severity===Tc.DiagnosticSeverity.Warning),s=n?"":" ";if(i.length)return console.log(`${Rs()}${
|
|
103
|
-
`)),console.log(ks()),i;console.log(`${
|
|
102
|
+
`)});l=null};for(let g of i.lines){let k=g[0],P=g.slice(1);k===" "?(y(),s++,u++):k==="-"?(l||(l={oldLines:[],newLines:[],line:s}),l.oldLines.push(P),s++):k==="+"&&(l||(l={oldLines:[],newLines:[],line:u}),l.newLines.push(P),u++)}y()}return n}var ph=new Set,wc=new Set,qg=async(t,e,n,r)=>{ph.add(e);let i=(await t.sendRequest("devicetree/diagnosticIssues",{uri:`file://${e}`,full:Pc})??[]).filter(u=>u.severity===Tc.DiagnosticSeverity.Error||u.severity===Tc.DiagnosticSeverity.Warning),s=n?"":" ";if(i.length)return console.log(`${Rs()}${ot("error",e,"Diagnostic errors",`${i.length} diagnostic errors!`,void 0,void 0,`${s}${r} `)}`),console.log(i.map(u=>`${s} ${ot("error",e,"Diagnostic error",u.message,{line:u.range.start.line,col:u.range.start.character},{line:u.range.end.line,col:u.range.end.character})}`).join(`
|
|
103
|
+
`)),console.log(ks()),i;console.log(`${ot("info",e,"Diagnostic","No diagnostic errors",void 0,void 0,`${s}${r} `)}`)};function Ig(t,e=6e4){return new Promise((n,r)=>{let i=setTimeout(()=>{r(new Error("Timed out waiting for devicetree/newActiveContext")),s.dispose()},e),s=t.onNotification("devicetree/newActiveContext",u=>{clearTimeout(i),n(u),s.dispose()})})}function Ag(t,e=5e3){return new Promise((n,r)=>{let i=setTimeout(()=>{r(new Error("Timed out waiting for devicetree/contextDeleted")),s.dispose()},e),s=t.onNotification("devicetree/contextDeleted",()=>{clearTimeout(i),n(),s.dispose()})})}
|