eslint-cdk-plugin 3.4.2 → 3.4.4
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/bin/migration.mjs +15 -4
- package/dist/index.cjs +299 -138
- package/dist/index.mjs +293 -132
- package/package.json +13 -10
- package/src/rules/no-unused-props/index.ts +152 -0
- package/src/rules/no-unused-props/props-usage-analyzer.ts +297 -0
- package/src/{utils/propsUsageTracker.ts → rules/no-unused-props/props-usage-tracker.ts} +96 -104
- package/src/utils/get-child-nodes.ts +25 -0
- package/src/utils/getPropertyNames.ts +1 -5
- package/src/utils/is-resource-with-readonly-interface.ts +5 -5
- package/src/utils/typecheck/ts-node.ts +2 -37
- package/src/utils/typecheck/ts-type.ts +2 -8
- package/src/constants/tsInternalFlags.ts +0 -18
- package/src/rules/no-unused-props.ts +0 -176
package/bin/migration.mjs
CHANGED
|
@@ -79,11 +79,22 @@ ${O.cyan(z)} `)}
|
|
|
79
79
|
${O.cyan(B)}
|
|
80
80
|
`}}}).prompt()},`${O.gray(z)}`,pn=Symbol.for(`cancel`)}));const G=Object.create(null),K=e=>globalThis.process?.env||import.meta.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?G:globalThis),q=new Proxy(G,{get(e,t){return K()[t]??G[t]},has(e,t){return t in K()||t in G},set(e,t,n){let r=K(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=K(!0);return delete n[t],!0},ownKeys(){let e=K(!0);return Object.keys(e)}}),hn=typeof process<`u`&&process.env&&process.env.NODE_ENV||``,gn=[[`APPVEYOR`],[`AWS_AMPLIFY`,`AWS_APP_ID`,{ci:!0}],[`AZURE_PIPELINES`,`SYSTEM_TEAMFOUNDATIONCOLLECTIONURI`],[`AZURE_STATIC`,`INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN`],[`APPCIRCLE`,`AC_APPCIRCLE`],[`BAMBOO`,`bamboo_planKey`],[`BITBUCKET`,`BITBUCKET_COMMIT`],[`BITRISE`,`BITRISE_IO`],[`BUDDY`,`BUDDY_WORKSPACE_ID`],[`BUILDKITE`],[`CIRCLE`,`CIRCLECI`],[`CIRRUS`,`CIRRUS_CI`],[`CLOUDFLARE_PAGES`,`CF_PAGES`,{ci:!0}],[`CODEBUILD`,`CODEBUILD_BUILD_ARN`],[`CODEFRESH`,`CF_BUILD_ID`],[`DRONE`],[`DRONE`,`DRONE_BUILD_EVENT`],[`DSARI`],[`GITHUB_ACTIONS`],[`GITLAB`,`GITLAB_CI`],[`GITLAB`,`CI_MERGE_REQUEST_ID`],[`GOCD`,`GO_PIPELINE_LABEL`],[`LAYERCI`],[`HUDSON`,`HUDSON_URL`],[`JENKINS`,`JENKINS_URL`],[`MAGNUM`],[`NETLIFY`],[`NETLIFY`,`NETLIFY_LOCAL`,{ci:!1}],[`NEVERCODE`],[`RENDER`],[`SAIL`,`SAILCI`],[`SEMAPHORE`],[`SCREWDRIVER`],[`SHIPPABLE`],[`SOLANO`,`TDDIUM`],[`STRIDER`],[`TEAMCITY`,`TEAMCITY_VERSION`],[`TRAVIS`],[`VERCEL`,`NOW_BUILDER`],[`VERCEL`,`VERCEL`,{ci:!1}],[`VERCEL`,`VERCEL_ENV`,{ci:!1}],[`APPCENTER`,`APPCENTER_BUILD_ID`],[`CODESANDBOX`,`CODESANDBOX_SSE`,{ci:!1}],[`CODESANDBOX`,`CODESANDBOX_HOST`,{ci:!1}],[`STACKBLITZ`],[`STORMKIT`],[`CLEAVR`],[`ZEABUR`],[`CODESPHERE`,`CODESPHERE_APP_ID`,{ci:!0}],[`RAILWAY`,`RAILWAY_PROJECT_ID`],[`RAILWAY`,`RAILWAY_SERVICE_ID`],[`DENO-DEPLOY`,`DENO_DEPLOYMENT_ID`],[`FIREBASE_APP_HOSTING`,`FIREBASE_APP_HOSTING`,{ci:!0}]];function _n(){if(globalThis.process?.env)for(let e of gn){let t=e[1]||e[0];if(globalThis.process?.env[t])return{name:e[0].toLowerCase(),...e[2]}}return globalThis.process?.env?.SHELL===`/bin/jsh`&&globalThis.process?.versions?.webcontainer?{name:`stackblitz`,ci:!1}:{name:``,ci:!1}}const vn=_n();vn.name;function J(e){return e?e!==`false`:!1}const yn=globalThis.process?.platform||``,bn=J(q.CI)||vn.ci!==!1,xn=J(globalThis.process?.stdout&&globalThis.process?.stdout.isTTY),Sn=J(q.DEBUG),Cn=hn===`test`||J(q.TEST);q.MINIMAL;const wn=/^win/i.test(yn);!J(q.NO_COLOR)&&(J(q.FORCE_COLOR)||(xn||wn)&&q.TERM);const Tn=(globalThis.process?.versions?.node||``).replace(/^v/,``)||null;Number(Tn?.split(`.`)[0]);const En=globalThis.process||Object.create(null),Dn={versions:{}};new Proxy(En,{get(e,t){if(t===`env`)return q;if(t in e)return e[t];if(t in Dn)return Dn[t]}});const On=globalThis.process?.release?.name===`node`,kn=!!globalThis.Bun||!!globalThis.process?.versions?.bun,An=!!globalThis.Deno,jn=!!globalThis.fastly,Mn=!!globalThis.Netlify,Nn=!!globalThis.EdgeRuntime,Pn=globalThis.navigator?.userAgent===`Cloudflare-Workers`,Fn=[[Mn,`netlify`],[Nn,`edge-light`],[Pn,`workerd`],[jn,`fastly`],[An,`deno`],[kn,`bun`],[On,`node`]];function In(){let e=Fn.find(e=>e[0]);if(e)return{name:e[1]}}In()?.name;function Ln({onlyFirst:e=!1}={}){let t=[`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`,`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))`].join(`|`);return new RegExp(t,e?void 0:`g`)}const Rn=Ln();function zn(e){if(typeof e!=`string`)throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);return e.replace(Rn,``)}function Bn(e){return e===161||e===164||e===167||e===168||e===170||e===173||e===174||e>=176&&e<=180||e>=182&&e<=186||e>=188&&e<=191||e===198||e===208||e===215||e===216||e>=222&&e<=225||e===230||e>=232&&e<=234||e===236||e===237||e===240||e===242||e===243||e>=247&&e<=250||e===252||e===254||e===257||e===273||e===275||e===283||e===294||e===295||e===299||e>=305&&e<=307||e===312||e>=319&&e<=322||e===324||e>=328&&e<=331||e===333||e===338||e===339||e===358||e===359||e===363||e===462||e===464||e===466||e===468||e===470||e===472||e===474||e===476||e===593||e===609||e===708||e===711||e>=713&&e<=715||e===717||e===720||e>=728&&e<=731||e===733||e===735||e>=768&&e<=879||e>=913&&e<=929||e>=931&&e<=937||e>=945&&e<=961||e>=963&&e<=969||e===1025||e>=1040&&e<=1103||e===1105||e===8208||e>=8211&&e<=8214||e===8216||e===8217||e===8220||e===8221||e>=8224&&e<=8226||e>=8228&&e<=8231||e===8240||e===8242||e===8243||e===8245||e===8251||e===8254||e===8308||e===8319||e>=8321&&e<=8324||e===8364||e===8451||e===8453||e===8457||e===8467||e===8470||e===8481||e===8482||e===8486||e===8491||e===8531||e===8532||e>=8539&&e<=8542||e>=8544&&e<=8555||e>=8560&&e<=8569||e===8585||e>=8592&&e<=8601||e===8632||e===8633||e===8658||e===8660||e===8679||e===8704||e===8706||e===8707||e===8711||e===8712||e===8715||e===8719||e===8721||e===8725||e===8730||e>=8733&&e<=8736||e===8739||e===8741||e>=8743&&e<=8748||e===8750||e>=8756&&e<=8759||e===8764||e===8765||e===8776||e===8780||e===8786||e===8800||e===8801||e>=8804&&e<=8807||e===8810||e===8811||e===8814||e===8815||e===8834||e===8835||e===8838||e===8839||e===8853||e===8857||e===8869||e===8895||e===8978||e>=9312&&e<=9449||e>=9451&&e<=9547||e>=9552&&e<=9587||e>=9600&&e<=9615||e>=9618&&e<=9621||e===9632||e===9633||e>=9635&&e<=9641||e===9650||e===9651||e===9654||e===9655||e===9660||e===9661||e===9664||e===9665||e>=9670&&e<=9672||e===9675||e>=9678&&e<=9681||e>=9698&&e<=9701||e===9711||e===9733||e===9734||e===9737||e===9742||e===9743||e===9756||e===9758||e===9792||e===9794||e===9824||e===9825||e>=9827&&e<=9829||e>=9831&&e<=9834||e===9836||e===9837||e===9839||e===9886||e===9887||e===9919||e>=9926&&e<=9933||e>=9935&&e<=9939||e>=9941&&e<=9953||e===9955||e===9960||e===9961||e>=9963&&e<=9969||e===9972||e>=9974&&e<=9977||e===9979||e===9980||e===9982||e===9983||e===10045||e>=10102&&e<=10111||e>=11094&&e<=11097||e>=12872&&e<=12879||e>=57344&&e<=63743||e>=65024&&e<=65039||e===65533||e>=127232&&e<=127242||e>=127248&&e<=127277||e>=127280&&e<=127337||e>=127344&&e<=127373||e===127375||e===127376||e>=127387&&e<=127404||e>=917760&&e<=917999||e>=983040&&e<=1048573||e>=1048576&&e<=1114109}function Vn(e){return e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510}function Hn(e){return e>=4352&&e<=4447||e===8986||e===8987||e===9001||e===9002||e>=9193&&e<=9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e>=9776&&e<=9783||e>=9800&&e<=9811||e===9855||e>=9866&&e<=9871||e===9875||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093||e>=11904&&e<=11929||e>=11931&&e<=12019||e>=12032&&e<=12245||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12353&&e<=12438||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12773||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=42124||e>=42128&&e<=42182||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=94176&&e<=94180||e===94192||e===94193||e>=94208&&e<=100343||e>=100352&&e<=101589||e>=101631&&e<=101640||e>=110576&&e<=110579||e>=110581&&e<=110587||e===110589||e===110590||e>=110592&&e<=110882||e===110898||e>=110928&&e<=110930||e===110933||e>=110948&&e<=110951||e>=110960&&e<=111355||e>=119552&&e<=119638||e>=119648&&e<=119670||e===126980||e===127183||e===127374||e>=127377&&e<=127386||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e===127568||e===127569||e>=127584&&e<=127589||e>=127744&&e<=127776||e>=127789&&e<=127797||e>=127799&&e<=127868||e>=127870&&e<=127891||e>=127904&&e<=127946||e>=127951&&e<=127955||e>=127968&&e<=127984||e===127988||e>=127992&&e<=128062||e===128064||e>=128066&&e<=128252||e>=128255&&e<=128317||e>=128331&&e<=128334||e>=128336&&e<=128359||e===128378||e===128405||e===128406||e===128420||e>=128507&&e<=128591||e>=128640&&e<=128709||e===128716||e>=128720&&e<=128722||e>=128725&&e<=128727||e>=128732&&e<=128735||e===128747||e===128748||e>=128756&&e<=128764||e>=128992&&e<=129003||e===129008||e>=129292&&e<=129338||e>=129340&&e<=129349||e>=129351&&e<=129535||e>=129648&&e<=129660||e>=129664&&e<=129673||e>=129679&&e<=129734||e>=129742&&e<=129756||e>=129759&&e<=129769||e>=129776&&e<=129784||e>=131072&&e<=196605||e>=196608&&e<=262141}function Un(e){if(!Number.isSafeInteger(e))throw TypeError(`Expected a code point, got \`${typeof e}\`.`)}function Wn(e,{ambiguousAsWide:t=!1}={}){return Un(e),Vn(e)||Hn(e)||t&&Bn(e)?2:1}const Gn=()=>/[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g,Kn=globalThis.Intl?.Segmenter?new Intl.Segmenter:{segment:e=>e.split(``)},qn=/^\p{Default_Ignorable_Code_Point}$/u;function Jn(e,t={}){if(typeof e!=`string`||e.length===0)return 0;let{ambiguousIsNarrow:n=!0,countAnsiEscapeCodes:r=!1}=t;if(r||(e=zn(e)),e.length===0)return 0;let i=0,a={ambiguousAsWide:!n};for(let{segment:t}of Kn.segment(e)){let e=t.codePointAt(0);if(!(e<=31||e>=127&&e<=159)&&!(e>=8203&&e<=8207||e===65279)&&!(e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071)&&!(e>=55296&&e<=57343)&&!(e>=65024&&e<=65039)&&!qn.test(t)){if(Gn().test(t)){i+=2;continue}i+=Wn(e,a)}}return i}function Yn(){let{env:e}=n,{TERM:t,TERM_PROGRAM:r}=e;return n.platform===`win32`?!!e.WT_SESSION||!!e.TERMINUS_SUBLIME||e.ConEmuTask===`{cmd::Cmder}`||r===`Terminus-Sublime`||r===`vscode`||t===`xterm-256color`||t===`alacritty`||t===`rxvt-unicode`||t===`rxvt-unicode-256color`||e.TERMINAL_EMULATOR===`JetBrains-JediTerm`:t!==`linux`}const Xn={info:`cyan`,fail:`red`,success:`green`,ready:`green`,start:`magenta`},Zn={0:`red`,1:`yellow`},Qn=Yn(),Y=(e,t)=>Qn?e:t,$n={error:Y(`✖`,`×`),fatal:Y(`✖`,`×`),ready:Y(`✔`,`√`),warn:Y(`⚠`,`‼`),info:Y(`ℹ`,`i`),success:Y(`✔`,`√`),debug:Y(`⚙`,`D`),trace:Y(`→`,`→`),fail:Y(`✖`,`×`),start:Y(`◐`,`o`),log:``};function er(e){return typeof Intl!=`object`||!Intl.Segmenter?C(e).length:Jn(e)}var tr=class extends Le{formatStack(e,t,n){let r=` `.repeat((n?.errorLevel||0)+1);return`
|
|
81
81
|
${r}`+Pe(e,t).map(e=>` `+e.replace(/^at +/,e=>S.gray(e)).replace(/\((.+)\)/,(e,t)=>`(${S.cyan(t)})`)).join(`
|
|
82
|
-
${r}`)}formatType(e,t,n){let r=Xn[e.type]||Zn[e.level]||`gray`;if(t)return
|
|
83
|
-
`);if(e.type===`box`)return rt(
|
|
82
|
+
${r}`)}formatType(e,t,n){let r=Xn[e.type]||Zn[e.level]||`gray`;if(t)return ir(r)(S.black(` ${e.type.toUpperCase()} `));let i=typeof $n[e.type]==`string`?$n[e.type]:e.icon||e.type;return i?rr(r)(i):``}formatLogObj(e,t){let[n,...r]=this.formatArgs(e.args,t).split(`
|
|
83
|
+
`);if(e.type===`box`)return rt(nr(n+(r.length>0?`
|
|
84
84
|
`+r.join(`
|
|
85
|
-
`):``)),{title:e.title?
|
|
85
|
+
`):``)),{title:e.title?nr(e.title):void 0,style:e.style});let i=this.formatDate(e.date,t),a=i&&S.gray(i),o=e.badge??e.level<2,s=this.formatType(e,o,t),c=e.tag?S.gray(e.tag):``,l,u=this.filterAndJoin([s,nr(n)]),d=this.filterAndJoin(t.columns?[c,a]:[c]),f=(t.columns||0)-er(u)-er(d)-2;if(l=f>0&&(t.columns||0)>=80?u+` `.repeat(f)+d:(d?`${S.gray(`[${d}]`)} `:``)+u,l+=nr(r.length>0?`
|
|
86
86
|
`+r.join(`
|
|
87
87
|
`):``),e.type===`trace`){let t=Error(`Trace: `+e.message);l+=this.formatStack(t.stack||``,t.message)}return o?`
|
|
88
88
|
`+l+`
|
|
89
|
-
`:l}};function
|
|
89
|
+
`:l}};function nr(e){return e.replace(/`([^`]+)`/gm,(e,t)=>S.cyan(t)).replace(/\s+_([^_]+)_\s+/gm,(e,t)=>` ${S.underline(t)} `)}function rr(e=`white`){return S[e]||S.white}function ir(e=`bgWhite`){return S[`bg${e[0].toUpperCase()}${e.slice(1)}`]||S.bgWhite}function ar(e={}){let t=or();return process.env.CONSOLA_LEVEL&&(t=Number.parseInt(process.env.CONSOLA_LEVEL)??t),Ne({level:t,defaults:{level:t},stdout:process.stdout,stderr:process.stderr,prompt:(...e)=>Promise.resolve().then(()=>(mn(),it)).then(t=>t.prompt(...e)),reporters:e.reporters||[e.fancy??!(bn||Cn)?new tr:new Le],...e})}function or(){return Sn?v.debug:Cn?v.warn:v.info}const X=ar(),Z=e=>e instanceof Error?e.message:typeof e==`string`?e:e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`?e.message:`An unknown error occurred`,Q={SUCCESS:`success`,ERROR:`error`},sr=()=>{try{return l(`npx eslint --fix`,{stdio:`inherit`}),{type:Q.SUCCESS,message:`ESLint fix completed successfully`}}catch(e){return e?typeof e!=`object`||!(`status`in e)?{type:Q.ERROR,message:`Failed to run ESLint fix command
|
|
90
|
+
${Z(e)}
|
|
91
|
+
|
|
92
|
+
Please manually run 'npx eslint --fix' and check the configuration`}:e.status===1?{type:Q.SUCCESS,message:`ESLint fix found issues, some may require manual fixing`}:{type:Q.ERROR,message:`Failed to run ESLint fix command
|
|
93
|
+
${Z(e)}
|
|
94
|
+
|
|
95
|
+
Please manually run 'npx eslint --fix' and check the configuration`}:{type:Q.ERROR,message:`An unknown error occurred while running ESLint fix command
|
|
96
|
+
|
|
97
|
+
Please manually run 'npx eslint --fix' and check the configuration`}}},cr=[`eslint.config.mjs`,`eslint.config.cjs`,`eslint.config.js`,`eslint.config.ts`,`eslint.config.mts`,`eslint.config.cts`],lr=e=>{let t=ur(e);if(!t.length)return{type:Q.ERROR,message:`ESLint config files not found`};for(let e of t){let t=dr(u.readFileSync(e,`utf-8`));t.modified&&u.writeFileSync(e,t.content,`utf-8`)}return{type:Q.SUCCESS}},ur=e=>cr.reduce((t,n)=>{let r=d.join(e,n);return u.existsSync(r)?[...t,r]:t},[]),dr=e=>{let t=e,n=!1;t.includes(`"eslint-cdk-plugin"`)&&(t=t.replace(/"eslint-cdk-plugin"/g,`"eslint-plugin-awscdk"`),n=!0),t.includes(`'eslint-cdk-plugin'`)&&(t=t.replace(/'eslint-cdk-plugin'/g,`'eslint-plugin-awscdk'`),n=!0);let r=/(\bplugins\s*:\s*\{[\s\S]*?\b)(cdk)(\s*:\s*[a-zA-Z_$])/g;return t.match(r)&&(t=t.replace(r,`$1awscdk$3`),n=!0),t.includes(`"cdk/`)&&(t=t.replace(/"cdk\//g,`"awscdk/`),n=!0),t.includes(`'cdk/`)&&(t=t.replace(/'cdk\//g,`'awscdk/`),n=!0),{content:t,modified:n}},$={NPM:`npm`,YARN:`yarn`,PNPM:`pnpm`},fr=Object.values($),pr=async e=>{if(!e.packageManager){let e=await X.prompt(`Which package manager are you using?`,{type:`select`,options:[{label:$.NPM,value:$.NPM},{label:$.YARN,value:$.YARN},{label:$.PNPM,value:$.PNPM}]});return{type:Q.SUCCESS,value:e}}return fr.includes(e.packageManager)?{type:Q.SUCCESS,value:e.packageManager}:{type:Q.ERROR,message:`Invalid package manager: ${e.packageManager}. Must be one of: ${fr.join(`, `)}`}},mr=e=>{let t=(()=>{switch(e){case $.NPM:return`npm install -D eslint-plugin-awscdk`;case $.YARN:return`yarn add -D eslint-plugin-awscdk`;case $.PNPM:return`pnpm install -D eslint-plugin-awscdk`}})();try{return l(t,{stdio:`inherit`}),{type:Q.SUCCESS}}catch(e){return{type:Q.ERROR,message:`Failed to install eslint-plugin-awscdk
|
|
98
|
+
${Z(e)}`}}},hr=(e,t)=>{let n=_r(t);if(n.type===Q.ERROR)return n;let r=vr(n.value);if(r.type===Q.ERROR)return r;for(let t of r.value){let n=gr(t===`devDependencies`,e);if(n.type===Q.ERROR)return n}return{type:Q.SUCCESS}},gr=(e,t)=>{let n=(()=>{let n=e?` -D`:``;switch(t){case $.NPM:return`npm uninstall${n} eslint-cdk-plugin`;case $.YARN:return`yarn remove${n} eslint-cdk-plugin`;case $.PNPM:return`pnpm remove${n} eslint-cdk-plugin`}})();try{return l(n,{stdio:`inherit`}),{type:Q.SUCCESS}}catch(e){return{type:Q.ERROR,message:`Failed to uninstall eslint-cdk-plugin
|
|
99
|
+
${Z(e)}`}}},_r=e=>{let t=d.join(e,`package.json`);if(!u.existsSync(t))return{type:Q.ERROR,message:`package.json not found`};try{let e=u.readFileSync(t,`utf-8`);return yr(JSON.parse(e))?{type:Q.SUCCESS,value:JSON.parse(e)}:{type:Q.ERROR,message:`Invalid package.json format`}}catch(e){return{type:Q.ERROR,message:`Failed to read package.json
|
|
100
|
+
${Z(e)}`}}},vr=e=>{let t=e.dependencies?.[`eslint-cdk-plugin`],n=e.devDependencies?.[`eslint-cdk-plugin`];return t&&n?{type:Q.SUCCESS,value:[`devDependencies`,`dependencies`]}:n?{type:Q.SUCCESS,value:[`devDependencies`]}:t?{type:Q.SUCCESS,value:[`dependencies`]}:{type:Q.ERROR,message:`eslint-cdk-plugin is not installed`}},yr=e=>typeof e==`object`&&!!e&&(`dependencies`in e&&typeof e.dependencies==`object`||`devDependencies`in e&&typeof e.devDependencies==`object`),br=new ye;br.name(`migration`).description(`Migrate from eslint-cdk-plugin to eslint-plugin-awscdk`).version(`1.0.0`).option(`-p, --package-manager <manager>`,`Specify package manager (${fr.join(`, `)})`).parse(process.argv);const xr=br.opts();await(async()=>{X.box(`Starting migration from ${$e(`black`,`eslint-cdk-plugin`)} to ${$e(`green`,`eslint-plugin-awscdk`)}`);let e=process.cwd(),t=await pr(xr);t.type===Q.ERROR&&(X.error(t.message),process.exit(1));let n=mr(t.value);n.type===Q.ERROR&&(X.error(n.message),process.exit(1));let r=lr(e);r.type===Q.ERROR&&(X.error(r.message),process.exit(1));let i=hr(t.value,e);i.type===Q.ERROR&&(X.error(i.message),process.exit(1));let a=sr();a.type===Q.ERROR&&(X.error(a.message),process.exit(1)),a.message&&X.warn(a.message),X.success(`All migration steps completed successfully!`)})();export{};
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tsParser = require('@typescript-eslint/parser');
|
|
6
6
|
var utils = require('@typescript-eslint/utils');
|
|
7
|
+
var typescript = require('typescript');
|
|
7
8
|
var path = require('path');
|
|
8
9
|
|
|
9
10
|
function _interopNamespaceDefault(e) {
|
|
@@ -26,7 +27,7 @@ function _interopNamespaceDefault(e) {
|
|
|
26
27
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
27
28
|
|
|
28
29
|
var name = "eslint-cdk-plugin";
|
|
29
|
-
var version = "3.4.
|
|
30
|
+
var version = "3.4.4";
|
|
30
31
|
|
|
31
32
|
const createRule = utils.ESLintUtils.RuleCreator(
|
|
32
33
|
(name) => `https://eslint-cdk-plugin.dev/rules/${name}`
|
|
@@ -143,21 +144,11 @@ const validateConstructorProperty = (constructor, context, parserServices) => {
|
|
|
143
144
|
}
|
|
144
145
|
};
|
|
145
146
|
|
|
146
|
-
const SYMBOL_FLAGS = {
|
|
147
|
-
CLASS: 32};
|
|
148
|
-
const SYNTAX_KIND = {
|
|
149
|
-
CLASS_DECLARATION: 263,
|
|
150
|
-
CONSTRUCTOR: 176,
|
|
151
|
-
IMPLEMENTS_KEYWORD: 119,
|
|
152
|
-
IDENTIFIER: 80,
|
|
153
|
-
PROPERTY_ACCESS_EXPRESSION: 211
|
|
154
|
-
};
|
|
155
|
-
|
|
156
147
|
const getSymbol = (type) => {
|
|
157
148
|
return type.getSymbol?.() ?? type.symbol;
|
|
158
149
|
};
|
|
159
150
|
const isClassType = (type) => {
|
|
160
|
-
return getSymbol(type)?.flags ===
|
|
151
|
+
return getSymbol(type)?.flags === typescript.SymbolFlags.Class;
|
|
161
152
|
};
|
|
162
153
|
const isArrayType = (type) => {
|
|
163
154
|
const symbol = getSymbol(type);
|
|
@@ -193,20 +184,8 @@ const getGenericTypeArgument = (type) => {
|
|
|
193
184
|
return void 0;
|
|
194
185
|
};
|
|
195
186
|
|
|
196
|
-
const isClassDeclaration = (node) => {
|
|
197
|
-
return node.kind === SYNTAX_KIND.CLASS_DECLARATION;
|
|
198
|
-
};
|
|
199
|
-
const isIdentifier = (node) => {
|
|
200
|
-
return node.kind === SYNTAX_KIND.IDENTIFIER;
|
|
201
|
-
};
|
|
202
|
-
const isPropertyAccessExpression = (node) => {
|
|
203
|
-
return node.kind === SYNTAX_KIND.PROPERTY_ACCESS_EXPRESSION;
|
|
204
|
-
};
|
|
205
187
|
const checkHeritageClauseIsImplements = (node) => {
|
|
206
|
-
return node.token ===
|
|
207
|
-
};
|
|
208
|
-
const isConstructorDeclaration = (node) => {
|
|
209
|
-
return node.kind === SYNTAX_KIND.CONSTRUCTOR;
|
|
188
|
+
return node.token === typescript.SyntaxKind.ImplementsKeyword;
|
|
210
189
|
};
|
|
211
190
|
|
|
212
191
|
const isResourceWithReadonlyInterface = (type) => {
|
|
@@ -254,7 +233,7 @@ const getDirectImplementedInterfaceNames = (type) => {
|
|
|
254
233
|
const declarations = symbol.getDeclarations ? symbol.getDeclarations() : symbol.declarations;
|
|
255
234
|
if (!declarations?.length) return [];
|
|
256
235
|
return declarations.reduce((acc, decl) => {
|
|
257
|
-
if (!isClassDeclaration(decl)) return acc;
|
|
236
|
+
if (!typescript.isClassDeclaration(decl)) return acc;
|
|
258
237
|
const heritageClauses = decl.heritageClauses;
|
|
259
238
|
if (!heritageClauses) return acc;
|
|
260
239
|
return heritageClauses.reduce((hcAcc, hc) => {
|
|
@@ -262,11 +241,11 @@ const getDirectImplementedInterfaceNames = (type) => {
|
|
|
262
241
|
return hc.types.reduce((typeAcc, type2) => {
|
|
263
242
|
const expression = type2.expression;
|
|
264
243
|
if (!expression) return typeAcc;
|
|
265
|
-
if (isIdentifier(expression)) return [...typeAcc, expression.text];
|
|
266
|
-
if (!isPropertyAccessExpression(expression)) return typeAcc;
|
|
244
|
+
if (typescript.isIdentifier(expression)) return [...typeAcc, expression.text];
|
|
245
|
+
if (!typescript.isPropertyAccessExpression(expression)) return typeAcc;
|
|
267
246
|
const namespace = expression.expression;
|
|
268
247
|
const interfaceName = expression.name;
|
|
269
|
-
if (isIdentifier(namespace) && isIdentifier(interfaceName)) {
|
|
248
|
+
if (typescript.isIdentifier(namespace) && typescript.isIdentifier(interfaceName)) {
|
|
270
249
|
return [...typeAcc, `${namespace.text}.${interfaceName.text}`];
|
|
271
250
|
}
|
|
272
251
|
return typeAcc;
|
|
@@ -466,9 +445,9 @@ const getConstructorPropertyNames = (type) => {
|
|
|
466
445
|
const declarations = type.symbol?.declarations;
|
|
467
446
|
if (!declarations?.length) return [];
|
|
468
447
|
const classDeclaration = declarations[0];
|
|
469
|
-
if (!isClassDeclaration(classDeclaration)) return [];
|
|
448
|
+
if (!typescript.isClassDeclaration(classDeclaration)) return [];
|
|
470
449
|
const constructor = classDeclaration.members.find(
|
|
471
|
-
(member) => isConstructorDeclaration(member)
|
|
450
|
+
(member) => typescript.isConstructorDeclaration(member)
|
|
472
451
|
);
|
|
473
452
|
if (!constructor?.parameters.length) return [];
|
|
474
453
|
return constructor.parameters.map((param) => param.name.getText());
|
|
@@ -971,76 +950,272 @@ const validateConstructId$2 = ({
|
|
|
971
950
|
}
|
|
972
951
|
};
|
|
973
952
|
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
if (
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
953
|
+
const getChildNodes = (node) => {
|
|
954
|
+
return Object.entries(node).reduce((acc, [key, value]) => {
|
|
955
|
+
if (["parent", "range", "loc"].includes(key)) return acc;
|
|
956
|
+
if (isESTreeNode(value)) return [...acc, value];
|
|
957
|
+
if (Array.isArray(value)) return [...acc, ...value.filter(isESTreeNode)];
|
|
958
|
+
return acc;
|
|
959
|
+
}, []);
|
|
960
|
+
};
|
|
961
|
+
const isESTreeNode = (value) => {
|
|
962
|
+
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
class PropsUsageAnalyzer {
|
|
966
|
+
propsUsageTracker;
|
|
967
|
+
visitedNodes;
|
|
968
|
+
propsAliases;
|
|
969
|
+
constructor(propsUsageTracker) {
|
|
970
|
+
this.propsUsageTracker = propsUsageTracker;
|
|
971
|
+
this.visitedNodes = /* @__PURE__ */ new Set();
|
|
972
|
+
this.propsAliases = /* @__PURE__ */ new Set();
|
|
973
|
+
}
|
|
974
|
+
analyze(constructor, propsParam) {
|
|
975
|
+
this.initialize();
|
|
976
|
+
const constructorBody = constructor.value.body;
|
|
977
|
+
const classNode = constructor.parent;
|
|
978
|
+
const propsParamName = propsParam.name;
|
|
979
|
+
if (!constructorBody) return;
|
|
980
|
+
this.visitNodes(constructorBody, propsParamName);
|
|
981
|
+
this.analyzeClassBody(classNode, constructor, propsParamName);
|
|
982
|
+
this.analyzePrivateMethodsCalledFromConstructor(
|
|
983
|
+
constructorBody,
|
|
984
|
+
classNode,
|
|
985
|
+
propsParamName
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
initialize() {
|
|
989
|
+
this.visitedNodes.clear();
|
|
990
|
+
this.propsAliases.clear();
|
|
991
|
+
}
|
|
992
|
+
analyzeClassBody(classBody, constructor, propsParamName) {
|
|
993
|
+
if (!constructor.value.body) return;
|
|
994
|
+
const instanceVarName = this.findPropsInstanceVariable(
|
|
995
|
+
constructor.value.body,
|
|
996
|
+
propsParamName
|
|
997
|
+
);
|
|
998
|
+
if (!instanceVarName) return;
|
|
999
|
+
for (const member of classBody.body) {
|
|
1000
|
+
if (member.type === utils.AST_NODE_TYPES.MethodDefinition && member.value.body) {
|
|
1001
|
+
this.visitNodes(member.value.body, instanceVarName);
|
|
1002
|
+
}
|
|
982
1003
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1004
|
+
}
|
|
1005
|
+
analyzePrivateMethodsCalledFromConstructor(constructorBody, classBody, propsParamName) {
|
|
1006
|
+
const methodCallsWithProps = this.findMethodCallsWithProps(
|
|
1007
|
+
constructorBody,
|
|
1008
|
+
propsParamName
|
|
1009
|
+
);
|
|
1010
|
+
for (const { methodName, propsArgIndices } of methodCallsWithProps) {
|
|
1011
|
+
const methodDef = this.findMethodDefinition(classBody, methodName);
|
|
1012
|
+
if (!methodDef?.value.body) continue;
|
|
1013
|
+
for (const argIndex of propsArgIndices) {
|
|
1014
|
+
const param = methodDef.value.params[argIndex];
|
|
1015
|
+
if (param && param.type === utils.AST_NODE_TYPES.Identifier) {
|
|
1016
|
+
this.visitNodes(methodDef.value.body, param.name);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
visitNodes(node, propsParamName) {
|
|
1022
|
+
if (this.visitedNodes.has(node)) return;
|
|
1023
|
+
this.visitedNodes.add(node);
|
|
1024
|
+
switch (node.type) {
|
|
1025
|
+
case utils.AST_NODE_TYPES.MemberExpression:
|
|
1026
|
+
this.propsUsageTracker.markAsUsedForMemberExpression(
|
|
1027
|
+
node,
|
|
1028
|
+
propsParamName
|
|
1029
|
+
);
|
|
1030
|
+
if (node.object.type === utils.AST_NODE_TYPES.Identifier && this.propsAliases.has(node.object.name) && node.property.type === utils.AST_NODE_TYPES.Identifier) {
|
|
1031
|
+
this.propsUsageTracker.markAsUsed(node.property.name);
|
|
1032
|
+
}
|
|
1033
|
+
break;
|
|
1034
|
+
case utils.AST_NODE_TYPES.VariableDeclarator:
|
|
1035
|
+
this.propsUsageTracker.markAsUsedForVariableDeclarator(
|
|
1036
|
+
node,
|
|
1037
|
+
propsParamName
|
|
1038
|
+
);
|
|
1039
|
+
break;
|
|
1040
|
+
case utils.AST_NODE_TYPES.AssignmentExpression:
|
|
1041
|
+
this.propsUsageTracker.markAsUsedForAssignmentExpression(
|
|
1042
|
+
node,
|
|
1043
|
+
propsParamName
|
|
1044
|
+
);
|
|
1045
|
+
break;
|
|
1046
|
+
case utils.AST_NODE_TYPES.Identifier:
|
|
1047
|
+
if (node.name === propsParamName) this.handlePropsIdentifier(node);
|
|
1048
|
+
break;
|
|
1049
|
+
}
|
|
1050
|
+
const children = getChildNodes(node);
|
|
1051
|
+
for (const child of children) {
|
|
1052
|
+
this.visitNodes(child, propsParamName);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Handles cases where props is used as a whole identifier
|
|
1057
|
+
*/
|
|
1058
|
+
handlePropsIdentifier(node) {
|
|
1059
|
+
const parent = node.parent;
|
|
1060
|
+
if (!parent) return;
|
|
1061
|
+
switch (parent.type) {
|
|
1062
|
+
case utils.AST_NODE_TYPES.AssignmentExpression:
|
|
1063
|
+
case utils.AST_NODE_TYPES.MemberExpression: {
|
|
1064
|
+
break;
|
|
1065
|
+
}
|
|
1066
|
+
case utils.AST_NODE_TYPES.VariableDeclarator: {
|
|
1067
|
+
if (parent.init === node && parent.id.type === utils.AST_NODE_TYPES.Identifier) {
|
|
1068
|
+
this.propsAliases.add(parent.id.name);
|
|
1069
|
+
}
|
|
1070
|
+
break;
|
|
1071
|
+
}
|
|
1072
|
+
case utils.AST_NODE_TYPES.CallExpression: {
|
|
1073
|
+
if (!parent.arguments.includes(node)) break;
|
|
1074
|
+
if (parent.callee.type === utils.AST_NODE_TYPES.MemberExpression && parent.callee.object.type === utils.AST_NODE_TYPES.ThisExpression) {
|
|
1075
|
+
break;
|
|
1076
|
+
}
|
|
1077
|
+
this.propsUsageTracker.markAllAsUsed();
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
case utils.AST_NODE_TYPES.ReturnStatement: {
|
|
1081
|
+
if (parent.argument === node) {
|
|
1082
|
+
this.propsUsageTracker.markAllAsUsed();
|
|
1083
|
+
}
|
|
1084
|
+
break;
|
|
1085
|
+
}
|
|
1086
|
+
case utils.AST_NODE_TYPES.ArrayExpression: {
|
|
1087
|
+
if (parent.elements.includes(node)) {
|
|
1088
|
+
this.propsUsageTracker.markAllAsUsed();
|
|
1089
|
+
}
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
case utils.AST_NODE_TYPES.Property: {
|
|
1093
|
+
if (parent.value === node) {
|
|
1094
|
+
this.propsUsageTracker.markAllAsUsed();
|
|
1095
|
+
}
|
|
1096
|
+
break;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
findPropsInstanceVariable(body, propsParamName) {
|
|
1101
|
+
for (const statement of body.body) {
|
|
1102
|
+
if (statement.type === utils.AST_NODE_TYPES.ExpressionStatement && statement.expression.type === utils.AST_NODE_TYPES.AssignmentExpression && statement.expression.left.type === utils.AST_NODE_TYPES.MemberExpression && statement.expression.left.object.type === utils.AST_NODE_TYPES.ThisExpression && statement.expression.left.property.type === utils.AST_NODE_TYPES.Identifier && statement.expression.right.type === utils.AST_NODE_TYPES.Identifier && statement.expression.right.name === propsParamName) {
|
|
1103
|
+
return statement.expression.left.property.name;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
return null;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Finds method definition in class body
|
|
1110
|
+
*/
|
|
1111
|
+
findMethodDefinition(classBody, methodName) {
|
|
1112
|
+
for (const member of classBody.body) {
|
|
1113
|
+
if (member.type === utils.AST_NODE_TYPES.MethodDefinition && member.key.type === utils.AST_NODE_TYPES.Identifier && member.key.name === methodName) {
|
|
1114
|
+
return member;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return null;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Finds method calls in constructor body that receive props as argument
|
|
1121
|
+
*/
|
|
1122
|
+
findMethodCallsWithProps(body, propsParamName) {
|
|
1123
|
+
const result = [];
|
|
1124
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1125
|
+
const visitNode = (node) => {
|
|
1126
|
+
if (visited.has(node)) return;
|
|
1127
|
+
visited.add(node);
|
|
1128
|
+
if (node.type === utils.AST_NODE_TYPES.CallExpression && node.callee.type === utils.AST_NODE_TYPES.MemberExpression && node.callee.object.type === utils.AST_NODE_TYPES.ThisExpression && node.callee.property.type === utils.AST_NODE_TYPES.Identifier) {
|
|
1129
|
+
const methodName = node.callee.property.name;
|
|
1130
|
+
const propsArgIndices = node.arguments.reduce(
|
|
1131
|
+
(acc, arg, index) => arg.type === utils.AST_NODE_TYPES.Identifier && arg.name === propsParamName ? (
|
|
1132
|
+
// NOTE: props is passed directly (e.g., this.method(props))
|
|
1133
|
+
[...acc, index]
|
|
1134
|
+
) : acc,
|
|
1135
|
+
[]
|
|
1136
|
+
);
|
|
1137
|
+
if (propsArgIndices.length) {
|
|
1138
|
+
result.push({ methodName, propsArgIndices });
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
const children = getChildNodes(node);
|
|
1142
|
+
for (const child of children) {
|
|
1143
|
+
visitNode(child);
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
visitNode(body);
|
|
1147
|
+
return result;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
class PropsUsageTracker {
|
|
1152
|
+
propUsageMap;
|
|
1153
|
+
constructor(propType) {
|
|
1154
|
+
this.propUsageMap = new Map(
|
|
1155
|
+
this.getPropsPropertyNames(propType).map((name) => [name, false])
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
getUnusedProperties() {
|
|
1159
|
+
return Array.from(this.propUsageMap.entries()).reduce(
|
|
1001
1160
|
(acc, [name, used]) => !used ? [...acc, name] : acc,
|
|
1002
1161
|
[]
|
|
1003
1162
|
);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1163
|
+
}
|
|
1164
|
+
markAsUsed(propertyName) {
|
|
1165
|
+
if (this.propUsageMap.has(propertyName)) {
|
|
1166
|
+
this.propUsageMap.set(propertyName, true);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
markAllAsUsed() {
|
|
1170
|
+
for (const key of this.propUsageMap.keys()) {
|
|
1171
|
+
this.propUsageMap.set(key, true);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
markAsUsedForMemberExpression(node, propsParamName) {
|
|
1006
1175
|
if (node.object.type === utils.AST_NODE_TYPES.Identifier && node.object.name === propsParamName && node.property.type === utils.AST_NODE_TYPES.Identifier) {
|
|
1007
|
-
markAsUsed(node.property.name);
|
|
1176
|
+
this.markAsUsed(node.property.name);
|
|
1008
1177
|
return;
|
|
1009
1178
|
}
|
|
1010
|
-
if (node.object.type === utils.AST_NODE_TYPES.MemberExpression && node.object.object.type === utils.AST_NODE_TYPES.ThisExpression && node.object.property.type === utils.AST_NODE_TYPES.Identifier && node.object.property.name ===
|
|
1011
|
-
markAsUsed(node.property.name);
|
|
1179
|
+
if (node.object.type === utils.AST_NODE_TYPES.MemberExpression && node.object.object.type === utils.AST_NODE_TYPES.ThisExpression && node.object.property.type === utils.AST_NODE_TYPES.Identifier && node.object.property.name === propsParamName && node.property.type === utils.AST_NODE_TYPES.Identifier) {
|
|
1180
|
+
this.markAsUsed(node.property.name);
|
|
1012
1181
|
return;
|
|
1013
1182
|
}
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1183
|
+
}
|
|
1184
|
+
markAsUsedForVariableDeclarator(node, propsParamName) {
|
|
1016
1185
|
if (node.id.type !== utils.AST_NODE_TYPES.ObjectPattern || node.init?.type !== utils.AST_NODE_TYPES.Identifier || node.init.name !== propsParamName) {
|
|
1017
1186
|
return;
|
|
1018
1187
|
}
|
|
1019
1188
|
const propertyNames = getPropertyNames(node.id.properties);
|
|
1020
1189
|
for (const name of propertyNames) {
|
|
1021
|
-
markAsUsed(name);
|
|
1190
|
+
this.markAsUsed(name);
|
|
1022
1191
|
}
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1192
|
+
}
|
|
1193
|
+
markAsUsedForAssignmentExpression(node, propsParamName) {
|
|
1025
1194
|
if (node.right.type !== utils.AST_NODE_TYPES.MemberExpression || node.right.object.type !== utils.AST_NODE_TYPES.Identifier || node.right.object.name !== propsParamName || node.right.property.type !== utils.AST_NODE_TYPES.Identifier) {
|
|
1026
1195
|
return;
|
|
1027
1196
|
}
|
|
1028
|
-
markAsUsed(node.right.property.name);
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1197
|
+
this.markAsUsed(node.right.property.name);
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Gets the property names from the props type
|
|
1201
|
+
*/
|
|
1202
|
+
getPropsPropertyNames(propsType) {
|
|
1203
|
+
const isInternalProperty = (propertyName) => propertyName.startsWith("_") || propertyName === "constructor" || propertyName === "prototype";
|
|
1204
|
+
const typeProperties = propsType.getProperties();
|
|
1205
|
+
if (typeProperties.length) {
|
|
1206
|
+
return typeProperties.reduce(
|
|
1207
|
+
(acc, prop) => !isInternalProperty(prop.name) ? [...acc, prop.name] : acc,
|
|
1208
|
+
[]
|
|
1209
|
+
);
|
|
1033
1210
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
};
|
|
1043
|
-
};
|
|
1211
|
+
const symbol = propsType.getSymbol();
|
|
1212
|
+
if (!symbol?.members) return [];
|
|
1213
|
+
return Array.from(symbol.members.keys()).reduce((acc, key) => {
|
|
1214
|
+
const name = String(key);
|
|
1215
|
+
return !isInternalProperty(name) ? [...acc, name] : acc;
|
|
1216
|
+
}, []);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1044
1219
|
|
|
1045
1220
|
const noUnusedProps = createRule({
|
|
1046
1221
|
name: "no-unused-props",
|
|
@@ -1059,64 +1234,61 @@ const noUnusedProps = createRule({
|
|
|
1059
1234
|
const parserServices = utils.ESLintUtils.getParserServices(context);
|
|
1060
1235
|
return {
|
|
1061
1236
|
ClassDeclaration(node) {
|
|
1237
|
+
if (node.abstract) return;
|
|
1062
1238
|
const type = parserServices.getTypeAtLocation(node);
|
|
1063
1239
|
if (!isConstructType(type)) return;
|
|
1064
1240
|
const constructor = getConstructor(node);
|
|
1065
1241
|
if (!constructor) return;
|
|
1066
|
-
|
|
1242
|
+
const propsParam = getPropsParam(constructor, parserServices);
|
|
1243
|
+
if (!propsParam) return;
|
|
1244
|
+
const { node: propsNode, type: propsType } = propsParam;
|
|
1245
|
+
if (isPropsUsedInSuperCall(constructor, propsNode.name)) return;
|
|
1246
|
+
const tracker = new PropsUsageTracker(propsType);
|
|
1247
|
+
const analyzer = new PropsUsageAnalyzer(tracker);
|
|
1248
|
+
analyzer.analyze(constructor, propsNode);
|
|
1249
|
+
reportUnusedProperties(tracker, propsNode, context);
|
|
1067
1250
|
}
|
|
1068
1251
|
};
|
|
1069
1252
|
}
|
|
1070
1253
|
});
|
|
1071
|
-
const
|
|
1254
|
+
const getPropsParam = (constructor, parserServices) => {
|
|
1072
1255
|
const params = constructor.value.params;
|
|
1073
|
-
if (params.length < 3) return;
|
|
1256
|
+
if (params.length < 3) return null;
|
|
1074
1257
|
const propsParam = params[2];
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
analyzeConstructorBody(constructor.value.body, propsParam.name, tracker);
|
|
1081
|
-
reportUnusedProperties(tracker, propsParam, context);
|
|
1082
|
-
return;
|
|
1083
|
-
}
|
|
1084
|
-
case utils.AST_NODE_TYPES.ObjectPattern: {
|
|
1085
|
-
const typeAnnotation = propsParam.typeAnnotation?.typeAnnotation;
|
|
1086
|
-
if (!typeAnnotation) return;
|
|
1087
|
-
const propsType = parserServices.getTypeAtLocation(typeAnnotation);
|
|
1088
|
-
const tracker = propsUsageTrackerFactory(propsType);
|
|
1089
|
-
if (!tracker) return;
|
|
1090
|
-
tracker.markAsUsedForObjectPattern(propsParam);
|
|
1091
|
-
reportUnusedProperties(tracker, propsParam, context);
|
|
1092
|
-
return;
|
|
1093
|
-
}
|
|
1094
|
-
default:
|
|
1095
|
-
return;
|
|
1096
|
-
}
|
|
1258
|
+
if (propsParam.type !== utils.AST_NODE_TYPES.Identifier) return null;
|
|
1259
|
+
return {
|
|
1260
|
+
node: propsParam,
|
|
1261
|
+
type: parserServices.getTypeAtLocation(propsParam)
|
|
1262
|
+
};
|
|
1097
1263
|
};
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
tracker.markAsUsedForMemberExpression(node, propsParamName);
|
|
1106
|
-
break;
|
|
1107
|
-
case utils.AST_NODE_TYPES.VariableDeclarator:
|
|
1108
|
-
tracker.markAsUsedForVariableDeclarator(node, propsParamName);
|
|
1109
|
-
break;
|
|
1110
|
-
case utils.AST_NODE_TYPES.AssignmentExpression:
|
|
1111
|
-
tracker.markAsUsedForAssignmentExpression(node, propsParamName);
|
|
1112
|
-
break;
|
|
1264
|
+
const isPropsUsedInSuperCall = (constructor, propsPropertyName) => {
|
|
1265
|
+
if (constructor.kind !== "constructor") return false;
|
|
1266
|
+
const body = constructor.value.body;
|
|
1267
|
+
if (!body) return false;
|
|
1268
|
+
for (const expr of body.body) {
|
|
1269
|
+
if (expr.type !== utils.AST_NODE_TYPES.ExpressionStatement || expr.expression.type !== utils.AST_NODE_TYPES.CallExpression || expr.expression.callee.type !== utils.AST_NODE_TYPES.Super) {
|
|
1270
|
+
continue;
|
|
1113
1271
|
}
|
|
1114
|
-
const
|
|
1115
|
-
|
|
1116
|
-
|
|
1272
|
+
const visitNode = (node, propsName) => {
|
|
1273
|
+
const nodeValue = node.type === utils.AST_NODE_TYPES.Property ? node.value : node;
|
|
1274
|
+
switch (nodeValue.type) {
|
|
1275
|
+
case utils.AST_NODE_TYPES.Identifier: {
|
|
1276
|
+
return nodeValue.name === propsName;
|
|
1277
|
+
}
|
|
1278
|
+
case utils.AST_NODE_TYPES.ObjectExpression: {
|
|
1279
|
+
for (const prop of nodeValue.properties) {
|
|
1280
|
+
if (visitNode(prop, propsName)) return true;
|
|
1281
|
+
}
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return false;
|
|
1286
|
+
};
|
|
1287
|
+
for (const arg of expr.expression.arguments) {
|
|
1288
|
+
if (visitNode(arg, propsPropertyName)) return true;
|
|
1117
1289
|
}
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1290
|
+
}
|
|
1291
|
+
return false;
|
|
1120
1292
|
};
|
|
1121
1293
|
const reportUnusedProperties = (tracker, propsParam, context) => {
|
|
1122
1294
|
for (const propName of tracker.getUnusedProperties()) {
|
|
@@ -1129,17 +1301,6 @@ const reportUnusedProperties = (tracker, propsParam, context) => {
|
|
|
1129
1301
|
});
|
|
1130
1302
|
}
|
|
1131
1303
|
};
|
|
1132
|
-
const getChildNodes = (node) => {
|
|
1133
|
-
return Object.entries(node).reduce((acc, [key, value]) => {
|
|
1134
|
-
if (["parent", "range", "loc"].includes(key)) return acc;
|
|
1135
|
-
if (isESTreeNode(value)) return [...acc, value];
|
|
1136
|
-
if (Array.isArray(value)) return [...acc, ...value.filter(isESTreeNode)];
|
|
1137
|
-
return acc;
|
|
1138
|
-
}, []);
|
|
1139
|
-
};
|
|
1140
|
-
const isESTreeNode = (value) => {
|
|
1141
|
-
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
|
1142
|
-
};
|
|
1143
1304
|
|
|
1144
1305
|
const noVariableConstructId = createRule({
|
|
1145
1306
|
name: "no-variable-construct-id",
|