@webority/repo-checks 0.140.2 → 0.141.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/dist/repo-checks.js +5 -5
- package/package.json +2 -2
package/dist/repo-checks.js
CHANGED
|
@@ -156,11 +156,11 @@ fi
|
|
|
156
156
|
`&&n!=="`")&&(n=null);else if(i===`/`&&a===`/`){let n=e.indexOf(`
|
|
157
157
|
`,r),i=n===-1?e.length:n;t+=` `.repeat(i-r),r=i-1}else if(i===`/`&&a===`*`){let n=e.indexOf(`*/`,r+2),i=n===-1?e.length:n+2;t+=e.slice(r,i).replace(/[^\n]/g,` `),r=i-1}else(i===`"`||i===`'`||i==="`")&&(n=i),t+=i}return t}function xs(e,t){let n=[],r=e[t];if(r===`"`||r===`'`){let i=e.indexOf(r,t+1);i!==-1&&n.push({base:t+1,content:e.slice(t+1,i)})}else if(r===`{`){let r=0,i=t;for(;i<e.length;i+=1)if(e[i]===`{`)r+=1;else if(e[i]===`}`&&(--r,r===0))break;let a=e.slice(t,i);for(let e of a.matchAll(ys))n.push({base:t+e.index+1,content:e[2]})}return n}function Ss(e,t){let n=t===`markup`?C(e,`markup`):bs(e),r=[0];for(let e=0;e<n.length;e+=1)n[e]===`
|
|
158
158
|
`&&r.push(e+1);let i=e.split(`
|
|
159
|
-
`),a=e=>{let t=0,n=r.length-1;for(;t<n;){let i=t+n+1>>1;r[i]<=e?t=i:n=i-1}return t},o=[];for(let e of n.matchAll(vs)){let t=e.index+e[0].length;for(let e of xs(n,t))for(let t of e.content.matchAll(/\S+/g)){let n=_s.get(t[0]);if(!n)continue;let r=a(e.base+t.index);o.push({rule:gs,line:r+1,text:(i[r]??``).trim().slice(0,160),hint:`use ${n} in place of the raw Bootstrap class "${t[0]}"`})}}return o.sort((e,t)=>e.line-t.line),o}var Cs=`route-internal-id`,ws=`route by the record's public id ("{publicId:guid}"), never its internal number`,Ts=`pass the record's PublicId, never its internal Id`,Es=/^\s*@page\s+"([^"]*)"/gm,Ds=/\basp-route-([A-Za-z][\w-]*)\s*=\s*"@\(?\s*([\w.?!]+?)\.Id\s*\)?"/g,Os=/\b(?:Route|Http(?:Get|Post|Put|Patch|Delete))\s*\(\s*@?"([^"]*)"/g,ks=/\.Map(?:Get|Post|Put|Patch|Delete|Methods)?\s*\(\s*@?"([^"]*)"/g,As=/\{([^{}]*)\}/g,js=/^(?:[Ii]d|[a-z][A-Za-z0-9]*Id)$/,Ms=[`int`,`long`];function Ns(e){let t=[];for(let n of e.matchAll(As)){let[e,...r]=n[1].replace(/^\*{1,2}/,``).split(`:`),i=e.replace(/=.*$/,``).replace(/\?$/,``);js.test(i)&&r.some(e=>Ms.includes(e.replace(/\?$/,``)))&&t.push(i)}return t}function Ps(e,t){return e.slice(0,t).split(`
|
|
160
|
-
`).length}function
|
|
161
|
-
`),
|
|
159
|
+
`),a=e=>{let t=0,n=r.length-1;for(;t<n;){let i=t+n+1>>1;r[i]<=e?t=i:n=i-1}return t},o=[];for(let e of n.matchAll(vs)){let t=e.index+e[0].length;for(let e of xs(n,t))for(let t of e.content.matchAll(/\S+/g)){let n=_s.get(t[0]);if(!n)continue;let r=a(e.base+t.index);o.push({rule:gs,line:r+1,text:(i[r]??``).trim().slice(0,160),hint:`use ${n} in place of the raw Bootstrap class "${t[0]}"`})}}return o.sort((e,t)=>e.line-t.line),o}var Cs=`route-internal-id`,ws=`route by the record's public id ("{publicId:guid}"), never its internal number`,Ts=`pass the record's PublicId, never its internal Id`,Es=/^\s*@page\s+"([^"]*)"/gm,Ds=/\basp-route-([A-Za-z][\w-]*)\s*=\s*"@\(?\s*([\w.?!]+?)\.Id\s*\)?"/g,Os=/\b(?:Route|Http(?:Get|Post|Put|Patch|Delete))\s*\(\s*@?"([^"]*)"/g,ks=/\.Map(?:Get|Post|Put|Patch|Delete|Methods)?\s*\(\s*@?"([^"]*)"/g,As=/\{([^{}]*)\}/g,js=/^(?:[Ii]d|[a-z][A-Za-z0-9]*Id)$/,Ms=[`int`,`long`];function Ns(e){let t=[];for(let n of e.matchAll(As)){let[e,...r]=n[1].replace(/^\*{1,2}/,``).split(`:`),i=e.replace(/=.*$/,``).replace(/\?$/,``);js.test(i)&&r.some(e=>Ms.includes(e.replace(/\?$/,``)))&&t.push(i)}return t}function Ps(e){let t=[];for(let n of e.matchAll(As)){let[e,...r]=n[1].replace(/^\*{1,2}/,``).split(`:`);r.some(e=>e.replace(/\?$/,``)===`guid`)&&t.push(e.replace(/=.*$/,``).replace(/\?$/,``))}return t}function Fs(e,t){return e.slice(0,t).split(`
|
|
160
|
+
`).length}var Is=/\basp-page\s*=\s*"([^"]*)"/,Ls=/\basp-area\s*=\s*"([^"]*)"/,Rs=/(?:^|\/)(?:Areas\/([^/]+)\/)?Pages(\/.+)\.cshtml$/i;function zs(e){let t=e?Rs.exec(e.replaceAll(`\\`,`/`)):null;return t?{area:t[1]??null,path:t[2]}:null}function Bs(e,t,n){let r=e.lastIndexOf(`<`,t),i=e.indexOf(`>`,t),a=e.slice(r===-1?0:r,i===-1?e.length:i),o=Ls.exec(a)?.[1],s=Is.exec(a)?.[1];return s===void 0?o===void 0||n!==null&&o.toLowerCase()===(n.area??``).toLowerCase():n===null||o!==void 0&&o.toLowerCase()!==(n.area??``).toLowerCase()?!1:s.startsWith(`/`)?s.toLowerCase()===n.path.toLowerCase():s.split(`/`).pop()?.toLowerCase()===n.path.split(`/`).pop()?.toLowerCase()}function Vs(e,t,n){let r=e.split(`
|
|
161
|
+
`),i=[],a=(e,t)=>{i.push({rule:Cs,line:e,text:(r[e-1]??``).trim().slice(0,160),hint:t})},o=(e,t)=>{for(let n of Ns(e))a(t,ws)};if(t===`markup`){let t=C(e,`markup`),r=/* @__PURE__ */ new Set;for(let e of t.matchAll(Es)){o(e[1],Fs(t,e.index+e[0].indexOf(`@page`)));for(let t of Ps(e[1]))r.add(t.toLowerCase())}let s=zs(n);for(let e of t.matchAll(Ds))r.has(e[1].toLowerCase())&&Bs(t,e.index,s)||a(Fs(t,e.index),Ts);return i}for(let t of[Os,ks])for(let n of e.matchAll(t)){let t=Fs(e,n.index);(r[t-1]??``).trim().startsWith(`//`)||o(n[1],t)}return i}function Hs(e,t){if(!/\.(?:jsx|tsx|cshtml)$/i.test(e))return[];let n=t.endsWith(`
|
|
162
162
|
`)?t.split(`
|
|
163
163
|
`).length-1:t.split(`
|
|
164
|
-
`).length;return n>800?[{rule:`oversize`,line:1,text:`over 800 lines: split it along its concerns`,hint:null}]:n>600?[{rule:`oversize`,line:1,text:`over 600 lines`,hint:null}]:[]}var
|
|
164
|
+
`).length;return n>800?[{rule:`oversize`,line:1,text:`over 800 lines: split it along its concerns`,hint:null}]:n>600?[{rule:`oversize`,line:1,text:`over 600 lines`,hint:null}]:[]}var Us=`rename-wrapper`,Ws=`@webority/ui-react`,Gs=`["']${Ws}["']`,V=e=>e.replace(/[^\n]/g,` `),Ks=`shadowed-library-name`;function H(e,t,n,r=Us){let i=e.slice(0,t).split(`
|
|
165
165
|
`).length;return{rule:r,line:i,text:e.split(`
|
|
166
|
-
`)[i-1].trim(),hint:n}}function Vs(e){return e.replace(/\/\*[\s\S]*?\*\//g,V).replace(/\/\/[^\n]*/g,V)}function Hs(e){let t=/* @__PURE__ */ new Map,n=RegExp(`import\\s+(?:type\\s+)?([^;'"]*?)\\s+from\\s*${zs}`,`g`);for(let r of e.matchAll(n)){let e=r[1],n=e.match(/\{([^}]*)\}/);if(n)for(let e of n[1].split(`,`)){let n=e.trim().replace(/^type\s+/,``).split(/\s+as\s+/);n[0]&&t.set(n[n.length-1],n[0])}let i=e.match(/\*\s*as\s+(\w+)/);i&&t.set(i[1],`*`);let a=e.replace(/\{[^}]*\}/,``).replace(/\*\s*as\s+\w+/,``);for(let e of a.split(`,`)){let n=e.trim();/^\w+$/.test(n)&&t.set(n,`default`)}}return t}function Us(e){let t=RegExp(`^[ \\t]*export\\s+(?:type\\s+)?(?:\\*(?:\\s+as\\s+\\w+)?|\\{[^}]*\\})\\s*from\\s*${zs}`,`gm`);return[...e.matchAll(t)].map(t=>H(e,t.index,`Import the name from ${Rs} where it is used; a file that only re-exports it adds nothing.`))}function Ws(e,t){let n=[];if(t.size===0)return n;let r=`Import the name from ${Rs} where it is used instead of exporting it through this file.`;for(let i of e.matchAll(/^[ \t]*export\s*\{([^}]*)\}(?!\s*from)/gm))i[1].split(`,`).some(e=>t.has(e.trim().replace(/^type\s+/,``).split(/\s+as\s+/)[0]))&&n.push(H(e,i.index,r));for(let i of e.matchAll(/^[ \t]*export\s+default\s+(\w+)\s*;?[ \t]*$/gm))t.has(i[1])&&n.push(H(e,i.index,r));return n}function Gs(e,t,n,r){if(!/\.(jsx|tsx)$/.test(e))return[];let i=Vs(t);if(/\buse[A-Z]\w*\s*[(<]/.test(i)||/\b(if|switch)\s*\(/.test(i)||[...i.matchAll(/\breturn\b/g)].length>1)return[];let a=i.match(/(?:\breturn|=>)\s*\(?\s*<([A-Za-z][\w.]*)/);if(!a)return[];let o=a[1],s=r.get(o);return!s||s===`*`||!n.has(s)||[...i.matchAll(/<([A-Za-z][\w.]*)/g)].length!==1||/[?]|&&|\|\|/.test(i.slice(a.index))?[]:[H(t,a.index,`Import ${s} from ${Rs} and use it where this component is used instead of a wrapper.`)]}function Ks(e,t){let n=e.split(/[\\/]/).pop();if(!n.startsWith(`_`)||!n.endsWith(`.cshtml`))return[];let r=t.replace(/@\*[\s\S]*?\*@/g,V).replace(/<!--[\s\S]*?-->/g,V).replace(/^[ \t]*@(?:model|using)\b[^\n]*/gm,V),i=r.search(/\S/);if(i<0)return[];let a=r.slice(i).trimEnd(),o=a.match(/^<(app-[a-z0-9-]+)/);return!o||!a.endsWith(`/>`)&&!a.endsWith(`</${o[1]}>`)||(a.match(/<[A-Za-z]/g)||[]).length!==1?[]:[H(t,i,`Render the <${o[1]}> tag directly where the partial is used instead of a partial that only renders it.`)]}function qs(e,t,n,r){let i=[];for(let[a,o]of r){if(a===o||!n.has(o))continue;let r=RegExp(`\\b(?:function|class|const|let|var)\\s+${o}\\b`).exec(e);r&&i.push(H(t,r.index,`Declares ${o} over the library's ${o}; use the library component and its props, or give the product component its own name.`,Bs))}return i}function Js(e,t,n){let r=Hs(t);return[...Us(t),...Ws(t,r),...Gs(e,t,n,r),...Ks(e,t),.../\.(jsx|tsx)$/.test(e)?qs(Vs(t),t,n,r):[]]}var Ys=()=>new Set(hs),Xs=[`*.js`,`*.jsx`,`*.ts`,`*.tsx`],Zs=/(?:\bfrom\s*|\brequire\(\s*)["'](?:react-native|@webority\/mobile-ui)(?:\/[^"']*)?["']/;function Qs(e,t,n,i,a){let o=/* @__PURE__ */ new Set;for(let s of O(D(e,t))){if(s.kind!==`import`||s.imported.length===0)continue;let c=$o(t,s.specifier,i);if(c===null)continue;let l=`${n}:${c}`;a.has(l)||a.set(l,yo(r(d(e,c),`utf8`),{phone:n}));let u=a.get(l);for(let{name:e,local:t}of s.imported)u.has(e)&&o.add(t)}return o}var $s=[`*.js`,`*.jsx`,`*.ts`,`*.tsx`,`*.cshtml`];function ec(e){let n=[];for(let i of L(e,[`package.json`])){if(!t(d(e,i)))continue;let a;try{a=JSON.parse(r(d(e,i),`utf8`))}catch{continue}if(ga(a,d(e,p.dirname(i)))!==`mobile`)continue;let o=p.dirname(i);n.push(o===`.`?`src/`:`${o}/src/`)}return n}function tc(e,n=null){let i=n?n.map(t=>fa(e,t)):null,a=ec(e),o=e=>!i||i.some(t=>t===`.`||e===t||e.startsWith(`${t}/`)),s=L(e,Object.keys(Se).map(e=>`*${e}`)).filter(n=>t(d(e,n))&&!Ne(n,e)&&o(n)),c=[],l=Ys(),f=qa(e),p=Ga(e),m=null,h=/* @__PURE__ */ new Map;for(let n of s){let i=u(n).toLowerCase(),o=Se[i],s=r(d(e,n),`utf8`),g=n.startsWith(`packages/`)||n.startsWith(`samples/`),_=f&&g,v=()=>_?[]:[...Ss(s,o),...Js(n,s,p)],y=[];if(o===`scss`||o===`css`||o===`markup`)y=xn(s,o),o!==`scss`&&o!==`css`||_||y.push(...ms(s,o,l)),o===`markup`&&y.push(...v(),...g?[]:ds(s),...g?[]:Fs(s,`markup`),...Is(n,s));else if(o===`script`){let r=!g&&a.some(e=>n.startsWith(e)),o=qn(s)||r;if(Ce.includes(i)&&!o)continue;let c=[];if(!g){let i=r||Zs.test(s);m??=new Set(L(e,Xs).filter(n=>t(d(e,n)))),c=bo(s,{phone:i,keyedImports:s.includes(`.map(`)?Qs(e,n,i,m,h):/* @__PURE__ */ new Set})}y=[...Jn(s,{phone:o,colourLiterals:r}),...c],r&&a.some(e=>n===`${e}assets/theme/settings.js`)&&(y=y.filter(e=>e.rule!==`raw-colour`)),(i===`.jsx`||i===`.tsx`)&&y.push(...v(),...Is(n,s))}else o===`csharp`&&(g||(y=Fs(s,`csharp`)));for(let e of y)c.push({id:`${e.rule}:${n}`,line:e.line,text:e.text,hint:e.hint})}let g=L(e,$s).filter(n=>t(d(e,n)));for(let t of Zo(e,g)){let n=t.file.startsWith(`packages/`)||t.file.startsWith(`samples/`);o(t.file)&&!Ne(t.file,e)&&!n&&c.push({id:`${t.rule}:${t.file}`,line:t.line,text:t.text,hint:t.hint})}return c.sort((e,t)=>e.id<t.id?-1:e.id>t.id?1:e.line-t.line)}function nc(e){let t={};for(let n of e)t[n.id]=(t[n.id]||0)+1;return t}var U=process.argv.slice(2),rc=/* @__PURE__ */ new Set([`--baseline-accept`,`--reason`,`--baseline-adopt`]),ic=new Set(U.flatMap((e,t)=>rc.has(e)?[t+1]:[])),W=new Set(U.filter((e,t)=>e.startsWith(`--`)&&!ic.has(t))),G=U.filter((e,t)=>!e.startsWith(`--`)&&!ic.has(t)),ac=W.has(`--sync-hook`),oc=e=>U.includes(e)?U[U.indexOf(e)+1]:void 0,sc=oc(`--baseline-accept`),cc=oc(`--reason`),lc=oc(`--baseline-adopt`)?.split(`,`).map(e=>e.trim()).filter(Boolean),uc=e=>typeof e==`string`&&e.trim()!==``,K=e=>process.stdout.write(`${e}\n`),q=e=>process.stderr.write(`${e}\n`);W.has(`--json`)&&(console.log=(...e)=>console.error(...e));var dc=/* @__PURE__ */ new Set([`--json`,`--offline`,`--baseline-init`,`--baseline-shrink`,`--baseline-accept`,`--reason`,`--sync-hook`,`--baseline-adopt`]),fc=[...W].filter(e=>!dc.has(e)),pc=W.has(`--baseline-accept`),mc=(pc||W.has(`--reason`))&&!(uc(sc)&&uc(cc)),hc=pc&&(W.has(`--baseline-init`)||W.has(`--baseline-shrink`)||ac||W.has(`--baseline-adopt`)),gc=W.has(`--baseline-adopt`)&&(W.has(`--baseline-init`)||W.has(`--baseline-shrink`)||W.has(`--baseline-accept`)||ac);(fc.length||W.has(`--baseline-init`)&&W.has(`--baseline-shrink`)||ac&&(W.size>1||G.length)||mc||hc||gc)&&(q(`repo-checks: unknown or conflicting options ${fc.join(` `)}`.trim()),q(`usage: webority-repo-checks [--json] [--offline] [--baseline-init | --baseline-shrink] [--baseline-accept <folder> --reason <text>] [--baseline-adopt <rule,...>] [app folder ...]`),q(` webority-repo-checks --sync-hook`),process.exit(2));var J=ma(process.cwd());if(J||(q(`repo-checks: not inside a git repository.`),process.exit(2)),ac){let t=d(J,to);n(l(t),{recursive:!0}),s(t,lt),e(t,493),K(`repo-checks: wrote ${t}`),process.exit(0)}var _c=W.has(`--offline`);_c&&q(`repo-checks: advisory rule skipped (--offline).`);var vc=ao(J,G.length?G.map(e=>h(process.cwd(),e)):null,{advisories:!_c}).sort((e,t)=>e.pkg===t.pkg?0:e.pkg<t.pkg?-1:1),yc=vc.filter(e=>e.warning),bc=vc.filter(e=>!e.warning),xc=bc.filter(e=>e.id.startsWith(`lint:`)),Sc=bc.filter(e=>!e.id.startsWith(`lint:`)),Cc=tc(J,G.length?G.map(e=>h(process.cwd(),e)):null),Y={findings:Sc.map(e=>ee(e.pkg,e.id)),counts:nc(Cc)},wc=new Map(Sc.map(e=>[ee(e.pkg,e.id),e]));if(W.has(`--baseline-init`)){G.length&&(q(`repo-checks: --baseline-init reads the whole repository; run it without folder arguments.`),process.exit(2)),t(d(J,`.webority/baselines/repo-checks-baseline.json`))&&(q(`repo-checks: ${y} already exists. It only shrinks: fix a new finding, or run --baseline-shrink after fixing old ones.`),process.exit(2)),ae(J,oe(Y));let e=Object.keys(Y.counts).length;K(`repo-checks: recorded ${Sc.length} finding(s) and ${e} counted file(s) (${Cc.length} code finding(s)) in ${y}.`),process.exit(0)}var X=(()=>{try{return te(J)}catch(e){throw e instanceof x&&(q(`repo-checks: ${e.message}`),process.exit(2)),e}})();if(W.has(`--baseline-shrink`)){G.length&&(q(`repo-checks: --baseline-shrink reads the whole repository; run it without folder arguments.`),process.exit(2)),X===null&&(q(`repo-checks: no ${y}; run webority-repo-checks --baseline-init first.`),process.exit(2));let e=le(X,Y);ae(J,ue(X,Y)),K(`repo-checks: dropped ${e.stale.length} fixed finding(s) and lowered ${e.fallen.length} count(s) in ${y}.`),process.exit(0)}if(pc){G.length&&(q(`repo-checks: --baseline-accept reads the whole repository; run it without folder arguments.`),process.exit(2)),X===null&&(q(`repo-checks: no ${y}; run webority-repo-checks --baseline-init first.`),process.exit(2));let e=de(X,Y,sc,cc),t=new Set(X.findings),n=e.findings.filter(e=>!t.has(e)).length,r=Object.keys(e.counts).filter(t=>(X.counts[t]??0)<e.counts[t]).length;ae(J,e),K(`repo-checks: accepted ${n} finding(s) and ${r} count(s) under ${sc} (${cc}).`),process.exit(0)}if(W.has(`--baseline-adopt`)){G.length&&(q(`repo-checks: --baseline-adopt reads the whole repository; run it without folder arguments.`),process.exit(2)),X===null&&(q(`repo-checks: no ${y}; run webority-repo-checks --baseline-init first.`),process.exit(2)),lc?.length||(q(`repo-checks: --baseline-adopt needs a comma-separated list of rule ids.`),process.exit(2));let e;try{e=se(X,Y,lc)}catch(e){throw e instanceof x&&(q(`repo-checks: ${e.message}`),process.exit(2)),e}ae(J,e);let t=new Set(X.findings);for(let n of lc){let r=e.findings.filter(e=>!t.has(e)&&S(e)[1].split(`:`)[0]===n).length,i=Object.keys(e.counts).filter(e=>!(e in X.counts)&&e.split(`:`)[0]===n).length;K(`repo-checks: adopted ${r} finding(s) and ${i} count(s) for ${n} in ${y}.`)}process.exit(0)}var Tc=new Set(G.map(e=>m(J,h(process.cwd(),e)).split(`\\`).join(`/`)||`.`)),Ec=G.length?{pkgs:Tc,dirs:[...Tc]}:null,Z=le(ce(X??{version:2,findings:[],counts:{}},Ec),Y),Dc={"raw-measure":Pe,"palette-read":Le,"raw-colour":Fe,"root-font-size":Ie,"raw-motion":Re,"dark-read":ze,"missing-canvas-key":Be,"repeated-canvas-key":Ve},Oc=e=>Dc[e.slice(0,e.indexOf(`:`))],Q=[...Z.fresh.map(e=>wc.get(e)),...xc],kc=Z.known.map(e=>wc.get(e)),Ac=e=>[`${e.current} found, ${e.baseline} recorded.`,Oc(e.id)].filter(Boolean).join(` `),jc=e=>Xi(e.id.split(`:`)[0]),$=Z.over.filter(jc).map(e=>({pkg:`.`,id:e.id,message:Ac(e),lines:Cc.filter(t=>t.id===e.id).map(({line:e,text:t,hint:n})=>({line:e,text:t,hint:n}))})),Mc=Z.over.filter(e=>!jc(e)).map(e=>({pkg:`.`,id:e.id,message:Ac(e)})),Nc=Z.within.map(e=>({pkg:`.`,id:e.id,message:`${e.current} found, ${e.baseline} recorded.`})),Pc=[...Z.stale.map(S),...Z.fallen.map(e=>[`.`,e.id])],Fc=[...yc,...Mc];if(W.has(`--json`)||(()=>{if(Fc.length!==0){q(`repo-checks: ${Fc.length} warning(s), not enforced yet. Name a rule in REPO_CHECKS_ENFORCE (comma list, or all) to fail on it:`);for(let e of Fc)q(` - ${e.pkg} ${e.id}: ${e.message}`)}})(),W.has(`--json`)){let e={root:J,new:[...Q,...$],known:[...kc,...Nc],stale:Pc,warnings:Fc.map(e=>({pkg:e.pkg,id:e.id,message:e.message}))};K(JSON.stringify(e,null,2)),process.exitCode=Q.length||$.length?1:0}else if(Q.length||$.length){if(Q.length){q(`repo-checks: ${Q.length} new finding(s)`);let e=null;for(let t of Q)t.pkg!==e&&(e=t.pkg,q(` ${e}`)),q(` - ${t.id}: ${t.message}`)}if($.length){q(`repo-checks: ${$.length} file(s) above their recorded count`);for(let e of $){q(` ${e.id}: ${e.message}`);for(let t of e.lines)q(` ${t.line}: ${t.text}`),t.hint!==null&&q(` ${t.hint}`)}}process.exitCode=1}else{if(K(`repo-checks: no new findings.`),kc.length||Nc.length){let e=Z.within.reduce((e,t)=>e+t.current,0);K(`repo-checks: ${kc.length} known finding(s) and ${e} counted code finding(s) in ${Nc.length} file(s) recorded in ${y}.`)}if(Z.stale.length){K(`repo-checks: ${Z.stale.length} baseline entr${Z.stale.length===1?`y is`:`ies are`} fixed; drop them with webority-repo-checks --baseline-shrink:`);for(let e of Z.stale.map(S))K(` ${e[0]} ${e[1]}`)}if(Z.fallen.length){K(`repo-checks: ${Z.fallen.length} count(s) fell; record them with webority-repo-checks --baseline-shrink:`);for(let e of Z.fallen)K(` ${e.id} ${e.baseline} -> ${e.current}`)}}export{};
|
|
166
|
+
`)[i-1].trim(),hint:n}}function qs(e){return e.replace(/\/\*[\s\S]*?\*\//g,V).replace(/\/\/[^\n]*/g,V)}function Js(e){let t=/* @__PURE__ */ new Map,n=RegExp(`import\\s+(?:type\\s+)?([^;'"]*?)\\s+from\\s*${Gs}`,`g`);for(let r of e.matchAll(n)){let e=r[1],n=e.match(/\{([^}]*)\}/);if(n)for(let e of n[1].split(`,`)){let n=e.trim().replace(/^type\s+/,``).split(/\s+as\s+/);n[0]&&t.set(n[n.length-1],n[0])}let i=e.match(/\*\s*as\s+(\w+)/);i&&t.set(i[1],`*`);let a=e.replace(/\{[^}]*\}/,``).replace(/\*\s*as\s+\w+/,``);for(let e of a.split(`,`)){let n=e.trim();/^\w+$/.test(n)&&t.set(n,`default`)}}return t}function Ys(e){let t=RegExp(`^[ \\t]*export\\s+(?:type\\s+)?(?:\\*(?:\\s+as\\s+\\w+)?|\\{[^}]*\\})\\s*from\\s*${Gs}`,`gm`);return[...e.matchAll(t)].map(t=>H(e,t.index,`Import the name from ${Ws} where it is used; a file that only re-exports it adds nothing.`))}function Xs(e,t){let n=[];if(t.size===0)return n;let r=`Import the name from ${Ws} where it is used instead of exporting it through this file.`;for(let i of e.matchAll(/^[ \t]*export\s*\{([^}]*)\}(?!\s*from)/gm))i[1].split(`,`).some(e=>t.has(e.trim().replace(/^type\s+/,``).split(/\s+as\s+/)[0]))&&n.push(H(e,i.index,r));for(let i of e.matchAll(/^[ \t]*export\s+default\s+(\w+)\s*;?[ \t]*$/gm))t.has(i[1])&&n.push(H(e,i.index,r));return n}function Zs(e,t,n,r){if(!/\.(jsx|tsx)$/.test(e))return[];let i=qs(t);if(/\buse[A-Z]\w*\s*[(<]/.test(i)||/\b(if|switch)\s*\(/.test(i)||[...i.matchAll(/\breturn\b/g)].length>1)return[];let a=i.match(/(?:\breturn|=>)\s*\(?\s*<([A-Za-z][\w.]*)/);if(!a)return[];let o=a[1],s=r.get(o);return!s||s===`*`||!n.has(s)||[...i.matchAll(/<([A-Za-z][\w.]*)/g)].length!==1||/[?]|&&|\|\|/.test(i.slice(a.index))?[]:[H(t,a.index,`Import ${s} from ${Ws} and use it where this component is used instead of a wrapper.`)]}function Qs(e,t){let n=e.split(/[\\/]/).pop();if(!n.startsWith(`_`)||!n.endsWith(`.cshtml`))return[];let r=t.replace(/@\*[\s\S]*?\*@/g,V).replace(/<!--[\s\S]*?-->/g,V).replace(/^[ \t]*@(?:model|using)\b[^\n]*/gm,V),i=r.search(/\S/);if(i<0)return[];let a=r.slice(i).trimEnd(),o=a.match(/^<(app-[a-z0-9-]+)/);return!o||!a.endsWith(`/>`)&&!a.endsWith(`</${o[1]}>`)||(a.match(/<[A-Za-z]/g)||[]).length!==1?[]:[H(t,i,`Render the <${o[1]}> tag directly where the partial is used instead of a partial that only renders it.`)]}function $s(e,t,n,r){let i=[];for(let[a,o]of r){if(a===o||!n.has(o))continue;let r=RegExp(`\\b(?:function|class|const|let|var)\\s+${o}\\b`).exec(e);r&&i.push(H(t,r.index,`Declares ${o} over the library's ${o}; use the library component and its props, or give the product component its own name.`,Ks))}return i}function ec(e,t,n){let r=Js(t);return[...Ys(t),...Xs(t,r),...Zs(e,t,n,r),...Qs(e,t),.../\.(jsx|tsx)$/.test(e)?$s(qs(t),t,n,r):[]]}var tc=()=>new Set(hs),nc=[`*.js`,`*.jsx`,`*.ts`,`*.tsx`],rc=/(?:\bfrom\s*|\brequire\(\s*)["'](?:react-native|@webority\/mobile-ui)(?:\/[^"']*)?["']/;function ic(e,t,n,i,a){let o=/* @__PURE__ */ new Set;for(let s of O(D(e,t))){if(s.kind!==`import`||s.imported.length===0)continue;let c=$o(t,s.specifier,i);if(c===null)continue;let l=`${n}:${c}`;a.has(l)||a.set(l,yo(r(d(e,c),`utf8`),{phone:n}));let u=a.get(l);for(let{name:e,local:t}of s.imported)u.has(e)&&o.add(t)}return o}var ac=[`*.js`,`*.jsx`,`*.ts`,`*.tsx`,`*.cshtml`];function oc(e){let n=[];for(let i of L(e,[`package.json`])){if(!t(d(e,i)))continue;let a;try{a=JSON.parse(r(d(e,i),`utf8`))}catch{continue}if(ga(a,d(e,p.dirname(i)))!==`mobile`)continue;let o=p.dirname(i);n.push(o===`.`?`src/`:`${o}/src/`)}return n}function sc(e,n=null){let i=n?n.map(t=>fa(e,t)):null,a=oc(e),o=e=>!i||i.some(t=>t===`.`||e===t||e.startsWith(`${t}/`)),s=L(e,Object.keys(Se).map(e=>`*${e}`)).filter(n=>t(d(e,n))&&!Ne(n,e)&&o(n)),c=[],l=tc(),f=qa(e),p=Ga(e),m=null,h=/* @__PURE__ */ new Map;for(let n of s){let i=u(n).toLowerCase(),o=Se[i],s=r(d(e,n),`utf8`),g=n.startsWith(`packages/`)||n.startsWith(`samples/`),_=f&&g,v=()=>_?[]:[...Ss(s,o),...ec(n,s,p)],y=[];if(o===`scss`||o===`css`||o===`markup`)y=xn(s,o),o!==`scss`&&o!==`css`||_||y.push(...ms(s,o,l)),o===`markup`&&y.push(...v(),...g?[]:ds(s),...g?[]:Vs(s,`markup`,n),...Hs(n,s));else if(o===`script`){let r=!g&&a.some(e=>n.startsWith(e)),o=qn(s)||r;if(Ce.includes(i)&&!o)continue;let c=[];if(!g){let i=r||rc.test(s);m??=new Set(L(e,nc).filter(n=>t(d(e,n)))),c=bo(s,{phone:i,keyedImports:s.includes(`.map(`)?ic(e,n,i,m,h):/* @__PURE__ */ new Set})}y=[...Jn(s,{phone:o,colourLiterals:r}),...c],r&&a.some(e=>n===`${e}assets/theme/settings.js`)&&(y=y.filter(e=>e.rule!==`raw-colour`)),(i===`.jsx`||i===`.tsx`)&&y.push(...v(),...Hs(n,s))}else o===`csharp`&&(g||(y=Vs(s,`csharp`)));for(let e of y)c.push({id:`${e.rule}:${n}`,line:e.line,text:e.text,hint:e.hint})}let g=L(e,ac).filter(n=>t(d(e,n)));for(let t of Zo(e,g)){let n=t.file.startsWith(`packages/`)||t.file.startsWith(`samples/`);o(t.file)&&!Ne(t.file,e)&&!n&&c.push({id:`${t.rule}:${t.file}`,line:t.line,text:t.text,hint:t.hint})}return c.sort((e,t)=>e.id<t.id?-1:e.id>t.id?1:e.line-t.line)}function cc(e){let t={};for(let n of e)t[n.id]=(t[n.id]||0)+1;return t}var U=process.argv.slice(2),lc=/* @__PURE__ */ new Set([`--baseline-accept`,`--reason`,`--baseline-adopt`]),uc=new Set(U.flatMap((e,t)=>lc.has(e)?[t+1]:[])),W=new Set(U.filter((e,t)=>e.startsWith(`--`)&&!uc.has(t))),G=U.filter((e,t)=>!e.startsWith(`--`)&&!uc.has(t)),dc=W.has(`--sync-hook`),fc=e=>U.includes(e)?U[U.indexOf(e)+1]:void 0,pc=fc(`--baseline-accept`),mc=fc(`--reason`),hc=fc(`--baseline-adopt`)?.split(`,`).map(e=>e.trim()).filter(Boolean),gc=e=>typeof e==`string`&&e.trim()!==``,K=e=>process.stdout.write(`${e}\n`),q=e=>process.stderr.write(`${e}\n`);W.has(`--json`)&&(console.log=(...e)=>console.error(...e));var _c=/* @__PURE__ */ new Set([`--json`,`--offline`,`--baseline-init`,`--baseline-shrink`,`--baseline-accept`,`--reason`,`--sync-hook`,`--baseline-adopt`]),vc=[...W].filter(e=>!_c.has(e)),yc=W.has(`--baseline-accept`),bc=(yc||W.has(`--reason`))&&!(gc(pc)&&gc(mc)),xc=yc&&(W.has(`--baseline-init`)||W.has(`--baseline-shrink`)||dc||W.has(`--baseline-adopt`)),Sc=W.has(`--baseline-adopt`)&&(W.has(`--baseline-init`)||W.has(`--baseline-shrink`)||W.has(`--baseline-accept`)||dc);(vc.length||W.has(`--baseline-init`)&&W.has(`--baseline-shrink`)||dc&&(W.size>1||G.length)||bc||xc||Sc)&&(q(`repo-checks: unknown or conflicting options ${vc.join(` `)}`.trim()),q(`usage: webority-repo-checks [--json] [--offline] [--baseline-init | --baseline-shrink] [--baseline-accept <folder> --reason <text>] [--baseline-adopt <rule,...>] [app folder ...]`),q(` webority-repo-checks --sync-hook`),process.exit(2));var J=ma(process.cwd());if(J||(q(`repo-checks: not inside a git repository.`),process.exit(2)),dc){let t=d(J,to);n(l(t),{recursive:!0}),s(t,lt),e(t,493),K(`repo-checks: wrote ${t}`),process.exit(0)}var Cc=W.has(`--offline`);Cc&&q(`repo-checks: advisory rule skipped (--offline).`);var wc=ao(J,G.length?G.map(e=>h(process.cwd(),e)):null,{advisories:!Cc}).sort((e,t)=>e.pkg===t.pkg?0:e.pkg<t.pkg?-1:1),Tc=wc.filter(e=>e.warning),Ec=wc.filter(e=>!e.warning),Dc=Ec.filter(e=>e.id.startsWith(`lint:`)),Oc=Ec.filter(e=>!e.id.startsWith(`lint:`)),kc=sc(J,G.length?G.map(e=>h(process.cwd(),e)):null),Y={findings:Oc.map(e=>ee(e.pkg,e.id)),counts:cc(kc)},Ac=new Map(Oc.map(e=>[ee(e.pkg,e.id),e]));if(W.has(`--baseline-init`)){G.length&&(q(`repo-checks: --baseline-init reads the whole repository; run it without folder arguments.`),process.exit(2)),t(d(J,`.webority/baselines/repo-checks-baseline.json`))&&(q(`repo-checks: ${y} already exists. It only shrinks: fix a new finding, or run --baseline-shrink after fixing old ones.`),process.exit(2)),ae(J,oe(Y));let e=Object.keys(Y.counts).length;K(`repo-checks: recorded ${Oc.length} finding(s) and ${e} counted file(s) (${kc.length} code finding(s)) in ${y}.`),process.exit(0)}var X=(()=>{try{return te(J)}catch(e){throw e instanceof x&&(q(`repo-checks: ${e.message}`),process.exit(2)),e}})();if(W.has(`--baseline-shrink`)){G.length&&(q(`repo-checks: --baseline-shrink reads the whole repository; run it without folder arguments.`),process.exit(2)),X===null&&(q(`repo-checks: no ${y}; run webority-repo-checks --baseline-init first.`),process.exit(2));let e=le(X,Y);ae(J,ue(X,Y)),K(`repo-checks: dropped ${e.stale.length} fixed finding(s) and lowered ${e.fallen.length} count(s) in ${y}.`),process.exit(0)}if(yc){G.length&&(q(`repo-checks: --baseline-accept reads the whole repository; run it without folder arguments.`),process.exit(2)),X===null&&(q(`repo-checks: no ${y}; run webority-repo-checks --baseline-init first.`),process.exit(2));let e=de(X,Y,pc,mc),t=new Set(X.findings),n=e.findings.filter(e=>!t.has(e)).length,r=Object.keys(e.counts).filter(t=>(X.counts[t]??0)<e.counts[t]).length;ae(J,e),K(`repo-checks: accepted ${n} finding(s) and ${r} count(s) under ${pc} (${mc}).`),process.exit(0)}if(W.has(`--baseline-adopt`)){G.length&&(q(`repo-checks: --baseline-adopt reads the whole repository; run it without folder arguments.`),process.exit(2)),X===null&&(q(`repo-checks: no ${y}; run webority-repo-checks --baseline-init first.`),process.exit(2)),hc?.length||(q(`repo-checks: --baseline-adopt needs a comma-separated list of rule ids.`),process.exit(2));let e;try{e=se(X,Y,hc)}catch(e){throw e instanceof x&&(q(`repo-checks: ${e.message}`),process.exit(2)),e}ae(J,e);let t=new Set(X.findings);for(let n of hc){let r=e.findings.filter(e=>!t.has(e)&&S(e)[1].split(`:`)[0]===n).length,i=Object.keys(e.counts).filter(e=>!(e in X.counts)&&e.split(`:`)[0]===n).length;K(`repo-checks: adopted ${r} finding(s) and ${i} count(s) for ${n} in ${y}.`)}process.exit(0)}var jc=new Set(G.map(e=>m(J,h(process.cwd(),e)).split(`\\`).join(`/`)||`.`)),Mc=G.length?{pkgs:jc,dirs:[...jc]}:null,Z=le(ce(X??{version:2,findings:[],counts:{}},Mc),Y),Nc={"raw-measure":Pe,"palette-read":Le,"raw-colour":Fe,"root-font-size":Ie,"raw-motion":Re,"dark-read":ze,"missing-canvas-key":Be,"repeated-canvas-key":Ve},Pc=e=>Nc[e.slice(0,e.indexOf(`:`))],Q=[...Z.fresh.map(e=>Ac.get(e)),...Dc],Fc=Z.known.map(e=>Ac.get(e)),Ic=e=>[`${e.current} found, ${e.baseline} recorded.`,Pc(e.id)].filter(Boolean).join(` `),Lc=e=>Xi(e.id.split(`:`)[0]),$=Z.over.filter(Lc).map(e=>({pkg:`.`,id:e.id,message:Ic(e),lines:kc.filter(t=>t.id===e.id).map(({line:e,text:t,hint:n})=>({line:e,text:t,hint:n}))})),Rc=Z.over.filter(e=>!Lc(e)).map(e=>({pkg:`.`,id:e.id,message:Ic(e)})),zc=Z.within.map(e=>({pkg:`.`,id:e.id,message:`${e.current} found, ${e.baseline} recorded.`})),Bc=[...Z.stale.map(S),...Z.fallen.map(e=>[`.`,e.id])],Vc=[...Tc,...Rc];if(W.has(`--json`)||(()=>{if(Vc.length!==0){q(`repo-checks: ${Vc.length} warning(s), not enforced yet. Name a rule in REPO_CHECKS_ENFORCE (comma list, or all) to fail on it:`);for(let e of Vc)q(` - ${e.pkg} ${e.id}: ${e.message}`)}})(),W.has(`--json`)){let e={root:J,new:[...Q,...$],known:[...Fc,...zc],stale:Bc,warnings:Vc.map(e=>({pkg:e.pkg,id:e.id,message:e.message}))};K(JSON.stringify(e,null,2)),process.exitCode=Q.length||$.length?1:0}else if(Q.length||$.length){if(Q.length){q(`repo-checks: ${Q.length} new finding(s)`);let e=null;for(let t of Q)t.pkg!==e&&(e=t.pkg,q(` ${e}`)),q(` - ${t.id}: ${t.message}`)}if($.length){q(`repo-checks: ${$.length} file(s) above their recorded count`);for(let e of $){q(` ${e.id}: ${e.message}`);for(let t of e.lines)q(` ${t.line}: ${t.text}`),t.hint!==null&&q(` ${t.hint}`)}}process.exitCode=1}else{if(K(`repo-checks: no new findings.`),Fc.length||zc.length){let e=Z.within.reduce((e,t)=>e+t.current,0);K(`repo-checks: ${Fc.length} known finding(s) and ${e} counted code finding(s) in ${zc.length} file(s) recorded in ${y}.`)}if(Z.stale.length){K(`repo-checks: ${Z.stale.length} baseline entr${Z.stale.length===1?`y is`:`ies are`} fixed; drop them with webority-repo-checks --baseline-shrink:`);for(let e of Z.stale.map(S))K(` ${e[0]} ${e[1]}`)}if(Z.fallen.length){K(`repo-checks: ${Z.fallen.length} count(s) fell; record them with webority-repo-checks --baseline-shrink:`);for(let e of Z.fallen)K(` ${e.id} ${e.baseline} -> ${e.current}`)}}export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/repo-checks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.141.0",
|
|
4
4
|
"description": "Repository checks for Webority React web portals, React Native apps and Razor sites: banned and required dependencies, pnpm only, exact pins, the shared Biome preset, and token use in style, markup and component code. Run before a push; existing findings and per-file counts sit in a baseline that only shrinks.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"node": ">=24.15 <27"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@webority/theme": "0.
|
|
25
|
+
"@webority/theme": "0.141.0",
|
|
26
26
|
"vite": "^8.0.12"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|