eslint-plugin-code-style 2.0.7 → 2.0.8
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/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -222,7 +222,7 @@ ${c})${x}`),message:"Multi-line JSX in object property must be wrapped in parent
|
|
|
222
222
|
|
|
223
223
|
`+Y+q+" "+W+";")),D};e.report({data:{name:P,type:$?"hook":"component"},fix:j,message:'Constant "{{name}}" should be declared inside the {{type}} as derived state, not at module level',node:R.id})}}},w=E=>{if(c(E)){b(E,!1),v(E,!1);return}a(E)&&(b(E,!0),v(E,!0))};return{ArrowFunctionExpression:w,FunctionDeclaration:w,FunctionExpression:w}},meta:{docs:{description:"Enforce consistent ordering of code blocks in React components and custom hooks"},fixable:"code",schema:[],type:"suggestion"}};var jt={create(e){let t=e.sourceCode||e.getSourceCode();return{VariableDeclaration:S=>{let d=t.getFirstToken(S);d&&S.declarations.forEach(s=>{let{id:g,init:i}=s;if(S.declarations[0]===s){if(g.type==="Identifier"&&d.loc.end.line!==g.loc.start.line){e.report({fix:o=>o.replaceTextRange([d.range[1],g.range[0]]," "),message:"Variable name should be on the same line as declaration keyword",node:g});return}if(g.type==="ObjectPattern"||g.type==="ArrayPattern"){let o=t.getFirstToken(g);if(d.loc.end.line!==o.loc.start.line){e.report({fix:n=>n.replaceTextRange([d.range[1],o.range[0]]," "),message:"Destructuring pattern should be on the same line as declaration keyword",node:o});return}}}if(!i)return;let l=t.getTokenBefore(i,o=>o.value==="=");if(l){if(g.loc.end.line!==l.loc.start.line){e.report({fix:o=>o.replaceTextRange([g.range[1],l.range[0]]," "),message:"Assignment operator should be on the same line as variable",node:l});return}i.loc.start.line>l.loc.end.line&&e.report({fix:o=>o.replaceTextRange([l.range[1],i.range[0]]," "),message:"Value should be on the same line as the assignment operator",node:i})}})}}},meta:{docs:{description:"Enforce assignment value on same line as equals sign"},fixable:"whitespace",schema:[],type:"layout"}},Ot={create(e){let t=e.sourceCode||e.getSourceCode(),I=(S,d,s)=>{let g=t.getTokenBefore(s),i=t.getTokenAfter(s);if(!g||g.value!=="["||!i||i.value!=="]")return;let r=t.getLastToken(d);if(r){let n=t.text.slice(r.range[1],g.range[0]);/\s/.test(n)&&e.report({fix:y=>y.replaceTextRange([r.range[1],g.range[0]],""),message:"No space before opening bracket in member expression",node:g})}let l=t.text.slice(g.range[1],s.range[0]);(l.includes(" ")||l.includes(`
|
|
224
224
|
`))&&e.report({fix:n=>n.replaceTextRange([g.range[1],s.range[0]],""),message:"No space after opening bracket in member expression",node:g});let o=t.text.slice(s.range[1],i.range[0]);(o.includes(" ")||o.includes(`
|
|
225
|
-
`))&&e.report({fix:n=>n.replaceTextRange([s.range[1],i.range[0]],""),message:"No space before closing bracket in member expression",node:i})};return{MemberExpression(S){S.computed&&I(S,S.object,S.property)},TSIndexedAccessType(S){I(S,S.objectType,S.indexType)}}},meta:{docs:{description:"Enforce no spaces inside brackets for member expressions"},fixable:"code",schema:[],type:"layout"}};var Mt={create(e){let t=e.options[0]||{},I=["accept","acceptCharset","accessKey","action","align","allow","allowFullScreen","alt","as","async","autoCapitalize","autoComplete","autoCorrect","autoFocus","autoPlay","capture","cellPadding","cellSpacing","charSet","className","clipPath","clipRule","colorInterpolation","colorInterpolationFilters","classNames","colSpan","contentEditable","controls","controlsList","coords","crossOrigin","d","data","data-*","dateTime","decoding","default","defer","dir","disabled","download","draggable","encType","enterKeyHint","fill","fillOpacity","fillRule","filter","filterUnits","floodColor","floodOpacity","for","form","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","headers","height","hidden","high","href","hrefLang","htmlFor","httpEquiv","gradientTransform","gradientUnits","icon","id","in","in2","imagesizes","imagesrcset","inputMode","integrity","is","itemID","itemProp","itemRef","itemScope","itemType","key","keyParams","keyType","kind","lang","list","loading","loop","low","marginHeight","marginWidth","markerEnd","markerMid","markerStart","markerUnits","mask","max","mode","maxLength","media","mediaGroup","method","min","minLength","multiple","muted","name","noModule","noValidate","nonce","open","optimum","pattern","patternContentUnits","patternTransform","patternUnits","ping","preserveAspectRatio","playsInline","poster","preload","profile","radioGroup","readOnly","referrerPolicy","rel","repeatCount","repeatDur","required","result","reversed","role","rowSpan","rows","sandbox","scope","scoped","scrolling","seamless","selected","shape","sizes","slot","span","spellCheck","src","srcDoc","srcLang","srcSet","start","step","spreadMethod","stdDeviation","stopColor","stopOpacity","stroke","strokeDasharray","strokeDashoffset","strokeLinecap","strokeLinejoin","strokeMiterlimit","strokeOpacity","strokeWidth","style","summary","tabIndex","target","testId","textAnchor","textDecoration","transform","translate","vectorEffect","useMap","value","viewBox","width","wmode","wrap","x","x1","x2","xmlns","y","y1","y2","baseFrequency","numOctaves","seed","stitchTiles","operator","k1","k2","k3","k4","surfaceScale","diffuseConstant","specularConstant","specularExponent","kernelMatrix","order","targetX","targetY","edgeMode","kernelUnitLength","bias","divisor","preserveAlpha","radius","azimuth","elevation","limitingConeAngle","pointsAtX","pointsAtY","pointsAtZ","cx","cy","r","rx","ry","points","pathLength","offset","dx","dy","rotate","lengthAdjust","textLength"],S=t.ignoreAttributes||[...I,...t.extraIgnoreAttributes||[]],d=[/^\s*$/,/^.$/,/^-?\d+(\.\d+)?(px|em|rem|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|deg|rad|turn|s|ms|fr)?$/,/^-?\d+(\.\d+)?e[+-]?\d+$/i,/^#[0-9a-fA-F]{3,8}$/,/^(rgb|rgba|hsl|hsla)\(.+\)$/,/^url\(#?.+\)$/,/^(round|butt|square|miter|bevel|none|normal|evenodd|nonzero|sRGB|linearRGB|userSpaceOnUse|objectBoundingBox|pad|reflect|repeat|auto|inherit|currentColor|meet|slice|xMinYMin|xMidYMin|xMaxYMin|xMinYMid|xMidYMid|xMaxYMid|xMinYMax|xMidYMax|xMaxYMax|stitch|noStitch|duplicate|wrap|arithmetic|atop|in|out|over|xor|dilate|erode|matrix|saturate|hueRotate|luminanceToAlpha|discrete|linear|gamma|table|identity|SourceGraphic|SourceAlpha|BackgroundImage|BackgroundAlpha|FillPaint|StrokePaint)$/,/^[a-zA-Z]+\d*[_a-zA-Z0-9]*(_[a-zA-Z0-9]+)+$/,/^(white|black|red|green|blue|yellow|orange|purple|pink|brown|gray|grey|cyan|magenta|transparent)$/i,/^(auto|default|none|context-menu|help|pointer|progress|wait|cell|crosshair|vertical-text|alias|copy|move|no-drop|not-allowed|grab|grabbing|all-scroll|col-resize|row-resize|n-resize|e-resize|s-resize|w-resize|ne-resize|nw-resize|se-resize|sw-resize|ew-resize|ns-resize|nesw-resize|nwse-resize|zoom-in|zoom-out)$/,/^(block|inline|inline-block|flex|inline-flex|grid|inline-grid|flow-root|contents|table|table-row|table-cell|list-item|none|visible|hidden|collapse)$/,/^(static|relative|absolute|fixed|sticky)$/,/^(visible|hidden|scroll|auto|clip)$/,/^(https?:\/\/|\/\/|\/|\.\/|\.\.\/)/,/^data:/,/^mailto:/,/^tel:/,/^\.[a-zA-Z0-9]+$/,/^[a-z]+\/[a-z0-9.+-]+$/,/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/,/^\d{1,2}:\d{2}(:\d{2})?(\s?(AM|PM|am|pm))?$/,/^[a-z]+[A-Z][a-zA-Z0-9]*$/,/^[a-z][a-z0-9]*_[a-z0-9_]*$/,/^[A-Z][A-Z0-9]*_[A-Z0-9_]+$/,/^(true|false|null|undefined|NaN|Infinity)$/,/^application\//,/^[a-z][a-zA-Z0-9_]*=/,/^[a-z]+-[a-z]+(-[a-z]+)*$/,/^-?[a-z]+-\d+(\.\d+)?(\/\d+)?$/,/^-?[a-z]+-[a-z]+-\d+(\.\d+)?(\/\d+)?$/,/^[a-z]+:[a-z][-a-z0-9/]*$/,/^[a-z]+-[a-z]+(-[a-z]+)*\/\d+$/,/^-?[a-z]+(-[a-z]+)*-\[.+\]$/,/^-[a-z]+-[a-z]+-\d+\/\d+$/,/^[a-z]+-(full|auto|screen|none|inherit|initial|px|fit|min|max)$/,/^(sm|md|lg|xl|2xl|hover|focus|active|disabled|first|last|odd|even|group-hover|dark|motion-safe|motion-reduce):[a-z][-a-z0-9/[\]]*$/,/^[\d,._]+$/,/^\d+\.\d+\.\d+/,/^[,;:|•·\-–—/\\]+$/,/^&[a-z]+;$/,/^[.!?,;:'"()\[\]{}]+$/,/^(rotate|translate|translateX|translateY|translateZ|translate3d|scale|scaleX|scaleY|scaleZ|scale3d|skew|skewX|skewY|matrix|matrix3d|perspective)\(.+\)$/,/^(rotate|translate|translateX|translateY|scale|scaleX|scaleY|skew|skewX|skewY|matrix)\([^)]+\)(\s+(rotate|translate|translateX|translateY|scale|scaleX|scaleY|skew|skewX|skewY|matrix)\([^)]+\))+$/,/^(linear-gradient|radial-gradient|conic-gradient|repeating-linear-gradient|repeating-radial-gradient)\(.+\)$/,/^[a-zA-Z][\w-]*\s+[\d.]+m?s\s+[\w-]+(\s+[\w-]+)*$/,/^(\d+%|center|top|bottom|left|right)(\s+(\d+%|center|top|bottom|left|right))?$/,/^calc\(.+\)$/,/^var\(.+\)$/,/^clamp\(.+\)$/,/^(min|max)\(.+\)$/],s=(t.ignorePatterns||[]).map(f=>typeof f=="string"?new RegExp(f):f),g=[...d,...s],i=/^-?[a-z]+(-[a-z0-9]+)*(\/\d+)?$|^-?[a-z]+(-[a-z0-9]+)*-\[.+\]$|^[a-z]+:[a-z][-a-z0-9/[\]]*$/,r=new Set(["block","contents","flex","flow","grid","hidden","inline","table","absolute","fixed","relative","static","sticky","collapse","invisible","visible","antialiased","capitalize","italic","lowercase","ordinal","overline","subpixel","truncate","underline","uppercase","container","isolate","grow","shrink","border","rounded","group","peer","resize","snap","touch","select","pointer","transition","animate","filter","backdrop","transform","appearance","cursor","outline","ring","shadow","opacity","blur","invert","sepia","grayscale","hue","saturate","brightness","contrast"]),l=f=>{let h=f.trim().split(/\s+/).filter(Boolean);return h.length===0||!h.some(L=>L.includes("-")||L.includes(":")||L.includes("/")||L.includes("["))?!1:h.every(L=>L.includes("${")||r.has(L)?!0:/^-?[a-z]+(-[a-z0-9]+)+$/.test(L)||/^-?[a-z]+(-[a-z0-9]+)*\/\d+$/.test(L)||/^[a-z][-a-z0-9]*(\[[-\w=]+\])?:[a-z][-a-z0-9/[\]]*$/.test(L)||/^\[.+\]:[a-z][-a-z0-9/[\]]*$/.test(L)||/^-?[a-z]+(-[a-z]+)*-?\[.+\]$/.test(L))},o=new Set(["button","checkbox","color","date","datetime-local","email","file","hidden","image","month","number","password","radio","range","reset","search","submit","tel","text","time","url","week"]),n=f=>o.has(f.toLowerCase()),y=f=>{let h=f.parent;for(;h;){if(h.type==="Property"&&h.parent&&h.parent.type==="ObjectExpression"){let A=h.parent;if(A.parent&&A.parent.type==="JSXExpressionContainer"){let L=A.parent;if(L.parent&&L.parent.type==="JSXAttribute"&&(L.parent.name&&L.parent.name.name)==="style")return!0}}h=h.parent}return!1},p=[/gradient/i,/transform/i,/animation/i,/transition/i,/color/i,/background/i,/border/i,/shadow/i,/filter/i,/clip/i,/mask/i,/font/i,/^style/i,/Style$/i,/css/i],c=f=>!!(/^(linear-gradient|radial-gradient|conic-gradient|repeating-linear-gradient|repeating-radial-gradient|rotate|translate|translateX|translateY|translateZ|translate3d|scale|scaleX|scaleY|scaleZ|scale3d|skew|skewX|skewY|matrix|matrix3d|perspective|calc|var|clamp|min|max|cubic-bezier|steps|url)\(/i.test(f)||/^(#[0-9a-fA-F]{3,8}|rgb|rgba|hsl|hsla)\(/i.test(f)||/^\d+(\.\d+)?(px|em|rem|%|vh|vw|vmin|vmax|deg|rad|turn|s|ms|fr)\s*/.test(f)),a=f=>{let h=f.parent;for(;h;){if(h.type==="VariableDeclarator"&&h.id&&h.id.name){let A=h.id.name;if(p.some(L=>L.test(A)))return!0}if(h.type==="Property"&&h.key){let A=h.key.name||h.key.value&&String(h.key.value);if(A&&p.some(L=>L.test(A)))return!0}h=h.parent}return!1},u=f=>{let h=f.parent,A=0;for(;h;){if(A++,h.type==="ExportNamedDeclaration"&&A<=3){let L=h.declaration;if(L&&L.type==="VariableDeclaration"){let R=L.declarations[0];if(R&&R.id&&R.id.name){let P=R.id.name;return!(/^[A-Z][A-Z0-9_]*$/.test(P)||/^(constants?|strings?|messages?|labels?|texts?|data)$/i.test(P))}}}if(h.type==="FunctionDeclaration"||h.type==="FunctionExpression"||h.type==="ArrowFunctionExpression")return!1;h=h.parent}return!1},T=(f,h="")=>{let A=f.length>30?`${f.substring(0,30)}...`:f,L=h?` in ${h}`:"",R=!/\s/.test(f)&&f.length<=30,P=/^[a-z_]+$/.test(f),O=h.includes("attribute");return R&&P?O?`Hardcoded "${A}"${L} should be imported from @/enums (preferred) or @/data to prevent typos (e.g., import { InputTypeEnum } from "@/enums")`:`Hardcoded "${A}"${L} should be imported from @/enums (preferred) or @/data (e.g., import { StatusEnum } from "@/enums")`:`Hardcoded UI string "${A}"${L} should be imported from @/strings or @/constants (e.g., import { strings } from "@/strings")`},x=new Set(["cn","cva","clsx","twMerge","classnames","cx","tv","twJoin"]),k=f=>{let h=f.parent;for(;h;){if(h.type==="CallExpression"&&h.callee){let A=h.callee.name||h.callee.property&&h.callee.property.name;if(A&&x.has(A))return!0}h=h.parent}return!1},m=(f,h)=>h&&k(h)||l(f)?!0:g.some(A=>A.test(f)),b=()=>{let h=(e.filename||e.getFilename()).replace(/\\/g,"/").toLowerCase();return/\/(constants|strings|@constants|@strings|data|@data|enums|@enums)(\/|\.)/i.test(h)||/\/data\/(constants|strings)/i.test(h)},v=new Set,w=f=>{let h=f.source.value;if(typeof h!="string")return;/@?\/?(@?constants|@?strings|@?data|@?enums|data\/constants|data\/strings)/i.test(h)&&f.specifiers.forEach(L=>{L.local&&L.local.name&&v.add(L.local.name)})},E=f=>f.type==="Identifier"?v.has(f.name):f.type==="MemberExpression"&&f.object.type==="Identifier"?v.has(f.object.name):!1,$=f=>{let h=f.parent;for(;h;){if(h.type==="FunctionDeclaration"||h.type==="FunctionExpression"||h.type==="ArrowFunctionExpression"){let A=null;return h.id&&h.id.name?A=h.id.name:h.parent&&h.parent.type==="VariableDeclarator"&&h.parent.id&&h.parent.id.name&&(A=h.parent.id.name),A&&(/^[A-Z]/.test(A)||/^use[A-Z]/.test(A)||/Handler$|Helper$|Util$|Utils$/i.test(A)),!0}if(h.type==="JSXElement"||h.type==="JSXFragment")return!0;h=h.parent}return!1},C=f=>{let h=f.parent,A=0;for(;h;){if(A++,h.type==="VariableDeclarator"){let L=h.id&&h.id.name;if(L&&(/^[A-Z][A-Z0-9_]*$/.test(L)||/^(constants?|strings?|messages?|labels?|texts?|data)$/i.test(L)))return!0}if(h.type==="ExportNamedDeclaration"&&A<=3){let L=h.declaration;if(L&&L.type==="VariableDeclaration"){let R=L.declarations[0];if(R&&R.init){let P=R.init.type;if(P==="Literal"||P==="ObjectExpression"||P==="ArrayExpression")return!0}}}if(h.type==="FunctionDeclaration"||h.type==="FunctionExpression"||h.type==="ArrowFunctionExpression")return!1;h=h.parent}return!1};return b()?{}:{ImportDeclaration:w,JSXText(f){let h=f.value.trim();h&&(m(h,f)||/[a-zA-Z]/.test(h)&&e.report({message:T(h,"JSX"),node:f}))},JSXExpressionContainer(f){let{expression:h}=f;if(!E(h)){if(f.parent&&f.parent.type==="JSXAttribute"){let A=f.parent.name.name||f.parent.name.namespace&&`${f.parent.name.namespace.name}:${f.parent.name.name.name}`;if(S.includes(A)||A&&(A.startsWith("data-")||A.startsWith("aria-")))return}if(h.type==="Literal"&&typeof h.value=="string"){let A=h.value;if(m(A,h)||!/[a-zA-Z]/.test(A))return;e.report({message:T(A,"JSX expression"),node:h})}h.type==="TemplateLiteral"&&h.quasis.forEach(A=>{let L=A.value.cooked||A.value.raw;m(L,h)||/[a-zA-Z]{2,}/.test(L)&&(/^[/.]|https?:\/\//.test(L)||e.report({message:T(L,"template literal"),node:A}))})}},JSXAttribute(f){if(!f.value)return;let h=f.name.name||f.name.namespace&&`${f.name.namespace.name}:${f.name.name.name}`;if(!S.includes(h)&&!(h&&h.startsWith("data-"))&&!(h&&h.startsWith("aria-"))){if(f.value.type==="Literal"&&typeof f.value.value=="string"){let A=f.value.value;if(m(A,f.value)||!/[a-zA-Z]/.test(A))return;e.report({message:T(A,`attribute "${h}"`),node:f.value})}if(f.value.type==="JSXExpressionContainer"){let{expression:A}=f.value;if(E(A))return;if(A.type==="Literal"&&typeof A.value=="string"){let L=A.value;if(m(L,A)||!/[a-zA-Z]/.test(L))return;e.report({message:T(L,`attribute "${h}"`),node:A})}}}},Literal(f){if(typeof f.value!="string")return;let h=f.value;if(!y(f)){if(u(f)){if(!/[a-zA-Z]/.test(h))return;e.report({message:T(h,"exported constant"),node:f});return}m(h,f)||$(f)&&(C(f)||f.parent.type==="JSXAttribute"||f.parent.type==="JSXExpressionContainer"||f.parent.type==="ImportDeclaration"||f.parent.type==="ExportNamedDeclaration"||f.parent.type==="ExportAllDeclaration"||f.parent.type==="Property"&&f.parent.key===f||/[a-zA-Z]/.test(h)&&e.report({message:T(h),node:f}))}},TemplateLiteral(f){if(f.parent.type!=="JSXExpressionContainer"&&!y(f)){if(a(f)){let h=f.quasis.map(A=>A.value.cooked||A.value.raw).join("");if(c(h))return}$(f)&&(C(f)||f.quasis.forEach(h=>{let A=h.value.cooked||h.value.raw;m(A,f)||/[a-zA-Z]{3,}/.test(A)&&(/^[/.]|^https?:\/\/|^[?&]/.test(A)||f.expressions.length>f.quasis.length||e.report({message:T(A,"template literal"),node:h}))}))}}}},meta:{docs:{description:"Enforce importing strings from constants/strings modules instead of hardcoding them"},schema:[{additionalProperties:!1,properties:{extraIgnoreAttributes:{description:"Additional JSX attributes to ignore (extends defaults)",items:{type:"string"},type:"array"},ignoreAttributes:{description:"JSX attributes to ignore (replaces defaults)",items:{type:"string"},type:"array"},ignorePatterns:{description:"Regex patterns for strings to ignore",items:{type:"string"},type:"array"}},type:"object"}],type:"suggestion"}};var Nt={create(e){let t=e.sourceCode||e.getSourceCode(),I=new Map,S=l=>l.endsWith("Type")?l.slice(0,-4)+"Enum":null,d=l=>l.toUpperCase().replace(/-/g,"_"),s=l=>{if(!l)return null;let o=l.typeAnnotation;if(!o)return null;if(o.type==="TSTypeReference"&&o.typeName?.type==="Identifier"){let n=o.typeName.name;if(n.endsWith("Type"))return{enumName:S(n),typeName:n}}return null},g=l=>{l.forEach(o=>{if(o.type==="TSPropertySignature"&&o.key?.type==="Identifier"){let n=o.key.name,y=s(o.typeAnnotation);y&&I.set(n,y)}})},i=l=>{l.forEach(o=>{if(o.type==="ObjectPattern"&&o.typeAnnotation){let n=o.typeAnnotation.typeAnnotation;n&&n.type==="TSTypeLiteral"&&g(n.members),n&&n.type==="TSIntersectionType"&&n.types.forEach(y=>{y.type==="TSTypeLiteral"&&g(y.members)})}if(o.type==="Identifier"&&o.typeAnnotation){let n=s(o);n&&I.set(o.name,n)}})},r=(l,o)=>{let y=t.getScope?t.getScope(o):e.getScope();for(;y;){if(y.variables.some(p=>p.name===l))return!0;y=y.upper}return!1};return{"ArrowFunctionExpression, FunctionDeclaration, FunctionExpression"(l){i(l.params)},AssignmentPattern(l){if(l.left.type!=="Identifier")return;let o=l.left.name,n=I.get(o);if(n&&l.right.type==="Literal"&&typeof l.right.value=="string"){let y=l.right.value,p=d(y),c=`${n.enumName}.${p}`,a=r(n.enumName,l);e.report({fix:a?u=>u.replaceText(l.right,c):void 0,message:`Use "${c}" instead of string literal "${y}"`,node:l.right})}},BinaryExpression(l){if(l.operator!=="==="&&l.operator!=="!==")return;let o=null,n=null;if(l.left.type==="Identifier"&&l.right.type==="Literal"?(o=l.left,n=l.right):l.right.type==="Identifier"&&l.left.type==="Literal"&&(o=l.right,n=l.left),!o||!n||typeof n.value!="string")return;let y=I.get(o.name);if(!y)return;let p=n.value,c=d(p),a=`${y.enumName}.${c}`,u=r(y.enumName,l);e.report({fix:u?T=>T.replaceText(n,a):void 0,message:`Use "${a}" instead of string literal "${p}"`,node:n})},"ArrowFunctionExpression:exit"(){I.clear()},"FunctionDeclaration:exit"(){I.clear()},"FunctionExpression:exit"(){I.clear()}}},meta:{docs:{description:"Enforce using enum values instead of string literals for typed variables"},fixable:"code",schema:[],type:"suggestion"}},Dt={create(e){let t=e.options[0]||{},I=["is","has","with","without"],S=t.booleanPrefixes||[...I,...t.extendBooleanPrefixes||[]],d=t.allowPastVerbBoolean||!1,s=t.allowContinuousVerbBoolean||!1,g=t.callbackPrefix||"on",i=t.allowActionSuffix||!1,r=new RegExp(`^(${S.join("|")})[A-Z]`),l=new RegExp(`^${g}[A-Z]`),o=/^[a-z]+ed$/,n=/^[a-z]+ing$/,y=["children","content","data","error","errors","items","permission","permissions","value","values"],p=C=>{let f=C.toLowerCase();return(y.some(A=>f.includes(A))?"has":"is")+C[0].toUpperCase()+C.slice(1)},c=C=>{if(C.startsWith("handle")&&C.length>6){let f=C.slice(6);return g+f[0].toUpperCase()+f.slice(1)}if(C.endsWith("Handler")&&C.length>7){let f=C.slice(0,-7);return g+f[0].toUpperCase()+f.slice(1)}return g+C[0].toUpperCase()+C.slice(1)},a=C=>{if(!C)return!1;let f=C.typeAnnotation;return f?f.type==="TSBooleanKeyword"?!0:f.type==="TSUnionType"?f.types.some(h=>h.type==="TSBooleanKeyword"):!1:!1},u=["MouseEventHandler","ChangeEventHandler","FormEventHandler","KeyboardEventHandler","FocusEventHandler","TouchEventHandler","PointerEventHandler","DragEventHandler","WheelEventHandler","AnimationEventHandler","TransitionEventHandler","ClipboardEventHandler","CompositionEventHandler","UIEventHandler","ScrollEventHandler","EventHandler"],T=C=>{if(!C)return!1;let f=C.typeAnnotation;if(!f)return!1;if(f.type==="TSFunctionType")return!0;if(f.type==="TSTypeReference"){let h=f.typeName?.name;if(h==="Function"||h==="VoidFunction"||u.includes(h))return!0}return f.type==="TSUnionType"?f.types.some(h=>h.type==="TSFunctionType"||h.type==="TSTypeReference"&&(h.typeName?.name==="Function"||h.typeName?.name==="VoidFunction"||u.includes(h.typeName?.name))):!1},x=C=>{if(!C)return!1;let f=C.typeAnnotation;return f?f.type==="TSTypeLiteral":!1},k=C=>!!(r.test(C)||d&&o.test(C)||s&&n.test(C)),m=C=>!!(l.test(C)||i&&C.endsWith("Action")&&C.length>6),b=C=>{let f=C;for(;f;){if(f.type==="ArrowFunctionExpression"||f.type==="FunctionExpression"||f.type==="FunctionDeclaration")return f;f=f.parent}return null},v=(C,f)=>{if(!C||!C.params||C.params.length===0)return null;let h=C.params[0];if(h.type!=="ObjectPattern")return null;for(let A of h.properties)if(A.type==="Property"&&A.key&&A.key.type==="Identifier"&&A.key.name===f)return A;return null},w=(C,f,h,A)=>{let L=[C.replaceText(f.key,A)],R=b(f);if(!R)return L;let P=v(R,h);if(!P)return L;let O=P.value||P.key;if(!O||O.type!=="Identifier")return L;P.shorthand!==!1&&P.key===P.value?L.push(C.replaceText(P,`${h}: ${A}`)):L.push(C.replaceText(O,A));let N=e.sourceCode?e.sourceCode.getScope(R):e.getScope(),j=(D,W)=>{let q=D.variables.find(_=>_.name===W);return q||(D.upper?j(D.upper,W):null)},M=j(N,h);if(M){let D=new Set;M.references.forEach(W=>{if(W.identifier===O)return;let q=`${W.identifier.range[0]}-${W.identifier.range[1]}`;D.has(q)||(D.add(q),L.push(C.replaceText(W.identifier,A)))})}return L},E=C=>{if(C.type!=="TSPropertySignature"||!C.key||C.key.type!=="Identifier")return;let f=C.key.name;if(!f.startsWith("_")){if(x(C.typeAnnotation)){let h=C.typeAnnotation.typeAnnotation;h&&h.members&&h.members.forEach(E);return}if(a(C.typeAnnotation)){if(!k(f)){let h=p(f);e.report({fix:A=>w(A,C,f,h),message:`Boolean prop "${f}" should start with a valid prefix (${S.join(", ")}). Use "${h}" instead.`,node:C.key})}return}if(T(C.typeAnnotation)&&!m(f)){let h=c(f);e.report({fix:A=>w(A,C,f,h),message:`Callback prop "${f}" should start with "${g}" prefix. Use "${h}" instead.`,node:C.key})}}},$=C=>{C.members&&C.members.forEach(E)};return{TSInterfaceDeclaration(C){!C.body||!C.body.body||C.body.body.forEach(E)},TSTypeAliasDeclaration(C){C.typeAnnotation?.type==="TSTypeLiteral"&&$(C.typeAnnotation)},TSTypeLiteral(C){C.parent?.type!=="TSTypeAliasDeclaration"&&$(C)}}},meta:{docs:{description:"Enforce naming conventions: boolean props must start with is/has/with/without, callback props must start with on"},fixable:"code",schema:[{additionalProperties:!1,properties:{allowActionSuffix:{default:!1,description:"Allow 'xxxAction' pattern for callback props (e.g., submitAction, copyAction)",type:"boolean"},allowContinuousVerbBoolean:{default:!1,description:"Allow continuous verb boolean props without prefix (e.g., loading, saving, fetching, closing)",type:"boolean"},allowPastVerbBoolean:{default:!1,description:"Allow past verb boolean props without prefix (e.g., disabled, selected, checked, opened)",type:"boolean"},booleanPrefixes:{description:"Replace default boolean prefixes entirely. If not provided, defaults are used with extendBooleanPrefixes",items:{type:"string"},type:"array"},callbackPrefix:{default:"on",description:"Required prefix for callback props",type:"string"},extendBooleanPrefixes:{default:[],description:"Add additional prefixes to the defaults (is, has, with, without)",items:{type:"string"},type:"array"}},type:"object"}],type:"suggestion"}},Jt={create(e){let t=e.sourceCode||e.getSourceCode(),I=e.options[0]||{},S=I.maxUnionMembers??2,d=I.maxLength??50,s=new Set(["any","bigint","boolean","never","null","number","object","string","symbol","undefined","unknown","void"]),g=new Set(["Array","BigInt","Boolean","Date","Error","Function","Map","Number","Object","Promise","ReadonlyArray","RegExp","Set","String","Symbol","WeakMap","WeakSet"]),i=n=>{if(!n)return!1;if(n.type==="TSStringKeyword"||n.type==="TSNumberKeyword"||n.type==="TSBooleanKeyword"||n.type==="TSNullKeyword"||n.type==="TSUndefinedKeyword"||n.type==="TSVoidKeyword"||n.type==="TSAnyKeyword"||n.type==="TSUnknownKeyword"||n.type==="TSNeverKeyword"||n.type==="TSObjectKeyword"||n.type==="TSSymbolKeyword"||n.type==="TSBigIntKeyword")return!0;if(n.type==="TSTypeReference"&&n.typeName){let y=n.typeName.name||n.typeName.type==="Identifier"&&n.typeName.name;if(y&&g.has(y))return!0}return n.type==="TSLiteralType"},r=n=>n.type!=="TSUnionType"?!1:n.types.every(y=>i(y)),l=n=>{if(n.type!=="TSUnionType")return 1;let y=0;for(let p of n.types)y+=l(p);return y},o=(n,y)=>{if(n){if(n.type==="TSUnionType"){if(r(n))return;let p=l(n),c=t.getText(n);(p>=S||c.length>d)&&e.report({message:`Inline union type with ${p} members is too complex. Extract to a named type in a types file.`,node:n});return}if(n.type==="TSIntersectionType"){for(let p of n.types)o(p,y);return}if(n.type==="TSTypeLiteral"){for(let p of n.members)if(p.type==="TSPropertySignature"&&p.typeAnnotation){let c=p.typeAnnotation.typeAnnotation,a=p.key&&p.key.name?p.key.name:"unknown";if(c&&c.type==="TSUnionType"){let u=l(c),T=t.getText(c);(u>=S||T.length>d)&&e.report({message:`Property "${a}" has inline union type with ${u} members. Extract to a named type in a types file.`,node:c})}}}}};return{ArrowFunctionExpression(n){for(let y of n.params)if(y.typeAnnotation&&y.typeAnnotation.typeAnnotation){let p=y.type==="Identifier"?y.name:"param";o(y.typeAnnotation.typeAnnotation,p)}},FunctionDeclaration(n){for(let y of n.params)if(y.typeAnnotation&&y.typeAnnotation.typeAnnotation){let p=y.type==="Identifier"?y.name:"param";o(y.typeAnnotation.typeAnnotation,p)}},FunctionExpression(n){for(let y of n.params)if(y.typeAnnotation&&y.typeAnnotation.typeAnnotation){let p=y.type==="Identifier"?y.name:"param";o(y.typeAnnotation.typeAnnotation,p)}}}},meta:{docs:{description:"Enforce extracting inline union types to named types in type files"},schema:[{additionalProperties:!1,properties:{maxLength:{default:50,description:"Maximum character length for inline union types (default: 50)",minimum:1,type:"integer"},maxUnionMembers:{default:2,description:"Maximum union members to keep inline (default: 2)",minimum:1,type:"integer"}},type:"object"}],type:"suggestion"}},Xt={create(e){let t=e.sourceCode||e.getSourceCode(),I=e.options[0]||{},S=I.minUnionMembersForMultiline!==void 0?I.minUnionMembersForMultiline:5,d=/^[A-Z][a-zA-Z0-9]*$/,s=/^[a-z][a-zA-Z0-9]*$/,g=l=>/^[A-Z][A-Z0-9_]*$/.test(l)?l.toLowerCase().replace(/_([a-z0-9])/g,(o,n)=>n.toUpperCase()):/_/.test(l)?l.toLowerCase().replace(/_([a-z0-9])/g,(o,n)=>n.toUpperCase()):/^[A-Z]/.test(l)?l[0].toLowerCase()+l.slice(1):l,i=(l,o,n)=>{if(n.length===0)return;let p=t.lines[l.loc.start.line-1].match(/^\s*/)[0],c=p+" ",a=t.getFirstToken(o),u=t.getLastToken(o),T=n[0];T.loc.start.line-a.loc.end.line>1&&e.report({fix:k=>k.replaceTextRange([a.range[1],T.range[0]],`
|
|
225
|
+
`))&&e.report({fix:n=>n.replaceTextRange([s.range[1],i.range[0]],""),message:"No space before closing bracket in member expression",node:i})};return{MemberExpression(S){S.computed&&I(S,S.object,S.property)},TSIndexedAccessType(S){I(S,S.objectType,S.indexType)}}},meta:{docs:{description:"Enforce no spaces inside brackets for member expressions"},fixable:"code",schema:[],type:"layout"}};var Mt={create(e){let t=e.options[0]||{},I=["accept","acceptCharset","accessKey","action","align","allow","allowFullScreen","alt","as","async","autoCapitalize","autoComplete","autoCorrect","autoFocus","autoPlay","capture","cellPadding","cellSpacing","charSet","className","clipPath","clipRule","colorInterpolation","colorInterpolationFilters","classNames","colSpan","contentEditable","controls","controlsList","coords","crossOrigin","d","data","data-*","dateTime","decoding","default","defer","dir","disabled","download","draggable","encType","enterKeyHint","fill","fillOpacity","fillRule","filter","filterUnits","floodColor","floodOpacity","for","form","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","headers","height","hidden","high","href","hrefLang","htmlFor","httpEquiv","gradientTransform","gradientUnits","icon","id","in","in2","imagesizes","imagesrcset","inputMode","integrity","is","itemID","itemProp","itemRef","itemScope","itemType","key","keyParams","keyType","kind","lang","list","loading","loop","low","marginHeight","marginWidth","markerEnd","markerMid","markerStart","markerUnits","mask","max","mode","maxLength","media","mediaGroup","method","min","minLength","multiple","muted","name","noModule","noValidate","nonce","open","optimum","pattern","patternContentUnits","patternTransform","patternUnits","ping","preserveAspectRatio","playsInline","poster","preload","profile","radioGroup","readOnly","referrerPolicy","rel","repeatCount","repeatDur","required","result","reversed","role","rowSpan","rows","sandbox","scope","scoped","scrolling","seamless","selected","shape","sizes","slot","span","spellCheck","src","srcDoc","srcLang","srcSet","start","step","spreadMethod","stdDeviation","stopColor","stopOpacity","stroke","strokeDasharray","strokeDashoffset","strokeLinecap","strokeLinejoin","strokeMiterlimit","strokeOpacity","strokeWidth","style","summary","tabIndex","target","testId","textAnchor","textDecoration","transform","translate","vectorEffect","useMap","value","viewBox","width","wmode","wrap","x","x1","x2","xmlns","y","y1","y2","baseFrequency","numOctaves","seed","stitchTiles","operator","k1","k2","k3","k4","surfaceScale","diffuseConstant","specularConstant","specularExponent","kernelMatrix","order","targetX","targetY","edgeMode","kernelUnitLength","bias","divisor","preserveAlpha","radius","azimuth","elevation","limitingConeAngle","pointsAtX","pointsAtY","pointsAtZ","cx","cy","r","rx","ry","points","pathLength","offset","dx","dy","rotate","lengthAdjust","textLength"],S=t.ignoreAttributes||[...I,...t.extraIgnoreAttributes||[]],d=[/^\s*$/,/^.$/,/^-?\d+(\.\d+)?(px|em|rem|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|deg|rad|turn|s|ms|fr)?$/,/^-?\d+(\.\d+)?e[+-]?\d+$/i,/^#[0-9a-fA-F]{3,8}$/,/^(rgb|rgba|hsl|hsla)\(.+\)$/,/^url\(#?.+\)$/,/^(round|butt|square|miter|bevel|none|normal|evenodd|nonzero|sRGB|linearRGB|userSpaceOnUse|objectBoundingBox|pad|reflect|repeat|auto|inherit|currentColor|meet|slice|xMinYMin|xMidYMin|xMaxYMin|xMinYMid|xMidYMid|xMaxYMid|xMinYMax|xMidYMax|xMaxYMax|stitch|noStitch|duplicate|wrap|arithmetic|atop|in|out|over|xor|dilate|erode|matrix|saturate|hueRotate|luminanceToAlpha|discrete|linear|gamma|table|identity|SourceGraphic|SourceAlpha|BackgroundImage|BackgroundAlpha|FillPaint|StrokePaint)$/,/^[a-zA-Z]+\d*[_a-zA-Z0-9]*(_[a-zA-Z0-9]+)+$/,/^(white|black|red|green|blue|yellow|orange|purple|pink|brown|gray|grey|cyan|magenta|transparent)$/i,/^(auto|default|none|context-menu|help|pointer|progress|wait|cell|crosshair|vertical-text|alias|copy|move|no-drop|not-allowed|grab|grabbing|all-scroll|col-resize|row-resize|n-resize|e-resize|s-resize|w-resize|ne-resize|nw-resize|se-resize|sw-resize|ew-resize|ns-resize|nesw-resize|nwse-resize|zoom-in|zoom-out)$/,/^(block|inline|inline-block|flex|inline-flex|grid|inline-grid|flow-root|contents|table|table-row|table-cell|list-item|none|visible|hidden|collapse)$/,/^(static|relative|absolute|fixed|sticky)$/,/^(visible|hidden|scroll|auto|clip)$/,/^(https?:\/\/|\/\/|\/|\.\/|\.\.\/)/,/^data:/,/^mailto:/,/^tel:/,/^\.[a-zA-Z0-9]+$/,/^[a-z]+\/[a-z0-9.+-]+$/,/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/,/^\d{1,2}:\d{2}(:\d{2})?(\s?(AM|PM|am|pm))?$/,/^[a-z]+[A-Z][a-zA-Z0-9]*$/,/^[a-z][a-z0-9]*_[a-z0-9_]*$/,/^[A-Z][A-Z0-9]*_[A-Z0-9_]+$/,/^(true|false|null|undefined|NaN|Infinity)$/,/^application\//,/^[a-z][a-zA-Z0-9_]*=/,/^[a-z]+-[a-z]+(-[a-z]+)*$/,/^-?[a-z]+-\d+(\.\d+)?(\/\d+)?$/,/^-?[a-z]+-[a-z]+-\d+(\.\d+)?(\/\d+)?$/,/^[a-z]+:[a-z][-a-z0-9/]*$/,/^[a-z]+-[a-z]+(-[a-z]+)*\/\d+$/,/^-?[a-z]+(-[a-z]+)*-\[.+\]$/,/^-[a-z]+-[a-z]+-\d+\/\d+$/,/^[a-z]+-(full|auto|screen|none|inherit|initial|px|fit|min|max)$/,/^(sm|md|lg|xl|2xl|hover|focus|active|disabled|first|last|odd|even|group-hover|dark|motion-safe|motion-reduce):[a-z][-a-z0-9/[\]]*$/,/^[\d,._]+$/,/^\d+\.\d+\.\d+/,/^[,;:|•·\-–—/\\]+$/,/^&[a-z]+;$/,/^[.!?,;:'"()\[\]{}]+$/,/^(rotate|translate|translateX|translateY|translateZ|translate3d|scale|scaleX|scaleY|scaleZ|scale3d|skew|skewX|skewY|matrix|matrix3d|perspective)\(.+\)$/,/^(rotate|translate|translateX|translateY|scale|scaleX|scaleY|skew|skewX|skewY|matrix)\([^)]+\)(\s+(rotate|translate|translateX|translateY|scale|scaleX|scaleY|skew|skewX|skewY|matrix)\([^)]+\))+$/,/^(linear-gradient|radial-gradient|conic-gradient|repeating-linear-gradient|repeating-radial-gradient)\(.+\)$/,/^[a-zA-Z][\w-]*\s+[\d.]+m?s\s+[\w-]+(\s+[\w-]+)*$/,/^(\d+%|center|top|bottom|left|right)(\s+(\d+%|center|top|bottom|left|right))?$/,/^calc\(.+\)$/,/^var\(.+\)$/,/^clamp\(.+\)$/,/^(min|max)\(.+\)$/],s=(t.ignorePatterns||[]).map(f=>typeof f=="string"?new RegExp(f):f),g=[...d,...s],i=/^-?[a-z]+(-[a-z0-9]+)*(\/\d+)?$|^-?[a-z]+(-[a-z0-9]+)*-\[.+\]$|^[a-z]+:[a-z][-a-z0-9/[\]]*$/,r=new Set(["block","contents","flex","flow","grid","hidden","inline","table","absolute","fixed","relative","static","sticky","collapse","invisible","visible","antialiased","capitalize","italic","lowercase","ordinal","overline","subpixel","truncate","underline","uppercase","container","isolate","grow","shrink","border","rounded","group","peer","resize","snap","touch","select","pointer","transition","animate","filter","backdrop","transform","appearance","cursor","outline","ring","shadow","opacity","blur","invert","sepia","grayscale","hue","saturate","brightness","contrast"]),l=f=>{let h=f.trim().split(/\s+/).filter(Boolean);return h.length===0||!h.some(L=>L.includes("-")||L.includes(":")||L.includes("/")||L.includes("["))?!1:h.every(L=>L.includes("${")||r.has(L)?!0:/^-?[a-z]+(-[a-z0-9.]+)+$/.test(L)||/^-?[a-z]+(-[a-z0-9.]+)*\/\d+$/.test(L)||/^[a-z][-a-z0-9]*(\[[-\w=]+\])?:[a-z][-a-z0-9./[\]]*$/.test(L)||/^\[.+\]:[a-z][-a-z0-9./[\]]*$/.test(L)||/^-?[a-z]+(-[a-z]+)*-?\[.+\]$/.test(L))},o=new Set(["button","checkbox","color","date","datetime-local","email","file","hidden","image","month","number","password","radio","range","reset","search","submit","tel","text","time","url","week"]),n=f=>o.has(f.toLowerCase()),y=f=>{let h=f.parent;for(;h;){if(h.type==="Property"&&h.parent&&h.parent.type==="ObjectExpression"){let A=h.parent;if(A.parent&&A.parent.type==="JSXExpressionContainer"){let L=A.parent;if(L.parent&&L.parent.type==="JSXAttribute"&&(L.parent.name&&L.parent.name.name)==="style")return!0}}h=h.parent}return!1},p=[/gradient/i,/transform/i,/animation/i,/transition/i,/color/i,/background/i,/border/i,/shadow/i,/filter/i,/clip/i,/mask/i,/font/i,/^style/i,/Style$/i,/css/i],c=f=>!!(/^(linear-gradient|radial-gradient|conic-gradient|repeating-linear-gradient|repeating-radial-gradient|rotate|translate|translateX|translateY|translateZ|translate3d|scale|scaleX|scaleY|scaleZ|scale3d|skew|skewX|skewY|matrix|matrix3d|perspective|calc|var|clamp|min|max|cubic-bezier|steps|url)\(/i.test(f)||/^(#[0-9a-fA-F]{3,8}|rgb|rgba|hsl|hsla)\(/i.test(f)||/^\d+(\.\d+)?(px|em|rem|%|vh|vw|vmin|vmax|deg|rad|turn|s|ms|fr)\s*/.test(f)),a=f=>{let h=f.parent;for(;h;){if(h.type==="VariableDeclarator"&&h.id&&h.id.name){let A=h.id.name;if(p.some(L=>L.test(A)))return!0}if(h.type==="Property"&&h.key){let A=h.key.name||h.key.value&&String(h.key.value);if(A&&p.some(L=>L.test(A)))return!0}h=h.parent}return!1},u=f=>{let h=f.parent,A=0;for(;h;){if(A++,h.type==="ExportNamedDeclaration"&&A<=3){let L=h.declaration;if(L&&L.type==="VariableDeclaration"){let R=L.declarations[0];if(R&&R.id&&R.id.name){let P=R.id.name;return!(/^[A-Z][A-Z0-9_]*$/.test(P)||/^(constants?|strings?|messages?|labels?|texts?|data)$/i.test(P))}}}if(h.type==="FunctionDeclaration"||h.type==="FunctionExpression"||h.type==="ArrowFunctionExpression")return!1;h=h.parent}return!1},T=(f,h="")=>{let A=f.length>30?`${f.substring(0,30)}...`:f,L=h?` in ${h}`:"",R=!/\s/.test(f)&&f.length<=30,P=/^[a-z_]+$/.test(f),O=h.includes("attribute");return R&&P?O?`Hardcoded "${A}"${L} should be imported from @/enums (preferred) or @/data to prevent typos (e.g., import { InputTypeEnum } from "@/enums")`:`Hardcoded "${A}"${L} should be imported from @/enums (preferred) or @/data (e.g., import { StatusEnum } from "@/enums")`:`Hardcoded UI string "${A}"${L} should be imported from @/strings or @/constants (e.g., import { strings } from "@/strings")`},x=new Set(["cn","cva","clsx","twMerge","classnames","cx","tv","twJoin"]),k=f=>{let h=f.parent,A=!1;for(;h;){if(h.type==="CallExpression"&&h.callee){let L=h.callee.name||h.callee.property&&h.callee.property.name;if(L&&x.has(L))return!0;A=!0}if(A&&h.type==="JSXAttribute"&&h.name){let L=h.name.name;if(L==="className"||L==="class")return!0}h=h.parent}return!1},m=(f,h)=>h&&k(h)||l(f)?!0:g.some(A=>A.test(f)),b=()=>{let h=(e.filename||e.getFilename()).replace(/\\/g,"/").toLowerCase();return/\/(constants|strings|@constants|@strings|data|@data|enums|@enums)(\/|\.)/i.test(h)||/\/data\/(constants|strings)/i.test(h)},v=new Set,w=f=>{let h=f.source.value;if(typeof h!="string")return;/@?\/?(@?constants|@?strings|@?data|@?enums|data\/constants|data\/strings)/i.test(h)&&f.specifiers.forEach(L=>{L.local&&L.local.name&&v.add(L.local.name)})},E=f=>f.type==="Identifier"?v.has(f.name):f.type==="MemberExpression"&&f.object.type==="Identifier"?v.has(f.object.name):!1,$=f=>{let h=f.parent;for(;h;){if(h.type==="FunctionDeclaration"||h.type==="FunctionExpression"||h.type==="ArrowFunctionExpression"){let A=null;return h.id&&h.id.name?A=h.id.name:h.parent&&h.parent.type==="VariableDeclarator"&&h.parent.id&&h.parent.id.name&&(A=h.parent.id.name),A&&(/^[A-Z]/.test(A)||/^use[A-Z]/.test(A)||/Handler$|Helper$|Util$|Utils$/i.test(A)),!0}if(h.type==="JSXElement"||h.type==="JSXFragment")return!0;h=h.parent}return!1},C=f=>{let h=f.parent,A=0;for(;h;){if(A++,h.type==="VariableDeclarator"){let L=h.id&&h.id.name;if(L&&(/^[A-Z][A-Z0-9_]*$/.test(L)||/^(constants?|strings?|messages?|labels?|texts?|data)$/i.test(L)))return!0}if(h.type==="ExportNamedDeclaration"&&A<=3){let L=h.declaration;if(L&&L.type==="VariableDeclaration"){let R=L.declarations[0];if(R&&R.init){let P=R.init.type;if(P==="Literal"||P==="ObjectExpression"||P==="ArrayExpression")return!0}}}if(h.type==="FunctionDeclaration"||h.type==="FunctionExpression"||h.type==="ArrowFunctionExpression")return!1;h=h.parent}return!1};return b()?{}:{ImportDeclaration:w,JSXText(f){let h=f.value.trim();h&&(m(h,f)||/[a-zA-Z]/.test(h)&&e.report({message:T(h,"JSX"),node:f}))},JSXExpressionContainer(f){let{expression:h}=f;if(!E(h)){if(f.parent&&f.parent.type==="JSXAttribute"){let A=f.parent.name.name||f.parent.name.namespace&&`${f.parent.name.namespace.name}:${f.parent.name.name.name}`;if(S.includes(A)||A&&(A.startsWith("data-")||A.startsWith("aria-")))return}if(h.type==="Literal"&&typeof h.value=="string"){let A=h.value;if(m(A,h)||!/[a-zA-Z]/.test(A))return;e.report({message:T(A,"JSX expression"),node:h})}h.type==="TemplateLiteral"&&h.quasis.forEach(A=>{let L=A.value.cooked||A.value.raw;m(L,h)||/[a-zA-Z]{2,}/.test(L)&&(/^[/.]|https?:\/\//.test(L)||e.report({message:T(L,"template literal"),node:A}))})}},JSXAttribute(f){if(!f.value)return;let h=f.name.name||f.name.namespace&&`${f.name.namespace.name}:${f.name.name.name}`;if(!S.includes(h)&&!(h&&h.startsWith("data-"))&&!(h&&h.startsWith("aria-"))){if(f.value.type==="Literal"&&typeof f.value.value=="string"){let A=f.value.value;if(m(A,f.value)||!/[a-zA-Z]/.test(A))return;e.report({message:T(A,`attribute "${h}"`),node:f.value})}if(f.value.type==="JSXExpressionContainer"){let{expression:A}=f.value;if(E(A))return;if(A.type==="Literal"&&typeof A.value=="string"){let L=A.value;if(m(L,A)||!/[a-zA-Z]/.test(L))return;e.report({message:T(L,`attribute "${h}"`),node:A})}}}},Literal(f){if(typeof f.value!="string")return;let h=f.value;if(!y(f)){if(u(f)){if(!/[a-zA-Z]/.test(h))return;e.report({message:T(h,"exported constant"),node:f});return}m(h,f)||$(f)&&(C(f)||f.parent.type==="JSXAttribute"||f.parent.type==="JSXExpressionContainer"||f.parent.type==="ImportDeclaration"||f.parent.type==="ExportNamedDeclaration"||f.parent.type==="ExportAllDeclaration"||f.parent.type==="Property"&&f.parent.key===f||/[a-zA-Z]/.test(h)&&e.report({message:T(h),node:f}))}},TemplateLiteral(f){if(f.parent.type!=="JSXExpressionContainer"&&!y(f)){if(a(f)){let h=f.quasis.map(A=>A.value.cooked||A.value.raw).join("");if(c(h))return}$(f)&&(C(f)||f.quasis.forEach(h=>{let A=h.value.cooked||h.value.raw;m(A,f)||/[a-zA-Z]{3,}/.test(A)&&(/^[/.]|^https?:\/\/|^[?&]/.test(A)||f.expressions.length>f.quasis.length||e.report({message:T(A,"template literal"),node:h}))}))}}}},meta:{docs:{description:"Enforce importing strings from constants/strings modules instead of hardcoding them"},schema:[{additionalProperties:!1,properties:{extraIgnoreAttributes:{description:"Additional JSX attributes to ignore (extends defaults)",items:{type:"string"},type:"array"},ignoreAttributes:{description:"JSX attributes to ignore (replaces defaults)",items:{type:"string"},type:"array"},ignorePatterns:{description:"Regex patterns for strings to ignore",items:{type:"string"},type:"array"}},type:"object"}],type:"suggestion"}};var Nt={create(e){let t=e.sourceCode||e.getSourceCode(),I=new Map,S=l=>l.endsWith("Type")?l.slice(0,-4)+"Enum":null,d=l=>l.toUpperCase().replace(/-/g,"_"),s=l=>{if(!l)return null;let o=l.typeAnnotation;if(!o)return null;if(o.type==="TSTypeReference"&&o.typeName?.type==="Identifier"){let n=o.typeName.name;if(n.endsWith("Type"))return{enumName:S(n),typeName:n}}return null},g=l=>{l.forEach(o=>{if(o.type==="TSPropertySignature"&&o.key?.type==="Identifier"){let n=o.key.name,y=s(o.typeAnnotation);y&&I.set(n,y)}})},i=l=>{l.forEach(o=>{if(o.type==="ObjectPattern"&&o.typeAnnotation){let n=o.typeAnnotation.typeAnnotation;n&&n.type==="TSTypeLiteral"&&g(n.members),n&&n.type==="TSIntersectionType"&&n.types.forEach(y=>{y.type==="TSTypeLiteral"&&g(y.members)})}if(o.type==="Identifier"&&o.typeAnnotation){let n=s(o);n&&I.set(o.name,n)}})},r=(l,o)=>{let y=t.getScope?t.getScope(o):e.getScope();for(;y;){if(y.variables.some(p=>p.name===l))return!0;y=y.upper}return!1};return{"ArrowFunctionExpression, FunctionDeclaration, FunctionExpression"(l){i(l.params)},AssignmentPattern(l){if(l.left.type!=="Identifier")return;let o=l.left.name,n=I.get(o);if(n&&l.right.type==="Literal"&&typeof l.right.value=="string"){let y=l.right.value,p=d(y),c=`${n.enumName}.${p}`,a=r(n.enumName,l);e.report({fix:a?u=>u.replaceText(l.right,c):void 0,message:`Use "${c}" instead of string literal "${y}"`,node:l.right})}},BinaryExpression(l){if(l.operator!=="==="&&l.operator!=="!==")return;let o=null,n=null;if(l.left.type==="Identifier"&&l.right.type==="Literal"?(o=l.left,n=l.right):l.right.type==="Identifier"&&l.left.type==="Literal"&&(o=l.right,n=l.left),!o||!n||typeof n.value!="string")return;let y=I.get(o.name);if(!y)return;let p=n.value,c=d(p),a=`${y.enumName}.${c}`,u=r(y.enumName,l);e.report({fix:u?T=>T.replaceText(n,a):void 0,message:`Use "${a}" instead of string literal "${p}"`,node:n})},"ArrowFunctionExpression:exit"(){I.clear()},"FunctionDeclaration:exit"(){I.clear()},"FunctionExpression:exit"(){I.clear()}}},meta:{docs:{description:"Enforce using enum values instead of string literals for typed variables"},fixable:"code",schema:[],type:"suggestion"}},Dt={create(e){let t=e.options[0]||{},I=["is","has","with","without"],S=t.booleanPrefixes||[...I,...t.extendBooleanPrefixes||[]],d=t.allowPastVerbBoolean||!1,s=t.allowContinuousVerbBoolean||!1,g=t.callbackPrefix||"on",i=t.allowActionSuffix||!1,r=new RegExp(`^(${S.join("|")})[A-Z]`),l=new RegExp(`^${g}[A-Z]`),o=/^[a-z]+ed$/,n=/^[a-z]+ing$/,y=["children","content","data","error","errors","items","permission","permissions","value","values"],p=C=>{let f=C.toLowerCase();return(y.some(A=>f.includes(A))?"has":"is")+C[0].toUpperCase()+C.slice(1)},c=C=>{if(C.startsWith("handle")&&C.length>6){let f=C.slice(6);return g+f[0].toUpperCase()+f.slice(1)}if(C.endsWith("Handler")&&C.length>7){let f=C.slice(0,-7);return g+f[0].toUpperCase()+f.slice(1)}return g+C[0].toUpperCase()+C.slice(1)},a=C=>{if(!C)return!1;let f=C.typeAnnotation;return f?f.type==="TSBooleanKeyword"?!0:f.type==="TSUnionType"?f.types.some(h=>h.type==="TSBooleanKeyword"):!1:!1},u=["MouseEventHandler","ChangeEventHandler","FormEventHandler","KeyboardEventHandler","FocusEventHandler","TouchEventHandler","PointerEventHandler","DragEventHandler","WheelEventHandler","AnimationEventHandler","TransitionEventHandler","ClipboardEventHandler","CompositionEventHandler","UIEventHandler","ScrollEventHandler","EventHandler"],T=C=>{if(!C)return!1;let f=C.typeAnnotation;if(!f)return!1;if(f.type==="TSFunctionType")return!0;if(f.type==="TSTypeReference"){let h=f.typeName?.name;if(h==="Function"||h==="VoidFunction"||u.includes(h))return!0}return f.type==="TSUnionType"?f.types.some(h=>h.type==="TSFunctionType"||h.type==="TSTypeReference"&&(h.typeName?.name==="Function"||h.typeName?.name==="VoidFunction"||u.includes(h.typeName?.name))):!1},x=C=>{if(!C)return!1;let f=C.typeAnnotation;return f?f.type==="TSTypeLiteral":!1},k=C=>!!(r.test(C)||d&&o.test(C)||s&&n.test(C)),m=C=>!!(l.test(C)||i&&C.endsWith("Action")&&C.length>6),b=C=>{let f=C;for(;f;){if(f.type==="ArrowFunctionExpression"||f.type==="FunctionExpression"||f.type==="FunctionDeclaration")return f;f=f.parent}return null},v=(C,f)=>{if(!C||!C.params||C.params.length===0)return null;let h=C.params[0];if(h.type!=="ObjectPattern")return null;for(let A of h.properties)if(A.type==="Property"&&A.key&&A.key.type==="Identifier"&&A.key.name===f)return A;return null},w=(C,f,h,A)=>{let L=[C.replaceText(f.key,A)],R=b(f);if(!R)return L;let P=v(R,h);if(!P)return L;let O=P.value||P.key;if(!O||O.type!=="Identifier")return L;P.shorthand!==!1&&P.key===P.value?L.push(C.replaceText(P,`${h}: ${A}`)):L.push(C.replaceText(O,A));let N=e.sourceCode?e.sourceCode.getScope(R):e.getScope(),j=(D,W)=>{let q=D.variables.find(_=>_.name===W);return q||(D.upper?j(D.upper,W):null)},M=j(N,h);if(M){let D=new Set;M.references.forEach(W=>{if(W.identifier===O)return;let q=`${W.identifier.range[0]}-${W.identifier.range[1]}`;D.has(q)||(D.add(q),L.push(C.replaceText(W.identifier,A)))})}return L},E=C=>{if(C.type!=="TSPropertySignature"||!C.key||C.key.type!=="Identifier")return;let f=C.key.name;if(!f.startsWith("_")){if(x(C.typeAnnotation)){let h=C.typeAnnotation.typeAnnotation;h&&h.members&&h.members.forEach(E);return}if(a(C.typeAnnotation)){if(!k(f)){let h=p(f);e.report({fix:A=>w(A,C,f,h),message:`Boolean prop "${f}" should start with a valid prefix (${S.join(", ")}). Use "${h}" instead.`,node:C.key})}return}if(T(C.typeAnnotation)&&!m(f)){let h=c(f);e.report({fix:A=>w(A,C,f,h),message:`Callback prop "${f}" should start with "${g}" prefix. Use "${h}" instead.`,node:C.key})}}},$=C=>{C.members&&C.members.forEach(E)};return{TSInterfaceDeclaration(C){!C.body||!C.body.body||C.body.body.forEach(E)},TSTypeAliasDeclaration(C){C.typeAnnotation?.type==="TSTypeLiteral"&&$(C.typeAnnotation)},TSTypeLiteral(C){C.parent?.type!=="TSTypeAliasDeclaration"&&$(C)}}},meta:{docs:{description:"Enforce naming conventions: boolean props must start with is/has/with/without, callback props must start with on"},fixable:"code",schema:[{additionalProperties:!1,properties:{allowActionSuffix:{default:!1,description:"Allow 'xxxAction' pattern for callback props (e.g., submitAction, copyAction)",type:"boolean"},allowContinuousVerbBoolean:{default:!1,description:"Allow continuous verb boolean props without prefix (e.g., loading, saving, fetching, closing)",type:"boolean"},allowPastVerbBoolean:{default:!1,description:"Allow past verb boolean props without prefix (e.g., disabled, selected, checked, opened)",type:"boolean"},booleanPrefixes:{description:"Replace default boolean prefixes entirely. If not provided, defaults are used with extendBooleanPrefixes",items:{type:"string"},type:"array"},callbackPrefix:{default:"on",description:"Required prefix for callback props",type:"string"},extendBooleanPrefixes:{default:[],description:"Add additional prefixes to the defaults (is, has, with, without)",items:{type:"string"},type:"array"}},type:"object"}],type:"suggestion"}},Jt={create(e){let t=e.sourceCode||e.getSourceCode(),I=e.options[0]||{},S=I.maxUnionMembers??2,d=I.maxLength??50,s=new Set(["any","bigint","boolean","never","null","number","object","string","symbol","undefined","unknown","void"]),g=new Set(["Array","BigInt","Boolean","Date","Error","Function","Map","Number","Object","Promise","ReadonlyArray","RegExp","Set","String","Symbol","WeakMap","WeakSet"]),i=n=>{if(!n)return!1;if(n.type==="TSStringKeyword"||n.type==="TSNumberKeyword"||n.type==="TSBooleanKeyword"||n.type==="TSNullKeyword"||n.type==="TSUndefinedKeyword"||n.type==="TSVoidKeyword"||n.type==="TSAnyKeyword"||n.type==="TSUnknownKeyword"||n.type==="TSNeverKeyword"||n.type==="TSObjectKeyword"||n.type==="TSSymbolKeyword"||n.type==="TSBigIntKeyword")return!0;if(n.type==="TSTypeReference"&&n.typeName){let y=n.typeName.name||n.typeName.type==="Identifier"&&n.typeName.name;if(y&&g.has(y))return!0}return n.type==="TSLiteralType"},r=n=>n.type!=="TSUnionType"?!1:n.types.every(y=>i(y)),l=n=>{if(n.type!=="TSUnionType")return 1;let y=0;for(let p of n.types)y+=l(p);return y},o=(n,y)=>{if(n){if(n.type==="TSUnionType"){if(r(n))return;let p=l(n),c=t.getText(n);(p>=S||c.length>d)&&e.report({message:`Inline union type with ${p} members is too complex. Extract to a named type in a types file.`,node:n});return}if(n.type==="TSIntersectionType"){for(let p of n.types)o(p,y);return}if(n.type==="TSTypeLiteral"){for(let p of n.members)if(p.type==="TSPropertySignature"&&p.typeAnnotation){let c=p.typeAnnotation.typeAnnotation,a=p.key&&p.key.name?p.key.name:"unknown";if(c&&c.type==="TSUnionType"){let u=l(c),T=t.getText(c);(u>=S||T.length>d)&&e.report({message:`Property "${a}" has inline union type with ${u} members. Extract to a named type in a types file.`,node:c})}}}}};return{ArrowFunctionExpression(n){for(let y of n.params)if(y.typeAnnotation&&y.typeAnnotation.typeAnnotation){let p=y.type==="Identifier"?y.name:"param";o(y.typeAnnotation.typeAnnotation,p)}},FunctionDeclaration(n){for(let y of n.params)if(y.typeAnnotation&&y.typeAnnotation.typeAnnotation){let p=y.type==="Identifier"?y.name:"param";o(y.typeAnnotation.typeAnnotation,p)}},FunctionExpression(n){for(let y of n.params)if(y.typeAnnotation&&y.typeAnnotation.typeAnnotation){let p=y.type==="Identifier"?y.name:"param";o(y.typeAnnotation.typeAnnotation,p)}}}},meta:{docs:{description:"Enforce extracting inline union types to named types in type files"},schema:[{additionalProperties:!1,properties:{maxLength:{default:50,description:"Maximum character length for inline union types (default: 50)",minimum:1,type:"integer"},maxUnionMembers:{default:2,description:"Maximum union members to keep inline (default: 2)",minimum:1,type:"integer"}},type:"object"}],type:"suggestion"}},Xt={create(e){let t=e.sourceCode||e.getSourceCode(),I=e.options[0]||{},S=I.minUnionMembersForMultiline!==void 0?I.minUnionMembersForMultiline:5,d=/^[A-Z][a-zA-Z0-9]*$/,s=/^[a-z][a-zA-Z0-9]*$/,g=l=>/^[A-Z][A-Z0-9_]*$/.test(l)?l.toLowerCase().replace(/_([a-z0-9])/g,(o,n)=>n.toUpperCase()):/_/.test(l)?l.toLowerCase().replace(/_([a-z0-9])/g,(o,n)=>n.toUpperCase()):/^[A-Z]/.test(l)?l[0].toLowerCase()+l.slice(1):l,i=(l,o,n)=>{if(n.length===0)return;let p=t.lines[l.loc.start.line-1].match(/^\s*/)[0],c=p+" ",a=t.getFirstToken(o),u=t.getLastToken(o),T=n[0];T.loc.start.line-a.loc.end.line>1&&e.report({fix:k=>k.replaceTextRange([a.range[1],T.range[0]],`
|
|
226
226
|
`+c),message:"No empty line after opening brace in type",node:T});let x=n[n.length-1];u.loc.start.line-x.loc.end.line>1&&e.report({fix:k=>k.replaceTextRange([x.range[1],u.range[0]],`
|
|
227
227
|
`+p),message:"No empty line before closing brace in type",node:x}),n.length>=2&&u.loc.start.line===x.loc.end.line&&e.report({fix:k=>k.replaceTextRange([x.range[1],u.range[0]],`
|
|
228
228
|
`+p),message:"Closing brace should be on its own line in multiline type literal",node:u}),n.length>1&&T.loc.start.line===a.loc.end.line&&e.report({fix:k=>k.replaceTextRange([a.range[1],T.range[0]],`
|
|
@@ -273,4 +273,4 @@ ${y})`;e.report({fix:u=>u.replaceTextRange([g.range[0],i.range[1]],a),message:"F
|
|
|
273
273
|
`);return k.replaceTextRange([x.range[1],a.range[0]],b)},message:"No empty lines allowed between interface properties",node:a})}}),r.length>1){let a=t.getText(c),u=a.trimEnd(),T=t.getTokenAfter(c),x=u.endsWith(",")||T&&T.value===",",k=u.endsWith(";"),m=y.loc.start.line===c.loc.end.line;if(k){let b=a.lastIndexOf(";"),v=c.range[0]+b;m?e.report({fix:w=>w.replaceTextRange([v,y.range[0]],`,
|
|
274
274
|
`+o),message:"Last interface property must end with comma and closing brace must be on its own line",node:c}):e.report({fix:w=>w.replaceTextRange([v,v+1],","),message:"Interface properties must end with comma (,) not semicolon (;)",node:c})}else!x&&m?e.report({fix:b=>b.replaceTextRange([c.range[1],y.range[0]],`,
|
|
275
275
|
`+o),message:"Last interface property must have trailing comma and closing brace must be on its own line",node:c}):x?m&&e.report({fix:b=>b.replaceTextRange([c.range[1],y.range[0]],`
|
|
276
|
-
`+o),message:"Closing brace must be on its own line",node:y}):e.report({fix:b=>b.insertTextAfter(c,","),message:"Last interface property must have trailing comma",node:c})}}}},meta:{docs:{description:"Enforce interface naming (PascalCase + Interface suffix), camelCase properties, proper formatting, and trailing commas"},fixable:"code",schema:[],type:"suggestion"}},Ut={create(e){let I=(e.filename||e.getFilename()).replace(/\\/g,"/"),S=s=>new RegExp(`/${s}/[^/]+\\.(ts|tsx)$`).test(I),d=()=>/\.(ts|tsx)$/.test(I);return{TSInterfaceDeclaration(s){d()&&(S("interfaces")||e.report({message:'Interfaces must be declared in files inside the "interfaces" folder',node:s.id||s}))},TSEnumDeclaration(s){d()&&(S("enums")||e.report({message:'Enums must be declared in files inside the "enums" folder',node:s.id||s}))},TSTypeAliasDeclaration(s){d()&&(S("types")||e.report({message:'Type aliases must be declared in files inside the "types" folder',node:s.id||s}))}}},meta:{docs:{description:"Enforce that interfaces are in interfaces folder, enums in enums folder, and types in types folder"},schema:[],type:"suggestion"}};var _t={create(e){let t=e.sourceCode||e.getSourceCode(),I=/^[a-z][a-zA-Z0-9]*$/,S=/^[A-Z][a-zA-Z0-9]*$/,d=/^use[A-Z][a-zA-Z0-9]*$/,s=/^[A-Z][A-Z0-9_]*$/,g=m=>/^[A-Z][A-Z0-9_]*$/.test(m)?m.toLowerCase().replace(/_([a-z0-9])/g,(b,v)=>v.toUpperCase()):/_/.test(m)?m.toLowerCase().replace(/_([a-z0-9])/g,(b,v)=>v.toUpperCase()):/^[A-Z]/.test(m)?m[0].toLowerCase()+m.slice(1):m,i=m=>{let v=(t.getScope?t.getScope(m):e.getScope()).variables.find(w=>w.name===m.name);return v?v.references.map(w=>w.identifier):[]},r=["ArrowFunctionExpression","CallExpression","FunctionDeclaration","FunctionExpression","Property","VariableDeclarator","JSXElement","JSXOpeningElement","ReturnStatement","SwitchCase","SwitchStatement","ObjectExpression","ObjectPattern","BlockStatement","IfStatement","Identifier","RestElement","AssignmentPattern","ArrayPattern","MemberExpression","JSXText","JSXAttribute","JSXExpressionContainer","Function","Object","Array","String","Number","Boolean","Symbol","BigInt","Date","RegExp","Error","Map","Set","WeakMap","WeakSet","Promise"],l=m=>{if(!m||m.type!=="CallExpression")return!1;let{callee:b}=m;if(b.type==="CallExpression"){let v=b.callee;if(v.type==="Identifier"&&v.name==="styled"||v.type==="MemberExpression"&&v.object.name==="styled")return!0}return!1},o=m=>{if(m.type!=="CallExpression")return!1;let{callee:b}=m;return b.type==="Identifier"&&b.name==="styled"},n=m=>{if(!m)return!1;if(m.type==="ArrowFunctionExpression"||m.type==="FunctionExpression")return!0;if(m.type==="CallExpression"&&m.callee){let b=m.callee.name||m.callee.property&&m.callee.property.name;return["memo","forwardRef","lazy","createContext"].includes(b)}return!1},y=m=>{if(!m.init)return!1;let b=m.id.name;if(/^[A-Z]/.test(b)&&n(m.init)||/^[A-Z]/.test(b)&&m.init.type==="MemberExpression"&&m.init.object.type==="Identifier"&&/^[A-Z]/.test(m.init.object.name))return!0;if(/^[A-Z]/.test(b)&&m.init.type==="ConditionalExpression"){let{consequent:v,alternate:w}=m.init,E=$=>$.type==="Identifier"&&/^[A-Z]/.test($.name)||$.type==="Literal"&&typeof $.value=="string"||$.type==="MemberExpression"&&$.object.type==="Identifier"&&/^[A-Z]/.test($.object.name);if(E(v)||E(w))return!0}return!1},p=m=>{if(!m.init)return!1;let b=m.id.name;return b.startsWith("use")&&/^use[A-Z]/.test(b)&&n(m.init)},c=["Icon","Component","FormComponent","Layout","Wrapper","Container","Provider"],a=(m,b)=>{if(m.type==="Identifier"){let v=m.name;if(v.startsWith("_")||s.test(v)||r.includes(v)||c.includes(v))return;I.test(v)||e.report({message:`${b} "${v}" should be camelCase`,node:m})}else m.type==="ObjectPattern"?m.properties.forEach(v=>{v.type==="Property"?a(v.value,b):v.type==="RestElement"&&a(v.argument,b)}):m.type==="ArrayPattern"?m.elements.forEach(v=>{v&&a(v,b)}):m.type==="AssignmentPattern"?a(m.left,b):m.type==="RestElement"&&a(m.argument,b)},u=m=>{if(m.id.type!=="Identifier"){a(m.id,"Variable");return}let b=m.id.name;if(l(m.init)){S.test(b)||e.report({message:`Styled component "${b}" should be PascalCase (e.g., StyledCard instead of styledCard)`,node:m.id});return}if(b.startsWith("_")||y(m))return;let v=["Component","Icon","Layout","Wrapper","Container","Provider","View","Screen","Page"];if(S.test(b)&&v.some(E=>b.endsWith(E)))return;if(p(m)){d.test(b)||e.report({message:`Hook "${b}" should start with "use" followed by PascalCase (e.g., useEventsList)`,node:m.id});return}if(!([/^[A-Z][a-zA-Z]*Data$/,/^[A-Z][a-zA-Z]*Config$/,/^Routes$/].some(E=>E.test(b))&&m.init&&(m.init.type==="ArrayExpression"||m.init.type==="ObjectExpression"||m.init.type==="CallExpression"))&&!I.test(b)){let E=g(b),$=i(m.id);e.report({fix:C=>{let f=[];return $.forEach(h=>{f.push(C.replaceText(h,E))}),f},message:`Variable "${b}" should be camelCase (e.g., ${E} instead of ${b})`,node:m.id})}},T=m=>{if(m.computed||m.key.type!=="Identifier")return;let b=m.key.name;if(!(b.startsWith("_")||r.includes(b))){if(m.value&&m.value.type==="Identifier"){let v=m.value.name;if(S.test(v)&&S.test(b))return}if(!c.includes(b)&&!b.startsWith("Mui")&&!I.test(b)){let v=g(b);e.report({fix:w=>w.replaceText(m.key,v),message:`Property "${b}" should be camelCase (e.g., ${v} instead of ${b})`,node:m.key})}}},x=m=>{m.params.forEach(b=>a(b,"Parameter"))};return{ArrowFunctionExpression:x,CallExpression:m=>{o(m)||m.arguments.forEach(b=>{if(b.type==="Identifier"){let v=b.name;if(v.startsWith("_")||s.test(v)||r.includes(v)||c.includes(v)||S.test(v))return;if(!I.test(v)){let w=g(v);e.report({fix(E){let $=t.getScope?t.getScope(b):e.getScope(),C=$.variables.find(A=>A.name===v)||$.upper&&$.upper.variables.find(A=>A.name===v);if(!C)return E.replaceText(b,w);let f=[],h=new Set;return C.references.forEach(A=>{let L=`${A.identifier.range[0]}-${A.identifier.range[1]}`;h.has(L)||(h.add(L),f.push(E.replaceText(A.identifier,w)))}),f},message:`Argument "${v}" should be camelCase (e.g., ${w} instead of ${v})`,node:b})}}})},FunctionDeclaration:x,FunctionExpression:x,Property:T,VariableDeclarator:u}},meta:{docs:{description:"Enforce naming conventions: camelCase for variables/properties/params/arguments, PascalCase for components, useXxx for hooks"},fixable:"code",schema:[],type:"suggestion"}};var Mn={meta:{name:"eslint-plugin-code-style",version:"2.0.
|
|
276
|
+
`+o),message:"Closing brace must be on its own line",node:y}):e.report({fix:b=>b.insertTextAfter(c,","),message:"Last interface property must have trailing comma",node:c})}}}},meta:{docs:{description:"Enforce interface naming (PascalCase + Interface suffix), camelCase properties, proper formatting, and trailing commas"},fixable:"code",schema:[],type:"suggestion"}},Ut={create(e){let I=(e.filename||e.getFilename()).replace(/\\/g,"/"),S=s=>new RegExp(`/${s}/[^/]+\\.(ts|tsx)$`).test(I),d=()=>/\.(ts|tsx)$/.test(I);return{TSInterfaceDeclaration(s){d()&&(S("interfaces")||e.report({message:'Interfaces must be declared in files inside the "interfaces" folder',node:s.id||s}))},TSEnumDeclaration(s){d()&&(S("enums")||e.report({message:'Enums must be declared in files inside the "enums" folder',node:s.id||s}))},TSTypeAliasDeclaration(s){d()&&(S("types")||e.report({message:'Type aliases must be declared in files inside the "types" folder',node:s.id||s}))}}},meta:{docs:{description:"Enforce that interfaces are in interfaces folder, enums in enums folder, and types in types folder"},schema:[],type:"suggestion"}};var _t={create(e){let t=e.sourceCode||e.getSourceCode(),I=/^[a-z][a-zA-Z0-9]*$/,S=/^[A-Z][a-zA-Z0-9]*$/,d=/^use[A-Z][a-zA-Z0-9]*$/,s=/^[A-Z][A-Z0-9_]*$/,g=m=>/^[A-Z][A-Z0-9_]*$/.test(m)?m.toLowerCase().replace(/_([a-z0-9])/g,(b,v)=>v.toUpperCase()):/_/.test(m)?m.toLowerCase().replace(/_([a-z0-9])/g,(b,v)=>v.toUpperCase()):/^[A-Z]/.test(m)?m[0].toLowerCase()+m.slice(1):m,i=m=>{let v=(t.getScope?t.getScope(m):e.getScope()).variables.find(w=>w.name===m.name);return v?v.references.map(w=>w.identifier):[]},r=["ArrowFunctionExpression","CallExpression","FunctionDeclaration","FunctionExpression","Property","VariableDeclarator","JSXElement","JSXOpeningElement","ReturnStatement","SwitchCase","SwitchStatement","ObjectExpression","ObjectPattern","BlockStatement","IfStatement","Identifier","RestElement","AssignmentPattern","ArrayPattern","MemberExpression","JSXText","JSXAttribute","JSXExpressionContainer","Function","Object","Array","String","Number","Boolean","Symbol","BigInt","Date","RegExp","Error","Map","Set","WeakMap","WeakSet","Promise"],l=m=>{if(!m||m.type!=="CallExpression")return!1;let{callee:b}=m;if(b.type==="CallExpression"){let v=b.callee;if(v.type==="Identifier"&&v.name==="styled"||v.type==="MemberExpression"&&v.object.name==="styled")return!0}return!1},o=m=>{if(m.type!=="CallExpression")return!1;let{callee:b}=m;return b.type==="Identifier"&&b.name==="styled"},n=m=>{if(!m)return!1;if(m.type==="ArrowFunctionExpression"||m.type==="FunctionExpression")return!0;if(m.type==="CallExpression"&&m.callee){let b=m.callee.name||m.callee.property&&m.callee.property.name;return["memo","forwardRef","lazy","createContext"].includes(b)}return!1},y=m=>{if(!m.init)return!1;let b=m.id.name;if(/^[A-Z]/.test(b)&&n(m.init)||/^[A-Z]/.test(b)&&m.init.type==="MemberExpression"&&m.init.object.type==="Identifier"&&/^[A-Z]/.test(m.init.object.name))return!0;if(/^[A-Z]/.test(b)&&m.init.type==="ConditionalExpression"){let{consequent:v,alternate:w}=m.init,E=$=>$.type==="Identifier"&&/^[A-Z]/.test($.name)||$.type==="Literal"&&typeof $.value=="string"||$.type==="MemberExpression"&&$.object.type==="Identifier"&&/^[A-Z]/.test($.object.name);if(E(v)||E(w))return!0}return!1},p=m=>{if(!m.init)return!1;let b=m.id.name;return b.startsWith("use")&&/^use[A-Z]/.test(b)&&n(m.init)},c=["Icon","Component","FormComponent","Layout","Wrapper","Container","Provider"],a=(m,b)=>{if(m.type==="Identifier"){let v=m.name;if(v.startsWith("_")||s.test(v)||r.includes(v)||c.includes(v))return;I.test(v)||e.report({message:`${b} "${v}" should be camelCase`,node:m})}else m.type==="ObjectPattern"?m.properties.forEach(v=>{v.type==="Property"?a(v.value,b):v.type==="RestElement"&&a(v.argument,b)}):m.type==="ArrayPattern"?m.elements.forEach(v=>{v&&a(v,b)}):m.type==="AssignmentPattern"?a(m.left,b):m.type==="RestElement"&&a(m.argument,b)},u=m=>{if(m.id.type!=="Identifier"){a(m.id,"Variable");return}let b=m.id.name;if(l(m.init)){S.test(b)||e.report({message:`Styled component "${b}" should be PascalCase (e.g., StyledCard instead of styledCard)`,node:m.id});return}if(b.startsWith("_")||y(m))return;let v=["Component","Icon","Layout","Wrapper","Container","Provider","View","Screen","Page"];if(S.test(b)&&v.some(E=>b.endsWith(E)))return;if(p(m)){d.test(b)||e.report({message:`Hook "${b}" should start with "use" followed by PascalCase (e.g., useEventsList)`,node:m.id});return}if(!([/^[A-Z][a-zA-Z]*Data$/,/^[A-Z][a-zA-Z]*Config$/,/^Routes$/].some(E=>E.test(b))&&m.init&&(m.init.type==="ArrayExpression"||m.init.type==="ObjectExpression"||m.init.type==="CallExpression"))&&!I.test(b)){let E=g(b),$=i(m.id);e.report({fix:C=>{let f=[];return $.forEach(h=>{f.push(C.replaceText(h,E))}),f},message:`Variable "${b}" should be camelCase (e.g., ${E} instead of ${b})`,node:m.id})}},T=m=>{if(m.computed||m.key.type!=="Identifier")return;let b=m.key.name;if(!(b.startsWith("_")||r.includes(b))){if(m.value&&m.value.type==="Identifier"){let v=m.value.name;if(S.test(v)&&S.test(b))return}if(!c.includes(b)&&!b.startsWith("Mui")&&!I.test(b)){let v=g(b);e.report({fix:w=>w.replaceText(m.key,v),message:`Property "${b}" should be camelCase (e.g., ${v} instead of ${b})`,node:m.key})}}},x=m=>{m.params.forEach(b=>a(b,"Parameter"))};return{ArrowFunctionExpression:x,CallExpression:m=>{o(m)||m.arguments.forEach(b=>{if(b.type==="Identifier"){let v=b.name;if(v.startsWith("_")||s.test(v)||r.includes(v)||c.includes(v)||S.test(v))return;if(!I.test(v)){let w=g(v);e.report({fix(E){let $=t.getScope?t.getScope(b):e.getScope(),C=$.variables.find(A=>A.name===v)||$.upper&&$.upper.variables.find(A=>A.name===v);if(!C)return E.replaceText(b,w);let f=[],h=new Set;return C.references.forEach(A=>{let L=`${A.identifier.range[0]}-${A.identifier.range[1]}`;h.has(L)||(h.add(L),f.push(E.replaceText(A.identifier,w)))}),f},message:`Argument "${v}" should be camelCase (e.g., ${w} instead of ${v})`,node:b})}}})},FunctionDeclaration:x,FunctionExpression:x,Property:T,VariableDeclarator:u}},meta:{docs:{description:"Enforce naming conventions: camelCase for variables/properties/params/arguments, PascalCase for components, useXxx for hooks"},fixable:"code",schema:[],type:"suggestion"}};var Mn={meta:{name:"eslint-plugin-code-style",version:"2.0.8"},rules:{"array-callback-destructure":Se,"array-items-per-line":Ee,"array-objects-on-new-lines":we,"arrow-function-block-body":ve,"arrow-function-simple-jsx":Ce,"arrow-function-simplify":Ae,"curried-arrow-same-line":$e,"function-arguments-format":Ie,"nested-call-closing-brackets":Le,"no-empty-lines-in-function-calls":Re,"opening-brackets-same-line":Pe,"simple-call-single-line":Fe,"single-argument-on-one-line":Be,"comment-format":Oe,"component-props-destructure":Ne,"component-props-inline-type":De,"folder-based-naming-convention":Xe,"folder-structure-consistency":ze,"no-redundant-folder-suffix":We,"svg-icon-naming-convention":Je,"react-code-order":Ht,"block-statement-newlines":Ve,"empty-line-after-block":Ge,"if-else-spacing":_e,"if-statement-format":Ue,"logical-expression-multiline":Ke,"multiline-if-conditions":qe,"no-empty-lines-in-switch-cases":Ye,"ternary-condition-multiline":Ze,"class-method-definition-format":je,"class-naming-convention":He,"function-call-spacing":Qe,"function-declaration-style":et,"function-naming-convention":tt,"function-object-destructure":st,"function-params-per-line":nt,"no-empty-lines-in-function-params":rt,"hook-callback-format":it,"hook-deps-per-line":at,"use-state-naming-convention":ot,"absolute-imports-only":lt,"export-format":ct,"import-format":pt,"import-source-spacing":ft,"index-export-style":gt,"index-exports-only":mt,"inline-export-declaration":dt,"module-index-exports":ut,"classname-dynamic-at-end":St,"classname-multiline":Ct,"classname-no-extra-spaces":wt,"classname-order":vt,"jsx-children-on-new-line":yt,"jsx-closing-bracket-spacing":ht,"jsx-element-child-new-line":xt,"jsx-logical-expression-simplify":Tt,"jsx-parentheses-position":bt,"jsx-prop-naming-convention":kt,"jsx-simple-element-one-line":Et,"jsx-string-value-trim":At,"jsx-ternary-format":$t,"no-empty-lines-in-jsx":It,"no-empty-lines-in-objects":Lt,"object-property-per-line":Rt,"object-property-value-brace":Pt,"object-property-value-format":Ft,"string-property-spacing":Bt,"assignment-value-same-line":jt,"member-expression-bracket-spacing":Ot,"enum-format":Wt,"enum-type-enforcement":Nt,"interface-format":Vt,"no-inline-type-definitions":Jt,"prop-naming-convention":Dt,"type-annotation-spacing":zt,"type-format":Xt,"typescript-definition-location":Ut,"no-hardcoded-strings":Mt,"variable-naming-convention":_t}};export{Mn as default};
|
package/package.json
CHANGED