/*! @author Huan Luo (https://shaiwang.life) */ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("path"),t=require("micromatch"),n=require("is-glob");const a='The naming pattern object "{{ value }}" does not appear to be an Object type, please double-check it and try again',o='There is an invalid pattern "{{ value }}", please double-check it and try again',i=e=>`https://github.com/dukeluo/eslint-plugin-check-file/blob/main/docs/rules/${e}.md`,r=/^<(\d+)>$/,s=/^[A-Za-z]:\\/,l=e=>"[object Object]"===Object.prototype.toString.call(e),d=e=>null==e,c=e=>""===e||(e=>null!=e&&e.length>=0&&"[object Array]"===Object.prototype.toString.call(e))(e)&&0===e.length||l(e)&&0===Object.keys(e).length,p=(...e)=>t=>e.reduce(((e,t)=>t(e)),t),m=p(c,(e=>!e)),f=t=>e.posix.basename(t),g=t=>e.posix.join(e.posix.dirname(t),e.posix.sep),u=(e,t=!1)=>e.substring(0,t?e.indexOf("."):e.lastIndexOf(".")),h=t=>t.split(e.posix.sep).filter(m),y=t=>{const n=h(t);let a=[];for(let t=0;t{const i=e.posix.join(t,n,e.posix.sep);return o>=1&&a.push(i),i}),"");return a.unshift(e.posix.join(n[0],e.posix.sep)),a},b=t=>t.split(e.sep).join(e.posix.sep),v=e=>e.replace(s,""),P=t=>{const n=(a=t.physicalFilename||t.getPhysicalFilename(),o=t.cwd||t.getCwd(),a.replace(e.join(o,e.sep),""));var a,o;return p(v,b)(n)},x="+([a-z])*([a-z0-9])*([A-Z]*([a-z0-9]))",j="+([a-z])*([a-z0-9])*(-+([a-z0-9]))";var M=Object.freeze({__proto__:null,CAMEL_CASE:x,FLAT_CASE:"+([a-z0-9])",KEBAB_CASE:j,PASCAL_CASE:"*([A-Z]*([a-z0-9]))",SCREAMING_SNAKE_CASE:"+([A-Z])*([A-Z0-9])*(_+([A-Z0-9]))",SNAKE_CASE:"+([a-z])*([a-z0-9])*(_+([a-z0-9]))"});const A=([e,n],a)=>{const o=t.capture(e,a);if(d(o))return[e,n];const i=[...n.matchAll(new RegExp(r,"g"))];if(c(i))return[e,n];const s=i.reduce(((t,a)=>{const i=+a[1];if(d(o[i]))throw{type:"invalidPrefinedMatch",payload:{namingPattern:n,filenamePattern:e}};return t.replace(a[0],o[i])}),n);return[e,s]},_=(e,n,a,o)=>t.isMatch(e,n)?a&&o&&t.isMatch(a,M[o]||o)?void 0:{path:e,pattern:o}:void 0,O=`@(${j}|${`\\[${x}\\]`}|${`\\[...${x}\\]`}|${`\\[\\[...${x}\\]\\]`}|${`\\(${j}\\)`}|${`\\@${j}`}|${`\\_${j}`})`;var E=Object.freeze({__proto__:null,NEXT_JS_APP_ROUTER_CASE:O});const k=(e,t,n)=>{if(!l(e))return{type:"invalidObject",payload:e};for(const[a,o]of Object.entries(e)){if(!t(a))return{type:"invalidPattern",payload:a};if(!n(o))return{type:"invalidPattern",payload:o}}},T=e=>Object.keys(M).includes(e),$=n,z=e=>$(e)||T(e)||r.test(e),S=e=>$(e)||T(e)||(e=>Object.keys(E).includes(e))(e);var I={meta:{type:"layout",docs:{description:"The filename should be blocklisted",category:"Layout & Formatting",recommended:!1,url:i("filename-blocklist")},fixable:null,schema:[{additionalProperties:{type:"string"}},{type:"object",properties:{errorMessage:{type:"string"}}}],messages:{invalidObject:a,invalidPattern:o,noMatch:'The filename "{{ filename }}" matches the blocklisted "{{ blockListPattern }}" pattern, use a pattern like "{{ suggestion }}" instead'}},create:e=>({Program:t=>{const n=e.options[0],a=e.options[1]?.errorMessage??"",o=k(n,$,c(a)?$:()=>!0);if(o)return void e.report({node:t,messageId:o.type,data:{value:o.payload}});const i=P(e),r=f(i);for(const[o,s]of Object.entries(n)){if(_(i,o)||_(r,o))return void(m(a)?e.report({node:t,message:a,data:{target:r,pattern:o}}):e.report({node:t,messageId:"noMatch",data:{filename:r,blockListPattern:o,suggestion:s}}))}}})},C={meta:{type:"layout",docs:{description:"The filename should follow the filename naming convention",category:"Layout & Formatting",recommended:!1,url:i("filename-naming-convention")},fixable:null,schema:[{additionalProperties:{type:"string"}},{type:"object",properties:{ignoreMiddleExtensions:{type:"boolean"},errorMessage:{type:"string"}}}],messages:{invalidObject:a,invalidPattern:o,invalidPrefinedMatch:'The prefined match "{{ namingPattern }}" is not found in the pattern "{{ filenamePattern }}", please double-check it and try again',noMatch:'The filename "{{ filename }}" does not match the "{{ originalNamingPattern }}" pattern'}},create:e=>({Program:t=>{const n=e.options[0],a=k(n,$,z);if(a)return void e.report({node:t,messageId:a.type,data:{value:a.payload}});const o=P(e),i=f(o),r=e.options[1]?.ignoreMiddleExtensions??!1,s=e.options[1]?.errorMessage??"";for(const[l,d]of Object.entries(n))try{const[e,t]=A([l,d],o);if(_(o,e,u(i,r),t))throw{type:"noMatch",payload:{filename:i,originalNamingPattern:d}}}catch(a){m(s)&&"noMatch"===a.type?e.report({node:t,message:s,data:{target:a.payload.filename,pattern:a.payload.originalNamingPattern}}):e.report({node:t,messageId:a.type,data:a.payload})}}})},w={meta:{type:"layout",docs:{description:"The folder should match the naming pattern specified by its file",category:"Layout & Formatting",recommended:!1,url:i("folder-match-with-fex")},fixable:null,schema:[{additionalProperties:{type:"string"}}],messages:{invalidObject:a,invalidPattern:o,noMatch:'The folder of the file "{{ filenameWithPath }}" does not match the "{{ folderPattern }}" pattern'}},create:e=>({Program:t=>{const n=e.options[0],a=k(n,$,$);if(a)return void e.report({node:t,messageId:a.type,data:{value:a.payload}});const o=P(e),i=f(o),r=g(o);for(const[a,s]of Object.entries(n)){if(_(i,a,r,s))return void e.report({node:t,messageId:"noMatch",data:{filenameWithPath:o,folderPattern:s}})}}})},L={meta:{type:"layout",docs:{description:"The folder should follow the folder naming convention",category:"Layout & Formatting",recommended:!1,url:i("folder-naming-convention")},fixable:null,schema:[{additionalProperties:{type:"string"}}],messages:{invalidObject:a,invalidPattern:o,noMatch:'The folder "{{ folder }}" does not match the "{{ namingPattern }}" pattern'}},create:e=>({Program:n=>{const a=e.options[0],o=k(a,$,S);if(o)return void e.report({node:n,messageId:o.type,data:{value:o.payload}});const i=P(e),r=g(i);for(const[o,i]of Object.entries(a))if(t.isMatch(r,o,{contains:!0}))for(const a of y(r)){const r=t.capture(o,a,{dot:!0});if(d(r))continue;const s=r.filter(m).reduce(((e,t)=>e.concat(h(t))),[]);for(const a of s)if(!t.isMatch(a,M[i]||E[i]||i))return void e.report({node:n,messageId:"noMatch",data:{folder:a,namingPattern:i}})}}})};const F={"filename-blocklist":I,"filename-naming-convention":C,"folder-match-with-fex":w,"folder-naming-convention":L,"no-index":{meta:{type:"layout",docs:{description:'A file cannot be named "index"',category:"Layout & Formatting",recommended:!1,url:i("no-index")},fixable:null,schema:[{type:"object",properties:{ignoreMiddleExtensions:{type:"boolean"}}}],messages:{noIndex:'The filename "index" is not allowed'}},create:e=>({Program:t=>{const{ignoreMiddleExtensions:n}=e.options[0]||{},a=P(e),o=f(a);"index"!==u(o,n)||e.report({node:t,messageId:"noIndex"})}})}},N={meta:{name:"eslint-plugin-check-file",version:"2.8.0"},rules:F};exports.default=N,exports.rules=F;