@nfq/eslint-config 4.0.0-beta.10 → 4.0.0-beta.12

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.
@@ -144,7 +144,7 @@ const componentFileStructure = createRule$b({
144
144
  if (isComponentExport(statement, componentName) || isDefaultComponentExport(statement, componentName)) {
145
145
  return 6;
146
146
  }
147
- if (isPageComponent && isNonPropsTypeDeclaration(statement) && statement.range[0] < componentInfo.statement.range[0]) {
147
+ if (isNonPropsTypeDeclaration(statement) && statement.range[0] < componentInfo.statement.range[0]) {
148
148
  return 2;
149
149
  }
150
150
  if (isStyledDeclaration(statement) || isStyledFactoryDeclaration(statement) || isNonPropsTypeDeclaration(statement)) {
@@ -1 +1 @@
1
- {"version":3,"file":"component-file-structure.js","sources":["../../../../src/rules/custom/component-file-structure.ts"],"sourcesContent":["import {ESLintUtils} from '@typescript-eslint/utils';\n\nimport {\n collectTypeReferences,\n getComponentInfoFromStatement,\n getTypeDeclarationInfo,\n isComponentExport,\n isDefaultComponentExport,\n isDisplayNameAssignment,\n isStyledDeclaration,\n isStyledFactoryDeclaration\n} from './utils/component-file-structure-utils';\n\nimport type {ComponentInfo} from './utils/component-file-structure-utils';\nimport type {TSESLint, TSESTree} from '@typescript-eslint/utils';\n\nconst createRule = ESLintUtils.RuleCreator(\n name => `https://github.com/nfqde/eslint-config-nfq/blob/master/docs/rules/${name}.md`\n);\n\ntype MessageIds = 'invalidOrder' | 'missingDisplayName' | 'missingNamedExport';\n\nconst ORDER_LABELS = [\n 'Imports',\n 'Optional declarations',\n 'Props types',\n 'Component',\n 'Component helpers and displayName',\n 'Exports',\n 'Styled components and local helper types'\n];\nconst ORDER_MESSAGE = ORDER_LABELS.join(' -> ');\n// eslint-disable-next-line jsdoc/require-jsdoc\nconst getSectionLabel = (section: number) => ORDER_LABELS[section - 1] ?? 'Unknown';\nconst PAGE_TYPE_NAMES = new Set([\n 'NextPage',\n 'NextPageWithLayout',\n 'NextSSRPage',\n 'NextSSRPageWithLayout',\n 'NextSSGPageWithLayout'\n]);\n\nexport const componentFileStructure = createRule<[], MessageIds>({\n defaultOptions: [],\n meta: {\n docs: {description: 'Enforce file structure order for React component files.'},\n messages: {\n // eslint-disable-next-line @stylistic/max-len\n invalidOrder: 'This file structure block is out of order. {{currentName}} is a {{current}} and should be before {{previousName}}. Expected order: {{order}}.',\n missingDisplayName: 'Component {{name}} must set displayName.',\n missingNamedExport: 'Component {{name}} must be exported by name.'\n },\n schema: [],\n type: 'suggestion'\n },\n name: 'component-file-structure',\n /**\n * Creates the rule listener for enforcing component file structure ordering. It analyzes the program body to\n * identify the primary component, its props types, and structural sections. It then reports ordering issues and\n * missing requirements like displayName or named exports.\n *\n * @param context The ESLint rule context used to access source code and report diagnostics.\n * @returns A rule listener that validates component file structure and reports issues.\n *\n * @example\n * ```tsx\n * // eslint-disable-next-line @nfq/component-file-structure\n * const listener = componentFileStructure.create(context);\n * ```\n */\n // eslint-disable-next-line max-lines-per-function\n create(context) {\n const {sourceCode} = context;\n const programBody = sourceCode.ast.body;\n const componentCandidates = programBody\n .filter((statement): statement is TSESTree.Statement => statement.type !== 'TSModuleDeclaration')\n .map(statement => getComponentInfoFromStatement(statement))\n .filter((info): info is ComponentInfo => Boolean(info));\n\n if (componentCandidates.length === 0) {\n return {};\n }\n\n const componentInfo = componentCandidates.sort(\n (left, right) => left.statement.range[0] - right.statement.range[0]\n )[0];\n const componentName = componentInfo.name;\n const typeDeclarations = new Map<string, TSESTree.Node>();\n\n for (const statement of programBody) {\n const info = getTypeDeclarationInfo(statement as TSESTree.Statement);\n\n if (info) {\n typeDeclarations.set(info.name, info.statement);\n }\n }\n\n const propsTypeNames = new Set<string>();\n const propsTypeRefs = new Set<string>();\n const propsTypeNode = componentInfo.propsTypeNode ?? null;\n /**\n * Determines whether the component uses a page-specific type alias. It inspects the component type node\n * and collects all referenced type names. It then checks if any of those names match known page types to\n * decide if the component is a page component.\n *\n * @returns True when the component type includes a known page type; otherwise false.\n *\n * @example\n * ```tsx\n * const isPage = isPageType();\n * ```\n */\n const isPageType = () => {\n const typeNode = componentInfo.componentTypeNode ?? null;\n\n if (!typeNode) {\n return false;\n }\n\n const typeRefs = new Set<string>();\n\n collectTypeReferences(typeNode, typeRefs);\n\n return Array.from(typeRefs).some(name => PAGE_TYPE_NAMES.has(name));\n };\n\n /**\n * Checks whether a statement assigns a page layout helper to the component. It ensures the statement is\n * an assignment expression targeting a member of the component identifier. It then verifies the member name\n * matches supported layout assignment properties.\n *\n * @param statement The statement to inspect for a layout assignment.\n * @returns True when the statement assigns a layout helper on the component; otherwise false.\n *\n * @example\n * ```tsx\n * const hasLayout = isPageLayoutAssignment(statement);\n * ```\n */\n const isPageLayoutAssignment = (statement: TSESTree.Statement) => {\n if (statement.type !== 'ExpressionStatement') {\n return false;\n }\n\n const {expression} = statement;\n\n if (expression.type !== 'AssignmentExpression') {\n return false;\n }\n\n const {left} = expression;\n\n if (left.type !== 'MemberExpression' || left.object.type !== 'Identifier') {\n return false;\n }\n\n if (left.object.name !== componentName || left.property.type !== 'Identifier') {\n return false;\n }\n\n return left.property.name === 'getLayout' || left.property.name === 'getLayoutKey';\n };\n\n const hasDefaultExport = programBody\n .some(statement => isDefaultComponentExport(statement as TSESTree.Statement, componentName));\n const hasLayoutAssignment = programBody\n .some(statement => isPageLayoutAssignment(statement as TSESTree.Statement));\n const isPageComponent = hasDefaultExport && (hasLayoutAssignment || isPageType());\n\n /**\n * Determines whether a class element represents a static displayName member. It checks that the element is a supported\n * property definition shape and that it is declared as static. It then verifies the identifier name matches the expected\n * displayName property, which signals a static display name assignment on a class.\n *\n * @returns True when the element is a static displayName property; otherwise false.\n *\n * @example\n * ```tsx\n * const isDisplayName = hasDisplayNameMember(member);\n * ```\n */\n const hasStaticDisplayName = () => {\n /**\n * Determines whether a class element represents a static displayName member. It checks that the element is a supported\n * property definition shape and that it is declared as static. It then verifies the identifier name matches the expected\n * displayName property, which signals a static display name assignment on a class.\n *\n * @param member The class element to inspect for a static displayName property.\n * @returns True when the element is a static displayName property; otherwise false.\n *\n * @example\n * ```tsx\n * const isDisplayName = hasDisplayNameMember(member);\n * ```\n */\n const hasDisplayNameMember = (member: TSESTree.ClassElement) => {\n // @ts-expect-error\n if (member.type !== 'PropertyDefinition' && member.type !== 'ClassProperty') {\n return false;\n }\n\n if (!member.static || member.key.type !== 'Identifier') {\n return false;\n }\n\n return member.key.name === 'displayName';\n };\n\n if (componentInfo.statement.type === 'ClassDeclaration') {\n return componentInfo.statement.id?.name === componentName\n && componentInfo.statement.body.body.some(hasDisplayNameMember);\n }\n\n if (componentInfo.statement.type === 'VariableDeclaration') {\n for (const declarator of componentInfo.statement.declarations) {\n if (declarator.id.type !== 'Identifier' || declarator.id.name !== componentName) {\n continue;\n }\n\n const {init} = declarator;\n\n if (init?.type === 'ClassExpression') {\n return init.body.body.some(hasDisplayNameMember);\n }\n }\n }\n\n return false;\n };\n\n if (propsTypeNode) {\n collectTypeReferences(propsTypeNode, propsTypeRefs);\n\n for (const name of propsTypeRefs) {\n if (typeDeclarations.has(name)) {\n propsTypeNames.add(name);\n }\n }\n }\n\n /**\n * Determines whether a statement declares a type that is used as the component props. It inspects the statement\n * for a type declaration and compares the declared name against the collected props type names. It returns a\n * boolean so callers can classify statements into the props type section.\n *\n * @param statement The statement to inspect for a props type declaration.\n * @returns True when the statement declares a props type; otherwise false.\n *\n * @example\n * ```tsx\n * const isProps = isPropsTypeDeclaration(statement);\n * ```\n */\n const isPropsTypeDeclaration = (statement: TSESTree.Statement) => {\n const info = getTypeDeclarationInfo(statement);\n\n return Boolean(info && propsTypeNames.has(info.name));\n };\n\n /**\n * Determines whether a statement declares a type that is not used as the component props. It inspects the\n * statement for a type declaration and ensures the declared name is not among the collected props type names.\n * It returns a boolean so callers can classify statements into non-props type sections.\n *\n * @param statement The statement to inspect for a non-props type declaration.\n * @returns True when the statement declares a non-props type; otherwise false.\n *\n * @example\n * ```tsx\n * const isNonProps = isNonPropsTypeDeclaration(statement);\n * ```\n */\n const isNonPropsTypeDeclaration = (statement: TSESTree.Statement) => {\n const info = getTypeDeclarationInfo(statement);\n\n return Boolean(info && !propsTypeNames.has(info.name));\n };\n\n /**\n * Determines whether a statement is an optional variable-like declaration in the component file structure. It\n * filters out the main component statement and styled declarations to avoid misclassification. It considers\n * variable declarations, non-component function declarations, and enum declarations as optional declarations.\n *\n * @param statement The statement to evaluate for optional declaration status.\n * @returns True when the statement should be treated as an optional declaration; otherwise false.\n *\n * @example\n * ```tsx\n * const isOptional = isOptionalVarDeclaration(statement);\n * ```\n */\n const isOptionalVarDeclaration = (statement: TSESTree.Statement) => {\n if (statement.type === 'VariableDeclaration') {\n if (\n statement === componentInfo.statement\n || isStyledDeclaration(statement)\n || isStyledFactoryDeclaration(statement)\n ) {\n return false;\n }\n\n return true;\n }\n\n if (statement.type === 'FunctionDeclaration') {\n return statement !== componentInfo.statement;\n }\n\n return statement.type === 'TSEnumDeclaration';\n };\n\n /**\n * Determines the structural section number for a given statement in a component file. It checks the statement\n * against known component structure elements like imports, the main component, displayName assignment, exports,\n * styled declarations, optional declarations, and props types. It returns a numeric section marker to help\n * enforce ordering rules or null when the statement does not belong to a tracked section.\n *\n * @param statement The statement to classify within the component file structure.\n * @returns The numeric section identifier for the statement, or null when it does not match a section.\n *\n * @example\n * ```tsx\n * const section = sectionForStatement(statement);\n * ```\n */\n const sectionForStatement = (statement: TSESTree.Statement) => {\n if (statement.type === 'ImportDeclaration') {\n return 1;\n }\n\n if (statement === componentInfo.statement) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 4;\n }\n\n if (isDisplayNameAssignment(statement, componentName)) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 5;\n }\n\n if (\n isComponentExport(statement, componentName)\n || isDefaultComponentExport(statement, componentName)\n ) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 6;\n }\n\n if (\n isPageComponent\n && isNonPropsTypeDeclaration(statement)\n && statement.range[0] < componentInfo.statement.range[0]\n ) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 2;\n }\n\n if (\n isStyledDeclaration(statement)\n || isStyledFactoryDeclaration(statement)\n || isNonPropsTypeDeclaration(statement)\n ) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 7;\n }\n\n if (isOptionalVarDeclaration(statement)) {\n if (statement.range[0] > componentInfo.statement.range[0]) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 5;\n }\n\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 2;\n }\n\n if (isPropsTypeDeclaration(statement)) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 3;\n }\n\n return null;\n };\n\n /**\n * Determines a human-readable label for a statement within the component file structure. It inspects the statement\n * type and section to produce a meaningful name for reporting order violations. It also handles special cases like\n * displayName assignments and exports so diagnostics are clear and actionable.\n *\n * @param statement The statement to derive a label for.\n * @param section The section number associated with the statement.\n * @returns A descriptive name for the statement within its section.\n *\n * @example\n * ```tsx\n * const name = getStatementName(statement, 4);\n * ```\n */\n const getStatementName = (statement: TSESTree.Statement, section: number) => {\n // eslint-disable-next-line @nfq/no-magic-numbers\n if (section === 4) {\n return componentName;\n }\n\n // eslint-disable-next-line @nfq/no-magic-numbers\n if (section === 5 && isDisplayNameAssignment(statement, componentName)) {\n return `${componentName}.displayName`;\n }\n\n if (statement.type === 'VariableDeclaration') {\n const first = statement.declarations[0];\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (first?.id.type === 'Identifier') {\n return first.id.name;\n }\n }\n\n if (statement.type === 'FunctionDeclaration' || statement.type === 'ClassDeclaration') {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return statement.id?.name ?? getSectionLabel(section);\n }\n\n if (statement.type === 'ExportDefaultDeclaration') {\n const {declaration} = statement;\n\n if (declaration.type === 'Identifier') {\n return `export default ${declaration.name}`;\n }\n\n if (declaration.type === 'ClassDeclaration' || declaration.type === 'FunctionDeclaration') {\n if (declaration.id?.name) {\n return `export default ${declaration.id.name}`;\n }\n }\n\n return 'export default';\n }\n\n if (statement.type === 'ExportNamedDeclaration') {\n const names = statement.specifiers\n .filter(specifier => specifier.local.type === 'Identifier')\n // @ts-expect-error\n .map(specifier => specifier.local.name as string);\n\n if (names.length === 1) {\n return `export {${names[0]}}`;\n }\n\n if (names.length > 1) {\n return 'export {...}';\n }\n }\n\n return getSectionLabel(section);\n };\n\n return {\n /**\n * Iterates over the program body statements to validate their order based on the defined component file structure. It\n * tracks the last seen section and reports any statement that appears in an earlier section than the last one. It also checks\n * for the presence of a displayName assignment and a named export for the component, reporting if either is missing.\n * This ensures that the component file adheres to the expected structure and includes necessary metadata for better maintainability and clarity.\n *\n * @example\n * ```tsx\n * Program();\n * ```\n */\n Program() {\n let lastSection = 0;\n let lastSectionName = '';\n let hasDisplayName = hasStaticDisplayName();\n let hasNamedExport = false;\n\n for (const statement of programBody) {\n const section = sectionForStatement(statement as TSESTree.Statement);\n\n // eslint-disable-next-line @nfq/no-magic-numbers\n if (section === 5) {\n hasDisplayName = true;\n }\n\n // eslint-disable-next-line @nfq/no-magic-numbers\n if (section === 6) {\n hasNamedExport = true;\n }\n\n if (!section) {\n continue;\n }\n\n if (section < lastSection) {\n context.report({\n data: {\n current: getSectionLabel(section),\n currentName: getStatementName(statement as TSESTree.Statement, section),\n order: ORDER_MESSAGE,\n previous: getSectionLabel(lastSection),\n previousName: lastSectionName || getSectionLabel(lastSection)\n },\n messageId: 'invalidOrder',\n node: statement\n });\n } else {\n lastSection = section;\n lastSectionName = getStatementName(statement as TSESTree.Statement, section);\n }\n }\n\n if (!hasDisplayName && !isPageComponent) {\n context.report({\n data: {name: componentName},\n messageId: 'missingDisplayName',\n node: componentInfo.statement\n });\n }\n\n if (!hasNamedExport && !isPageComponent) {\n context.report({\n data: {name: componentName},\n messageId: 'missingNamedExport',\n node: componentInfo.statement\n });\n }\n }\n } as TSESLint.RuleListener;\n }\n});"],"names":["createRule","ESLintUtils","RuleCreator","name","ORDER_LABELS","ORDER_MESSAGE","join","getSectionLabel","section","PAGE_TYPE_NAMES","Set","componentFileStructure","defaultOptions","meta","docs","description","messages","invalidOrder","missingDisplayName","missingNamedExport","schema","type","create","context","sourceCode","programBody","ast","body","componentCandidates","filter","statement","map","getComponentInfoFromStatement","info","Boolean","length","componentInfo","sort","left","right","range","componentName","typeDeclarations","Map","getTypeDeclarationInfo","set","propsTypeNames","propsTypeRefs","propsTypeNode","isPageType","typeNode","componentTypeNode","typeRefs","collectTypeReferences","Array","from","some","has","isPageLayoutAssignment","expression","object","property","hasDefaultExport","isDefaultComponentExport","hasLayoutAssignment","isPageComponent","hasStaticDisplayName","hasDisplayNameMember","member","static","key","id","declarator","declarations","init","add","isPropsTypeDeclaration","isNonPropsTypeDeclaration","isOptionalVarDeclaration","isStyledDeclaration","isStyledFactoryDeclaration","sectionForStatement","isDisplayNameAssignment","isComponentExport","getStatementName","first","declaration","names","specifiers","specifier","local","Program","lastSection","lastSectionName","hasDisplayName","hasNamedExport","report","data","current","currentName","order","previous","previousName","messageId","node"],"mappings":";;;AAgBA,MAAMA,YAAU,GAAGC,WAAW,CAACC,WAAW,CACtCC,IAAI,IAAI,CAAA,kEAAA,EAAqEA,IAAI,CAAA,GAAA,CACrF,CAAC;AAID,MAAMC,YAAY,GAAG,CACjB,SAAS,EACT,uBAAuB,EACvB,aAAa,EACb,WAAW,EACX,mCAAmC,EACnC,SAAS,EACT,0CAA0C,CAC7C;AACD,MAAMC,aAAa,GAAGD,YAAY,CAACE,IAAI,CAAC,MAAM,CAAC;AAE/C,MAAMC,eAAe,GAAIC,OAAe,IAAKJ,YAAY,CAACI,OAAO,GAAG,CAAC,CAAC,IAAI,SAAS;AACnF,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAAC,CAC5B,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,uBAAuB,CAC1B,CAAC;AAEK,MAAMC,sBAAsB,GAAGX,YAAU,CAAiB;AAC7DY,EAAAA,cAAc,EA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e,EAAE;UACrC1C,OAAO,CAACyE,MAAM,CAAC;AACXC,YAAAA,IAAI,EAAE;AAAC9F,cAAAA,IAAI,EAAEsC;aAAc;AAC3B8D,YAAAA,SAAS,EAAE,oBAAoB;YAC/BC,IAAI,EAAEpE,aAAa,CAACN;AACxB,WAAC,CAAC;AACN,QAAA;AAEA,QAAA,IAAI,CAACiE,cAAc,IAAI,CAAC9B,eAAe,EAAE;UACrC1C,OAAO,CAACyE,MAAM,CAAC;AACXC,YAAAA,IAAI,EAAE;AAAC9F,cAAAA,IAAI,EAAEsC;aAAc;AAC3B8D,YAAAA,SAAS,EAAE,oBAAoB;YAC/BC,IAAI,EAAEpE,aAAa,CAACN;AACxB,WAAC,CAAC;AACN,QAAA;AACJ,MAAA;KACH;AACL,EAAA;AACJ,CAAC;;;;"}
1
+ {"version":3,"file":"component-file-structure.js","sources":["../../../../src/rules/custom/component-file-structure.ts"],"sourcesContent":["import {ESLintUtils} from '@typescript-eslint/utils';\n\nimport {\n collectTypeReferences,\n getComponentInfoFromStatement,\n getTypeDeclarationInfo,\n isComponentExport,\n isDefaultComponentExport,\n isDisplayNameAssignment,\n isStyledDeclaration,\n isStyledFactoryDeclaration\n} from './utils/component-file-structure-utils';\n\nimport type {ComponentInfo} from './utils/component-file-structure-utils';\nimport type {TSESLint, TSESTree} from '@typescript-eslint/utils';\n\nconst createRule = ESLintUtils.RuleCreator(\n name => `https://github.com/nfqde/eslint-config-nfq/blob/master/docs/rules/${name}.md`\n);\n\ntype MessageIds = 'invalidOrder' | 'missingDisplayName' | 'missingNamedExport';\n\nconst ORDER_LABELS = [\n 'Imports',\n 'Optional declarations',\n 'Props types',\n 'Component',\n 'Component helpers and displayName',\n 'Exports',\n 'Styled components and local helper types'\n];\nconst ORDER_MESSAGE = ORDER_LABELS.join(' -> ');\n// eslint-disable-next-line jsdoc/require-jsdoc\nconst getSectionLabel = (section: number) => ORDER_LABELS[section - 1] ?? 'Unknown';\nconst PAGE_TYPE_NAMES = new Set([\n 'NextPage',\n 'NextPageWithLayout',\n 'NextSSRPage',\n 'NextSSRPageWithLayout',\n 'NextSSGPageWithLayout'\n]);\n\nexport const componentFileStructure = createRule<[], MessageIds>({\n defaultOptions: [],\n meta: {\n docs: {description: 'Enforce file structure order for React component files.'},\n messages: {\n // eslint-disable-next-line @stylistic/max-len\n invalidOrder: 'This file structure block is out of order. {{currentName}} is a {{current}} and should be before {{previousName}}. Expected order: {{order}}.',\n missingDisplayName: 'Component {{name}} must set displayName.',\n missingNamedExport: 'Component {{name}} must be exported by name.'\n },\n schema: [],\n type: 'suggestion'\n },\n name: 'component-file-structure',\n /**\n * Creates the rule listener for enforcing component file structure ordering. It analyzes the program body to\n * identify the primary component, its props types, and structural sections. It then reports ordering issues and\n * missing requirements like displayName or named exports.\n *\n * @param context The ESLint rule context used to access source code and report diagnostics.\n * @returns A rule listener that validates component file structure and reports issues.\n *\n * @example\n * ```tsx\n * // eslint-disable-next-line @nfq/component-file-structure\n * const listener = componentFileStructure.create(context);\n * ```\n */\n // eslint-disable-next-line max-lines-per-function\n create(context) {\n const {sourceCode} = context;\n const programBody = sourceCode.ast.body;\n const componentCandidates = programBody\n .filter((statement): statement is TSESTree.Statement => statement.type !== 'TSModuleDeclaration')\n .map(statement => getComponentInfoFromStatement(statement))\n .filter((info): info is ComponentInfo => Boolean(info));\n\n if (componentCandidates.length === 0) {\n return {};\n }\n\n const componentInfo = componentCandidates.sort(\n (left, right) => left.statement.range[0] - right.statement.range[0]\n )[0];\n const componentName = componentInfo.name;\n const typeDeclarations = new Map<string, TSESTree.Node>();\n\n for (const statement of programBody) {\n const info = getTypeDeclarationInfo(statement as TSESTree.Statement);\n\n if (info) {\n typeDeclarations.set(info.name, info.statement);\n }\n }\n\n const propsTypeNames = new Set<string>();\n const propsTypeRefs = new Set<string>();\n const propsTypeNode = componentInfo.propsTypeNode ?? null;\n /**\n * Determines whether the component uses a page-specific type alias. It inspects the component type node\n * and collects all referenced type names. It then checks if any of those names match known page types to\n * decide if the component is a page component.\n *\n * @returns True when the component type includes a known page type; otherwise false.\n *\n * @example\n * ```tsx\n * const isPage = isPageType();\n * ```\n */\n const isPageType = () => {\n const typeNode = componentInfo.componentTypeNode ?? null;\n\n if (!typeNode) {\n return false;\n }\n\n const typeRefs = new Set<string>();\n\n collectTypeReferences(typeNode, typeRefs);\n\n return Array.from(typeRefs).some(name => PAGE_TYPE_NAMES.has(name));\n };\n\n /**\n * Checks whether a statement assigns a page layout helper to the component. It ensures the statement is\n * an assignment expression targeting a member of the component identifier. It then verifies the member name\n * matches supported layout assignment properties.\n *\n * @param statement The statement to inspect for a layout assignment.\n * @returns True when the statement assigns a layout helper on the component; otherwise false.\n *\n * @example\n * ```tsx\n * const hasLayout = isPageLayoutAssignment(statement);\n * ```\n */\n const isPageLayoutAssignment = (statement: TSESTree.Statement) => {\n if (statement.type !== 'ExpressionStatement') {\n return false;\n }\n\n const {expression} = statement;\n\n if (expression.type !== 'AssignmentExpression') {\n return false;\n }\n\n const {left} = expression;\n\n if (left.type !== 'MemberExpression' || left.object.type !== 'Identifier') {\n return false;\n }\n\n if (left.object.name !== componentName || left.property.type !== 'Identifier') {\n return false;\n }\n\n return left.property.name === 'getLayout' || left.property.name === 'getLayoutKey';\n };\n\n const hasDefaultExport = programBody\n .some(statement => isDefaultComponentExport(statement as TSESTree.Statement, componentName));\n const hasLayoutAssignment = programBody\n .some(statement => isPageLayoutAssignment(statement as TSESTree.Statement));\n const isPageComponent = hasDefaultExport && (hasLayoutAssignment || isPageType());\n\n /**\n * Determines whether a class element represents a static displayName member. It checks that the element is a supported\n * property definition shape and that it is declared as static. It then verifies the identifier name matches the expected\n * displayName property, which signals a static display name assignment on a class.\n *\n * @returns True when the element is a static displayName property; otherwise false.\n *\n * @example\n * ```tsx\n * const isDisplayName = hasDisplayNameMember(member);\n * ```\n */\n const hasStaticDisplayName = () => {\n /**\n * Determines whether a class element represents a static displayName member. It checks that the element is a supported\n * property definition shape and that it is declared as static. It then verifies the identifier name matches the expected\n * displayName property, which signals a static display name assignment on a class.\n *\n * @param member The class element to inspect for a static displayName property.\n * @returns True when the element is a static displayName property; otherwise false.\n *\n * @example\n * ```tsx\n * const isDisplayName = hasDisplayNameMember(member);\n * ```\n */\n const hasDisplayNameMember = (member: TSESTree.ClassElement) => {\n // @ts-expect-error\n if (member.type !== 'PropertyDefinition' && member.type !== 'ClassProperty') {\n return false;\n }\n\n if (!member.static || member.key.type !== 'Identifier') {\n return false;\n }\n\n return member.key.name === 'displayName';\n };\n\n if (componentInfo.statement.type === 'ClassDeclaration') {\n return componentInfo.statement.id?.name === componentName\n && componentInfo.statement.body.body.some(hasDisplayNameMember);\n }\n\n if (componentInfo.statement.type === 'VariableDeclaration') {\n for (const declarator of componentInfo.statement.declarations) {\n if (declarator.id.type !== 'Identifier' || declarator.id.name !== componentName) {\n continue;\n }\n\n const {init} = declarator;\n\n if (init?.type === 'ClassExpression') {\n return init.body.body.some(hasDisplayNameMember);\n }\n }\n }\n\n return false;\n };\n\n if (propsTypeNode) {\n collectTypeReferences(propsTypeNode, propsTypeRefs);\n\n for (const name of propsTypeRefs) {\n if (typeDeclarations.has(name)) {\n propsTypeNames.add(name);\n }\n }\n }\n\n /**\n * Determines whether a statement declares a type that is used as the component props. It inspects the statement\n * for a type declaration and compares the declared name against the collected props type names. It returns a\n * boolean so callers can classify statements into the props type section.\n *\n * @param statement The statement to inspect for a props type declaration.\n * @returns True when the statement declares a props type; otherwise false.\n *\n * @example\n * ```tsx\n * const isProps = isPropsTypeDeclaration(statement);\n * ```\n */\n const isPropsTypeDeclaration = (statement: TSESTree.Statement) => {\n const info = getTypeDeclarationInfo(statement);\n\n return Boolean(info && propsTypeNames.has(info.name));\n };\n\n /**\n * Determines whether a statement declares a type that is not used as the component props. It inspects the\n * statement for a type declaration and ensures the declared name is not among the collected props type names.\n * It returns a boolean so callers can classify statements into non-props type sections.\n *\n * @param statement The statement to inspect for a non-props type declaration.\n * @returns True when the statement declares a non-props type; otherwise false.\n *\n * @example\n * ```tsx\n * const isNonProps = isNonPropsTypeDeclaration(statement);\n * ```\n */\n const isNonPropsTypeDeclaration = (statement: TSESTree.Statement) => {\n const info = getTypeDeclarationInfo(statement);\n\n return Boolean(info && !propsTypeNames.has(info.name));\n };\n\n /**\n * Determines whether a statement is an optional variable-like declaration in the component file structure. It\n * filters out the main component statement and styled declarations to avoid misclassification. It considers\n * variable declarations, non-component function declarations, and enum declarations as optional declarations.\n *\n * @param statement The statement to evaluate for optional declaration status.\n * @returns True when the statement should be treated as an optional declaration; otherwise false.\n *\n * @example\n * ```tsx\n * const isOptional = isOptionalVarDeclaration(statement);\n * ```\n */\n const isOptionalVarDeclaration = (statement: TSESTree.Statement) => {\n if (statement.type === 'VariableDeclaration') {\n if (\n statement === componentInfo.statement\n || isStyledDeclaration(statement)\n || isStyledFactoryDeclaration(statement)\n ) {\n return false;\n }\n\n return true;\n }\n\n if (statement.type === 'FunctionDeclaration') {\n return statement !== componentInfo.statement;\n }\n\n return statement.type === 'TSEnumDeclaration';\n };\n\n /**\n * Determines the structural section number for a given statement in a component file. It checks the statement\n * against known component structure elements like imports, the main component, displayName assignment, exports,\n * styled declarations, optional declarations, and props types. It returns a numeric section marker to help\n * enforce ordering rules or null when the statement does not belong to a tracked section.\n *\n * @param statement The statement to classify within the component file structure.\n * @returns The numeric section identifier for the statement, or null when it does not match a section.\n *\n * @example\n * ```tsx\n * const section = sectionForStatement(statement);\n * ```\n */\n const sectionForStatement = (statement: TSESTree.Statement) => {\n if (statement.type === 'ImportDeclaration') {\n return 1;\n }\n\n if (statement === componentInfo.statement) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 4;\n }\n\n if (isDisplayNameAssignment(statement, componentName)) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 5;\n }\n\n if (\n isComponentExport(statement, componentName)\n || isDefaultComponentExport(statement, componentName)\n ) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 6;\n }\n\n if (\n isNonPropsTypeDeclaration(statement)\n && statement.range[0] < componentInfo.statement.range[0]\n ) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 2;\n }\n\n if (\n isStyledDeclaration(statement)\n || isStyledFactoryDeclaration(statement)\n || isNonPropsTypeDeclaration(statement)\n ) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 7;\n }\n\n if (isOptionalVarDeclaration(statement)) {\n if (statement.range[0] > componentInfo.statement.range[0]) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 5;\n }\n\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 2;\n }\n\n if (isPropsTypeDeclaration(statement)) {\n // eslint-disable-next-line @nfq/no-magic-numbers\n return 3;\n }\n\n return null;\n };\n\n /**\n * Determines a human-readable label for a statement within the component file structure. It inspects the statement\n * type and section to produce a meaningful name for reporting order violations. It also handles special cases like\n * displayName assignments and exports so diagnostics are clear and actionable.\n *\n * @param statement The statement to derive a label for.\n * @param section The section number associated with the statement.\n * @returns A descriptive name for the statement within its section.\n *\n * @example\n * ```tsx\n * const name = getStatementName(statement, 4);\n * ```\n */\n const getStatementName = (statement: TSESTree.Statement, section: number) => {\n // eslint-disable-next-line @nfq/no-magic-numbers\n if (section === 4) {\n return componentName;\n }\n\n // eslint-disable-next-line @nfq/no-magic-numbers\n if (section === 5 && isDisplayNameAssignment(statement, componentName)) {\n return `${componentName}.displayName`;\n }\n\n if (statement.type === 'VariableDeclaration') {\n const first = statement.declarations[0];\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (first?.id.type === 'Identifier') {\n return first.id.name;\n }\n }\n\n if (statement.type === 'FunctionDeclaration' || statement.type === 'ClassDeclaration') {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return statement.id?.name ?? getSectionLabel(section);\n }\n\n if (statement.type === 'ExportDefaultDeclaration') {\n const {declaration} = statement;\n\n if (declaration.type === 'Identifier') {\n return `export default ${declaration.name}`;\n }\n\n if (declaration.type === 'ClassDeclaration' || declaration.type === 'FunctionDeclaration') {\n if (declaration.id?.name) {\n return `export default ${declaration.id.name}`;\n }\n }\n\n return 'export default';\n }\n\n if (statement.type === 'ExportNamedDeclaration') {\n const names = statement.specifiers\n .filter(specifier => specifier.local.type === 'Identifier')\n // @ts-expect-error\n .map(specifier => specifier.local.name as string);\n\n if (names.length === 1) {\n return `export {${names[0]}}`;\n }\n\n if (names.length > 1) {\n return 'export {...}';\n }\n }\n\n return getSectionLabel(section);\n };\n\n return {\n /**\n * Iterates over the program body statements to validate their order based on the defined component file structure. It\n * tracks the last seen section and reports any statement that appears in an earlier section than the last one. It also checks\n * for the presence of a displayName assignment and a named export for the component, reporting if either is missing.\n * This ensures that the component file adheres to the expected structure and includes necessary metadata for better maintainability and clarity.\n *\n * @example\n * ```tsx\n * Program();\n * ```\n */\n Program() {\n let lastSection = 0;\n let lastSectionName = '';\n let hasDisplayName = hasStaticDisplayName();\n let hasNamedExport = false;\n\n for (const statement of programBody) {\n const section = sectionForStatement(statement as TSESTree.Statement);\n\n // eslint-disable-next-line @nfq/no-magic-numbers\n if (section === 5) {\n hasDisplayName = true;\n }\n\n // eslint-disable-next-line @nfq/no-magic-numbers\n if (section === 6) {\n hasNamedExport = true;\n }\n\n if (!section) {\n continue;\n }\n\n if (section < lastSection) {\n context.report({\n data: {\n current: getSectionLabel(section),\n currentName: getStatementName(statement as TSESTree.Statement, section),\n order: ORDER_MESSAGE,\n previous: getSectionLabel(lastSection),\n previousName: lastSectionName || getSectionLabel(lastSection)\n },\n messageId: 'invalidOrder',\n node: statement\n });\n } else {\n lastSection = section;\n lastSectionName = getStatementName(statement as TSESTree.Statement, section);\n }\n }\n\n if (!hasDisplayName && !isPageComponent) {\n context.report({\n data: {name: componentName},\n messageId: 'missingDisplayName',\n node: componentInfo.statement\n });\n }\n\n if (!hasNamedExport && !isPageComponent) {\n context.report({\n data: {name: componentName},\n messageId: 'missingNamedExport',\n node: componentInfo.statement\n });\n }\n }\n } as TSESLint.RuleListener;\n }\n});"],"names":["createRule","ESLintUtils","RuleCreator","name","ORDER_LABELS","ORDER_MESSAGE","join","getSectionLabel","section","PAGE_TYPE_NAMES","Set","componentFileStructure","defaultOptions","meta","docs","description","messages","invalidOrder","missingDisplayName","missingNamedExport","schema","type","create","context","sourceCode","programBody","ast","body","componentCandidates","filter","statement","map","getComponentInfoFromStatement","info","Boolean","length","componentInfo","sort","left","right","range","componentName","typeDeclarations","Map","getTypeDeclarationInfo","set","propsTypeNames","propsTypeRefs","propsTypeNode","isPageType","typeNode","componentTypeNode","typeRefs","collectTypeReferences","Array","from","some","has","isPageLayoutAssignment","expression","object","property","hasDefaultExport","isDefaultComponentExport","hasLayoutAssignment","isPageComponent","hasStaticDisplayName","hasDisplayNameMember","member","static","key","id","declarator","declarations","init","add","isPropsTypeDeclaration","isNonPropsTypeDeclaration","isOptionalVarDeclaration","isStyledDeclaration","isStyledFactoryDeclaration","sectionForStatement","isDisplayNameAssignment","isComponentExport","getStatementName","first","declaration","names","specifiers","specifier","local","Program","lastSection","lastSectionName","hasDisplayName","hasNamedExport","report","data","current","currentName","order","previous","previousName","messageId","node"],"mappings":";;;AAgBA,MAAMA,YAAU,GAAGC,WAAW,CAACC,WAAW,CACtCC,IAAI,IAAI,CAAA,kEAAA,EAAqEA,IAAI,CAAA,GAAA,CACrF,CAAC;AAID,MAAMC,YAAY,GAAG,CACjB,SAAS,EACT,uBAAuB,EACvB,aAAa,EACb,WAAW,EACX,mCAAmC,EACnC,SAAS,EACT,0CAA0C,CAC7C;AACD,MAAMC,aAAa,GAAGD,YAAY,CAACE,IAAI,CAAC,MAAM,CAAC;AAE/C,MAAMC,eAAe,GAAIC,OAAe,IAAKJ,YAAY,CAACI,OAAO,GAAG,CAAC,CAAC,IAAI,SAAS;AACnF,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAAC,CAC5B,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,uBAAuB,CAC1B,CAAC;AAEK,MAAMC,sBAAsB,GAAGX,YAAU,CAA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AI,CAAC7B,eAAe,EAAE;UACrC1C,OAAO,CAACyE,MAAM,CAAC;AACXC,YAAAA,IAAI,EAAE;AAAC9F,cAAAA,IAAI,EAAEsC;aAAc;AAC3B8D,YAAAA,SAAS,EAAE,oBAAoB;YAC/BC,IAAI,EAAEpE,aAAa,CAACN;AACxB,WAAC,CAAC;AACN,QAAA;AAEA,QAAA,IAAI,CAACiE,cAAc,IAAI,CAAC9B,eAAe,EAAE;UACrC1C,OAAO,CAACyE,MAAM,CAAC;AACXC,YAAAA,IAAI,EAAE;AAAC9F,cAAAA,IAAI,EAAEsC;aAAc;AAC3B8D,YAAAA,SAAS,EAAE,oBAAoB;YAC/BC,IAAI,EAAEpE,aAAa,CAACN;AACxB,WAAC,CAAC;AACN,QAAA;AACJ,MAAA;KACH;AACL,EAAA;AACJ,CAAC;;;;"}
@@ -40,6 +40,64 @@ const noUnboundMethod = createRule$4({
40
40
  const reportCache = new Map();
41
41
  const aliasCache = new Map();
42
42
  const memberSymbolCache = new Map();
43
+ const classAutoBindCache = new WeakMap();
44
+ const isAutoBindOption = node => {
45
+ if (!ts.isObjectLiteralExpression(node)) {
46
+ return false;
47
+ }
48
+ return node.properties.some(property => {
49
+ if (!ts.isPropertyAssignment(property)) {
50
+ return false;
51
+ }
52
+ const name = ts.isIdentifier(property.name) ? property.name.text : ts.isStringLiteral(property.name) ? property.name.text : null;
53
+ if (name !== 'autoBind') {
54
+ return false;
55
+ }
56
+ return property.initializer.kind === ts.SyntaxKind.TrueKeyword;
57
+ });
58
+ };
59
+ const isMakeAutoObservableCallee = node => {
60
+ if (ts.isIdentifier(node)) {
61
+ return node.text === 'makeAutoObservable';
62
+ }
63
+ return ts.isPropertyAccessExpression(node) && node.name.text === 'makeAutoObservable';
64
+ };
65
+ const hasAutoBindInConstructor = classDecl => {
66
+ const cached = classAutoBindCache.get(classDecl);
67
+ if (cached !== undefined) {
68
+ return cached;
69
+ }
70
+ const ctor = classDecl.members.find(member => ts.isConstructorDeclaration(member));
71
+ if (!ctor?.body) {
72
+ classAutoBindCache.set(classDecl, false);
73
+ return false;
74
+ }
75
+ for (const statement of ctor.body.statements) {
76
+ if (!ts.isExpressionStatement(statement)) {
77
+ continue;
78
+ }
79
+ const expr = statement.expression;
80
+ if (!ts.isCallExpression(expr)) {
81
+ continue;
82
+ }
83
+ if (!isMakeAutoObservableCallee(expr.expression)) {
84
+ continue;
85
+ }
86
+ if (expr.arguments.length < 2) {
87
+ continue;
88
+ }
89
+ if (expr.arguments[0].kind !== ts.SyntaxKind.ThisKeyword) {
90
+ continue;
91
+ }
92
+ const hasAutoBind = expr.arguments.slice(1).some(arg => isAutoBindOption(arg));
93
+ if (hasAutoBind) {
94
+ classAutoBindCache.set(classDecl, true);
95
+ return true;
96
+ }
97
+ }
98
+ classAutoBindCache.set(classDecl, false);
99
+ return false;
100
+ };
43
101
  const resolveSymbol = symbol => {
44
102
  const cached = aliasCache.get(symbol);
45
103
  if (cached) {
@@ -74,6 +132,7 @@ const noUnboundMethod = createRule$4({
74
132
  return Boolean(name && decoratorNames.has(name));
75
133
  }));
76
134
  const info = {
135
+ autoBind: hasAutoBindInConstructor(methodDecl.parent),
77
136
  hasDecorator,
78
137
  isStatic,
79
138
  usesThis: methodUsesThis(methodDecl)
@@ -92,7 +151,7 @@ const noUnboundMethod = createRule$4({
92
151
  reportCache.set(aliased, false);
93
152
  return false;
94
153
  }
95
- const shouldReport = !info.isStatic && info.usesThis && !info.hasDecorator;
154
+ const shouldReport = !info.autoBind && !info.isStatic && info.usesThis && !info.hasDecorator;
96
155
  reportCache.set(aliased, shouldReport);
97
156
  return shouldReport;
98
157
  };
@@ -1 +1 @@
1
- {"version":3,"file":"no-unbound-method.js","sources":["../../../../src/rules/custom/no-unbound-method.ts"],"sourcesContent":["import {AST_NODE_TYPES, ESLintUtils} from '@typescript-eslint/utils';\nimport ts from 'typescript';\n\nimport {\n DEFAULT_DECORATORS,\n getDecoratorName,\n isCallbackUsage,\n isThisBindCall,\n methodUsesThis,\n normalizeDecoratorNames,\n unwrapExpression\n} from './utils/no-unbound-method-utils';\n\nimport type {TSESLint, TSESTree} from '@typescript-eslint/utils';\n\nconst createRule = ESLintUtils.RuleCreator(\n name => `https://github.com/nfqde/eslint-config-nfq/blob/master/docs/rules/${name}.md`\n);\n\ntype RuleOptions = [\n {decoratorNames?: string[]}?\n];\n\ntype MessageIds = 'constructorBind' | 'unboundMethod';\n\ntype MethodInfo = {\n hasDecorator: boolean;\n isStatic: boolean;\n usesThis: boolean;\n};\n\nexport const noUnboundMethod = createRule<RuleOptions, MessageIds>({\n defaultOptions: [{decoratorNames: DEFAULT_DECORATORS}],\n meta: {\n docs: {description: 'Warn when unbound class methods that use this are passed as callbacks.'},\n messages: {\n constructorBind: 'Do not bind in the constructor; prefer {{decoratorName}}.',\n unboundMethod: 'Method {{methodName}} uses this and is passed unbound. Add {{decoratorName}} or bind it.'\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n decoratorNames: {\n items: {type: 'string'},\n type: 'array',\n uniqueItems: true\n }\n },\n type: 'object'\n }\n ],\n type: 'problem'\n },\n name: 'no-unbound-method',\n /**\n * Creates the rule listeners and initializes caches for symbol analysis.\n * It wires the parser services to the TypeScript type checker and configures decorator handling.\n * It returns ESLint listeners that report unbound method usage in callbacks and constructor binding.\n *\n * @param context Rule context used to access parser services and report issues.\n * @returns The rule listener map for this rule.\n *\n * @example\n * ```tsx\n * const listeners = rule.create(context);\n * ```\n */\n create(context) {\n const services = ESLintUtils.getParserServices(context);\n const checker = services.program.getTypeChecker();\n const decoratorNames = normalizeDecoratorNames(context.options[0]?.decoratorNames);\n const decoratorLabel = `@${Array.from(decoratorNames)[0] ?? 'autobind'}`;\n const methodCache = new Map<ts.Symbol, MethodInfo>();\n const reportCache = new Map<ts.Symbol, boolean>();\n const aliasCache = new Map<ts.Symbol, ts.Symbol>();\n const memberSymbolCache = new Map<TSESTree.MemberExpression, ts.Symbol | null>();\n\n /**\n * Resolves an alias symbol to its original symbol and caches the result for reuse.\n * This function avoids repeated TypeScript checker work by memoizing alias resolutions.\n * It ensures downstream analysis consistently uses the same canonical symbol instance.\n *\n * @param symbol The symbol that may be an alias and needs resolution.\n * @returns The resolved canonical symbol for further analysis.\n *\n * @example\n * ```tsx\n * const resolved = resolveSymbol(methodSymbol);\n * ```\n */\n const resolveSymbol = (symbol: ts.Symbol): ts.Symbol => {\n const cached = aliasCache.get(symbol);\n\n if (cached) {\n return cached;\n }\n\n // eslint-disable-next-line no-bitwise\n const resolved = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;\n\n aliasCache.set(symbol, resolved);\n\n return resolved;\n };\n\n /**\n * Computes metadata about a method-like symbol and caches the result for later use.\n * This function filters out non-method symbols and constructor declarations before gathering details.\n * It also determines decorator presence, static status, and whether the method uses `this`.\n *\n * @param symbol The symbol to inspect for method information.\n * @returns The resolved method info or null when the symbol is not a supported method.\n *\n * @example\n * ```tsx\n * const info = getMethodInfo(methodSymbol);\n * ```\n */\n const getMethodInfo = (symbol: ts.Symbol): MethodInfo | null => {\n const aliased = resolveSymbol(symbol);\n const cached = methodCache.get(aliased);\n\n if (cached) {\n return cached;\n }\n\n if (!(\n // eslint-disable-next-line no-bitwise\n aliased.flags\n & (\n // eslint-disable-next-line no-bitwise\n ts.SymbolFlags.Method\n | ts.SymbolFlags.Property\n | ts.SymbolFlags.Function\n | ts.SymbolFlags.GetAccessor\n | ts.SymbolFlags.SetAccessor\n )\n )) {\n return null;\n }\n\n const declarations = aliased.getDeclarations() ?? [];\n const methodDecl = declarations\n .find(decl => ts.isMethodDeclaration(decl));\n\n if (!methodDecl?.parent || !ts.isClassLike(methodDecl.parent)) {\n return null;\n }\n\n if (ts.isIdentifier(methodDecl.name) && methodDecl.name.text === 'constructor') {\n return null;\n }\n\n const flags = ts.getCombinedModifierFlags(methodDecl);\n // eslint-disable-next-line no-bitwise\n const isStatic = Boolean(flags & ts.ModifierFlags.Static);\n const decorators = ts.canHaveDecorators(methodDecl) ? ts.getDecorators(methodDecl) : undefined;\n const hasDecorator = Boolean(decorators?.some(decorator => {\n const name = getDecoratorName(decorator);\n\n return Boolean(name && decoratorNames.has(name));\n }));\n\n const info: MethodInfo = {\n hasDecorator,\n isStatic,\n usesThis: methodUsesThis(methodDecl)\n };\n\n methodCache.set(aliased, info);\n\n return info;\n };\n\n /**\n * Determines whether a symbol should be reported as an unbound method.\n * It resolves aliases and consults cached results to avoid repeated analysis.\n * It evaluates method metadata to ensure only non-static methods that use `this` and lack decorators are flagged.\n *\n * @param symbol The symbol to evaluate for reporting eligibility.\n * @returns True when the symbol represents an unbound method that should be reported.\n *\n * @example\n * ```tsx\n * const shouldReport = shouldReportSymbol(methodSymbol);\n * ```\n */\n const shouldReportSymbol = (symbol: ts.Symbol): boolean => {\n const aliased = resolveSymbol(symbol);\n const cached = reportCache.get(aliased);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const info = getMethodInfo(aliased);\n\n if (!info) {\n reportCache.set(aliased, false);\n\n return false;\n }\n\n const shouldReport = !info.isStatic && info.usesThis && !info.hasDecorator;\n\n reportCache.set(aliased, shouldReport);\n\n return shouldReport;\n };\n\n /**\n * Resolves the TypeScript symbol associated with a member expression node.\n * It caches the resolved symbol to minimize repeated checker lookups.\n * It supports both property access and string-literal element access expressions.\n *\n * @param node The member expression node to resolve into a symbol.\n * @returns The resolved symbol, or null when no symbol can be determined.\n *\n * @example\n * ```tsx\n * const symbol = getSymbolForMember(memberExpression);\n * ```\n */\n const getSymbolForMember = (node: TSESTree.MemberExpression): ts.Symbol | null => {\n const cached = memberSymbolCache.get(node);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const tsNode = services.esTreeNodeToTSNodeMap.get(node);\n\n if (ts.isPropertyAccessExpression(tsNode)) {\n const symbol = checker.getSymbolAtLocation(tsNode.name) ?? null;\n\n memberSymbolCache.set(node, symbol);\n\n return symbol;\n }\n\n if (ts.isElementAccessExpression(tsNode)) {\n const arg = tsNode.argumentExpression;\n\n if (ts.isStringLiteralLike(arg)) {\n const symbol = checker.getSymbolAtLocation(arg) ?? null;\n\n memberSymbolCache.set(node, symbol);\n\n return symbol;\n }\n }\n\n memberSymbolCache.set(node, null);\n\n return null;\n };\n\n /**\n * Reports a constructor binding assignment for a method name.\n * It formats the report data with the decorator label and method name.\n * It delegates to the ESLint context to surface the diagnostic at the provided node.\n *\n * @param methodName The name of the method that was bound in the constructor.\n * @param node The AST node that represents the binding expression.\n *\n * @example\n * ```tsx\n * reportConstructorBinding('handleClick', expressionNode);\n * ```\n */\n const reportConstructorBinding = (methodName: string, node: TSESTree.Node) => {\n context.report({\n data: {\n decoratorName: decoratorLabel,\n methodName\n },\n messageId: 'constructorBind',\n node\n });\n };\n\n const listeners: TSESLint.RuleListener = {\n /**\n * Processes a member expression node to determine whether it represents an unbound method usage that\n * should be reported. It performs multiple early returns based on node shape, parent usage, callback context,\n * binding checks, and symbol eligibility. It ultimately reports a linting issue when all conditions\n * indicate a problematic unbound method reference.\n *\n * @param node The member expression node to analyze for unbound method usage.\n *\n * @example\n * ```tsx\n * MemberExpression(node);\n * ```\n */\n MemberExpression(node: TSESTree.MemberExpression) {\n if (node.property.type !== AST_NODE_TYPES.Identifier) {\n return;\n }\n\n const {parent} = node;\n\n if (\n (parent.type === AST_NODE_TYPES.CallExpression || parent.type === AST_NODE_TYPES.NewExpression)\n && parent.callee === node\n ) {\n return;\n }\n\n if (!isCallbackUsage(node)) {\n return;\n }\n\n if (isThisBindCall(node)) {\n return;\n }\n\n const symbol = getSymbolForMember(node);\n\n if (!symbol) {\n return;\n }\n\n if (!shouldReportSymbol(symbol)) {\n return;\n }\n\n context.report({\n data: {\n decoratorName: decoratorLabel,\n methodName: node.property.name\n },\n messageId: 'unboundMethod',\n node\n });\n },\n /**\n * Inspects constructor method definitions to detect assignments where a class method\n * is bound to `this` via `.bind(this)`, and reports such bindings for further handling.\n *\n * @param node The method definition node to analyze.\n */\n MethodDefinition(node: TSESTree.MethodDefinition) {\n if (node.kind !== 'constructor' || !node.value.body) {\n return;\n }\n\n const constructorBody = node.value.body;\n\n for (const statement of constructorBody.body) {\n if (statement.type !== AST_NODE_TYPES.ExpressionStatement) {\n continue;\n }\n\n const {expression} = statement;\n\n if (expression.type !== AST_NODE_TYPES.AssignmentExpression || expression.operator !== '=') {\n continue;\n }\n\n const {left, right} = expression;\n\n if (\n left.type !== AST_NODE_TYPES.MemberExpression\n || left.property.type !== AST_NODE_TYPES.Identifier\n ) {\n continue;\n }\n\n if (left.object.type !== AST_NODE_TYPES.ThisExpression) {\n continue;\n }\n\n if (right.type !== AST_NODE_TYPES.CallExpression) {\n continue;\n }\n\n const {callee} = right;\n\n if (callee.type !== AST_NODE_TYPES.MemberExpression) {\n continue;\n }\n\n if (\n callee.object.type !== AST_NODE_TYPES.MemberExpression\n || callee.object.object.type !== AST_NODE_TYPES.ThisExpression\n || callee.object.property.type !== AST_NODE_TYPES.Identifier\n || callee.object.property.name !== left.property.name\n ) {\n continue;\n }\n\n if (\n callee.property.type !== AST_NODE_TYPES.Identifier\n || callee.property.name !== 'bind'\n ) {\n continue;\n }\n\n if (right.arguments.length === 0) {\n continue;\n }\n\n const firstArg = unwrapExpression(right.arguments[0] as TSESTree.Expression);\n\n if (firstArg.type !== AST_NODE_TYPES.ThisExpression) {\n continue;\n }\n\n reportConstructorBinding(left.property.name, expression);\n }\n }\n };\n\n return listeners;\n }\n});"],"names":["createRule","ESLintUtils","RuleCreator","name","noUnboundMethod","defaultOptions","decoratorNames","DEFAULT_DECORATORS","meta","docs","description","messages","constructorBind","unboundMethod","schema","additionalProperties","properties","items","type","uniqueItems","create","context","services","getParserServices","checker","program","getTypeChecker","normalizeDecoratorNames","options","decoratorLabel","Array","from","methodCache","Map","reportCache","aliasCache","memberSymbolCache","resolveSymbol","symbol","cached","get","resolved","flags","ts","SymbolFlags","Alias","getAliasedSymbol","set","getMethodInfo","aliased","Method","Property","Function","GetAccessor","SetAccessor","declarations","getDeclarations","methodDecl","find","decl","isMethodDeclaration","parent","isClassLike","isIdentifier","text","getCombinedModifierFlags","isStatic","Boolean","ModifierFlags","Static","decorators","canHaveDecorators","getDecorators","undefined","hasDecorator","some","decorator","getDecoratorName","has","info","usesThis","methodUsesThis","shouldReportSymbol","shouldReport","getSymbolForMember","node","tsNode","esTreeNodeToTSNodeMap","isPropertyAccessExpression","getSymbolAtLocation","isElementAccessExpression","arg","argumentExpression","isStringLiteralLike","reportConstructorBinding","methodName","report","data","decoratorName","messageId","listeners","MemberExpression","property","AST_NODE_TYPES","Identifier","CallExpression","NewExpression","callee","isCallbackUsage","isThisBindCall","MethodDefinition","kind","value","body","constructorBody","statement","ExpressionStatement","expression","AssignmentExpression","operator","left","right","object","ThisExpression","arguments","length","firstArg","unwrapExpression"],"mappings":";;;;AAeA,MAAMA,YAAU,GAAGC,WAAW,CAACC,WAAW,CACtCC,IAAI,IAAI,CAAA,kEAAA,EAAqEA,IAAI,CAAA,GAAA,CACrF,CAAC;AAcM,MAAMC,eAAe,GAAGJ,YAAU,CAA0B;AAC/DK,EAAAA,cAAc,EAAE,CAAC;AAACC,IAAAA,cAAc,EAAEC;AAAkB,GAAC,CAAC;AACtDC,EAAAA,IAAI,EAAE;AACFC,IAAAA,IAAI,EAAE;AAACC,MAAAA,WAAW,EAAE;KAAyE;AAC7FC,IAAAA,QAAQ,EAAE;AACNC,MAAAA,eAAe,EAAE,2DAA2D;AAC5EC,MAAAA,aAAa,EAAE;KAClB;AACDC,IAAAA,MAAM,EAAE,CACJ;AACIC,MAAAA,oBAAoB,EAAE,KAAK;AAC3BC,MAAAA,UAAU,EAAE;AACRV,QAAAA,cAAc,EAAE;AACZW,UAAAA,KAAK,EAAE;AAACC,YAAAA,IAAI,EAAE;WAAS;AACvBA,UAAAA,IAAI,EAAE,OAAO;AACbC,UAAAA,WAAW,EAAE;AACjB;OACH;AACDD,MAAAA,IAAI,EAAE;AACV,KAAC,CACJ;AACDA,IAAAA,IAAI,EAAE;GACT;AACDf,EAAAA,IAAI,EAAE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,CAACpF,IAAI,KAAKqF,cAAc,CAACC,UAAU,IAC/CG,MAAM,CAACL,QAAQ,CAACnG,IAAI,KAAK,MAAM,EACpC;AACE,YAAA;AACJ,UAAA;AAEA,UAAA,IAAIsH,KAAK,CAACG,SAAS,CAACC,MAAM,KAAK,CAAC,EAAE;AAC9B,YAAA;AACJ,UAAA;UAEA,MAAMC,QAAQ,GAAGC,gBAAgB,CAACN,KAAK,CAACG,SAAS,CAAC,CAAC,CAAwB,CAAC;AAE5E,UAAA,IAAIE,QAAQ,CAAC5G,IAAI,KAAKqF,cAAc,CAACoB,cAAc,EAAE;AACjD,YAAA;AACJ,UAAA;UAEA7B,wBAAwB,CAAC0B,IAAI,CAAClB,QAAQ,CAACnG,IAAI,EAAEkH,UAAU,CAAC;AAC5D,QAAA;AACJ,MAAA;KACH;AAED,IAAA,OAAOjB,SAAS;AACpB,EAAA;AACJ,CAAC;;;;"}
1
+ {"version":3,"file":"no-unbound-method.js","sources":["../../../../src/rules/custom/no-unbound-method.ts"],"sourcesContent":["import {AST_NODE_TYPES, ESLintUtils} from '@typescript-eslint/utils';\nimport ts from 'typescript';\n\nimport {\n DEFAULT_DECORATORS,\n getDecoratorName,\n isCallbackUsage,\n isThisBindCall,\n methodUsesThis,\n normalizeDecoratorNames,\n unwrapExpression\n} from './utils/no-unbound-method-utils';\n\nimport type {TSESLint, TSESTree} from '@typescript-eslint/utils';\n\nconst createRule = ESLintUtils.RuleCreator(\n name => `https://github.com/nfqde/eslint-config-nfq/blob/master/docs/rules/${name}.md`\n);\n\ntype RuleOptions = [\n {decoratorNames?: string[]}?\n];\n\ntype MessageIds = 'constructorBind' | 'unboundMethod';\n\ntype MethodInfo = {\n autoBind: boolean;\n hasDecorator: boolean;\n isStatic: boolean;\n usesThis: boolean;\n};\n\nexport const noUnboundMethod = createRule<RuleOptions, MessageIds>({\n defaultOptions: [{decoratorNames: DEFAULT_DECORATORS}],\n meta: {\n docs: {description: 'Warn when unbound class methods that use this are passed as callbacks.'},\n messages: {\n constructorBind: 'Do not bind in the constructor; prefer {{decoratorName}}.',\n unboundMethod: 'Method {{methodName}} uses this and is passed unbound. Add {{decoratorName}} or bind it.'\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n decoratorNames: {\n items: {type: 'string'},\n type: 'array',\n uniqueItems: true\n }\n },\n type: 'object'\n }\n ],\n type: 'problem'\n },\n name: 'no-unbound-method',\n /**\n * Creates the rule listeners and initializes caches for symbol analysis.\n * It wires the parser services to the TypeScript type checker and configures decorator handling.\n * It returns ESLint listeners that report unbound method usage in callbacks and constructor binding.\n *\n * @param context Rule context used to access parser services and report issues.\n * @returns The rule listener map for this rule.\n *\n * @example\n * ```tsx\n * const listeners = rule.create(context);\n * ```\n */\n create(context) {\n const services = ESLintUtils.getParserServices(context);\n const checker = services.program.getTypeChecker();\n const decoratorNames = normalizeDecoratorNames(context.options[0]?.decoratorNames);\n const decoratorLabel = `@${Array.from(decoratorNames)[0] ?? 'autobind'}`;\n const methodCache = new Map<ts.Symbol, MethodInfo>();\n const reportCache = new Map<ts.Symbol, boolean>();\n const aliasCache = new Map<ts.Symbol, ts.Symbol>();\n const memberSymbolCache = new Map<TSESTree.MemberExpression, ts.Symbol | null>();\n const classAutoBindCache = new WeakMap<ts.ClassLikeDeclaration, boolean>();\n\n const isAutoBindOption = (node: ts.Expression): boolean => {\n if (!ts.isObjectLiteralExpression(node)) {\n return false;\n }\n\n return node.properties.some(property => {\n if (!ts.isPropertyAssignment(property)) {\n return false;\n }\n\n const name = ts.isIdentifier(property.name)\n ? property.name.text\n : ts.isStringLiteral(property.name)\n ? property.name.text\n : null;\n\n if (name !== 'autoBind') {\n return false;\n }\n\n return property.initializer.kind === ts.SyntaxKind.TrueKeyword;\n });\n };\n\n const isMakeAutoObservableCallee = (node: ts.Expression): boolean => {\n if (ts.isIdentifier(node)) {\n return node.text === 'makeAutoObservable';\n }\n\n return ts.isPropertyAccessExpression(node) && node.name.text === 'makeAutoObservable';\n };\n\n const hasAutoBindInConstructor = (classDecl: ts.ClassLikeDeclaration): boolean => {\n const cached = classAutoBindCache.get(classDecl);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const ctor = classDecl.members.find(member => ts.isConstructorDeclaration(member));\n\n if (!ctor?.body) {\n classAutoBindCache.set(classDecl, false);\n\n return false;\n }\n\n for (const statement of ctor.body.statements) {\n if (!ts.isExpressionStatement(statement)) {\n continue;\n }\n\n const expr = statement.expression;\n\n if (!ts.isCallExpression(expr)) {\n continue;\n }\n\n if (!isMakeAutoObservableCallee(expr.expression)) {\n continue;\n }\n\n if (expr.arguments.length < 2) {\n continue;\n }\n\n if (expr.arguments[0].kind !== ts.SyntaxKind.ThisKeyword) {\n continue;\n }\n\n const hasAutoBind = expr.arguments.slice(1).some(arg => isAutoBindOption(arg));\n\n if (hasAutoBind) {\n classAutoBindCache.set(classDecl, true);\n\n return true;\n }\n }\n\n classAutoBindCache.set(classDecl, false);\n\n return false;\n };\n\n /**\n * Resolves an alias symbol to its original symbol and caches the result for reuse.\n * This function avoids repeated TypeScript checker work by memoizing alias resolutions.\n * It ensures downstream analysis consistently uses the same canonical symbol instance.\n *\n * @param symbol The symbol that may be an alias and needs resolution.\n * @returns The resolved canonical symbol for further analysis.\n *\n * @example\n * ```tsx\n * const resolved = resolveSymbol(methodSymbol);\n * ```\n */\n const resolveSymbol = (symbol: ts.Symbol): ts.Symbol => {\n const cached = aliasCache.get(symbol);\n\n if (cached) {\n return cached;\n }\n\n // eslint-disable-next-line no-bitwise\n const resolved = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;\n\n aliasCache.set(symbol, resolved);\n\n return resolved;\n };\n\n /**\n * Computes metadata about a method-like symbol and caches the result for later use.\n * This function filters out non-method symbols and constructor declarations before gathering details.\n * It also determines decorator presence, static status, and whether the method uses `this`.\n *\n * @param symbol The symbol to inspect for method information.\n * @returns The resolved method info or null when the symbol is not a supported method.\n *\n * @example\n * ```tsx\n * const info = getMethodInfo(methodSymbol);\n * ```\n */\n const getMethodInfo = (symbol: ts.Symbol): MethodInfo | null => {\n const aliased = resolveSymbol(symbol);\n const cached = methodCache.get(aliased);\n\n if (cached) {\n return cached;\n }\n\n if (!(\n // eslint-disable-next-line no-bitwise\n aliased.flags\n & (\n // eslint-disable-next-line no-bitwise\n ts.SymbolFlags.Method\n | ts.SymbolFlags.Property\n | ts.SymbolFlags.Function\n | ts.SymbolFlags.GetAccessor\n | ts.SymbolFlags.SetAccessor\n )\n )) {\n return null;\n }\n\n const declarations = aliased.getDeclarations() ?? [];\n const methodDecl = declarations\n .find(decl => ts.isMethodDeclaration(decl));\n\n if (!methodDecl?.parent || !ts.isClassLike(methodDecl.parent)) {\n return null;\n }\n\n if (ts.isIdentifier(methodDecl.name) && methodDecl.name.text === 'constructor') {\n return null;\n }\n\n const flags = ts.getCombinedModifierFlags(methodDecl);\n // eslint-disable-next-line no-bitwise\n const isStatic = Boolean(flags & ts.ModifierFlags.Static);\n const decorators = ts.canHaveDecorators(methodDecl) ? ts.getDecorators(methodDecl) : undefined;\n const hasDecorator = Boolean(decorators?.some(decorator => {\n const name = getDecoratorName(decorator);\n\n return Boolean(name && decoratorNames.has(name));\n }));\n\n const info: MethodInfo = {\n autoBind: hasAutoBindInConstructor(methodDecl.parent),\n hasDecorator,\n isStatic,\n usesThis: methodUsesThis(methodDecl)\n };\n\n methodCache.set(aliased, info);\n\n return info;\n };\n\n /**\n * Determines whether a symbol should be reported as an unbound method.\n * It resolves aliases and consults cached results to avoid repeated analysis.\n * It evaluates method metadata to ensure only non-static methods that use `this` and lack decorators are flagged.\n *\n * @param symbol The symbol to evaluate for reporting eligibility.\n * @returns True when the symbol represents an unbound method that should be reported.\n *\n * @example\n * ```tsx\n * const shouldReport = shouldReportSymbol(methodSymbol);\n * ```\n */\n const shouldReportSymbol = (symbol: ts.Symbol): boolean => {\n const aliased = resolveSymbol(symbol);\n const cached = reportCache.get(aliased);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const info = getMethodInfo(aliased);\n\n if (!info) {\n reportCache.set(aliased, false);\n\n return false;\n }\n\n const shouldReport = !info.autoBind && !info.isStatic && info.usesThis && !info.hasDecorator;\n\n reportCache.set(aliased, shouldReport);\n\n return shouldReport;\n };\n\n /**\n * Resolves the TypeScript symbol associated with a member expression node.\n * It caches the resolved symbol to minimize repeated checker lookups.\n * It supports both property access and string-literal element access expressions.\n *\n * @param node The member expression node to resolve into a symbol.\n * @returns The resolved symbol, or null when no symbol can be determined.\n *\n * @example\n * ```tsx\n * const symbol = getSymbolForMember(memberExpression);\n * ```\n */\n const getSymbolForMember = (node: TSESTree.MemberExpression): ts.Symbol | null => {\n const cached = memberSymbolCache.get(node);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const tsNode = services.esTreeNodeToTSNodeMap.get(node);\n\n if (ts.isPropertyAccessExpression(tsNode)) {\n const symbol = checker.getSymbolAtLocation(tsNode.name) ?? null;\n\n memberSymbolCache.set(node, symbol);\n\n return symbol;\n }\n\n if (ts.isElementAccessExpression(tsNode)) {\n const arg = tsNode.argumentExpression;\n\n if (ts.isStringLiteralLike(arg)) {\n const symbol = checker.getSymbolAtLocation(arg) ?? null;\n\n memberSymbolCache.set(node, symbol);\n\n return symbol;\n }\n }\n\n memberSymbolCache.set(node, null);\n\n return null;\n };\n\n /**\n * Reports a constructor binding assignment for a method name.\n * It formats the report data with the decorator label and method name.\n * It delegates to the ESLint context to surface the diagnostic at the provided node.\n *\n * @param methodName The name of the method that was bound in the constructor.\n * @param node The AST node that represents the binding expression.\n *\n * @example\n * ```tsx\n * reportConstructorBinding('handleClick', expressionNode);\n * ```\n */\n const reportConstructorBinding = (methodName: string, node: TSESTree.Node) => {\n context.report({\n data: {\n decoratorName: decoratorLabel,\n methodName\n },\n messageId: 'constructorBind',\n node\n });\n };\n\n const listeners: TSESLint.RuleListener = {\n /**\n * Processes a member expression node to determine whether it represents an unbound method usage that\n * should be reported. It performs multiple early returns based on node shape, parent usage, callback context,\n * binding checks, and symbol eligibility. It ultimately reports a linting issue when all conditions\n * indicate a problematic unbound method reference.\n *\n * @param node The member expression node to analyze for unbound method usage.\n *\n * @example\n * ```tsx\n * MemberExpression(node);\n * ```\n */\n MemberExpression(node: TSESTree.MemberExpression) {\n if (node.property.type !== AST_NODE_TYPES.Identifier) {\n return;\n }\n\n const {parent} = node;\n\n if (\n (parent.type === AST_NODE_TYPES.CallExpression || parent.type === AST_NODE_TYPES.NewExpression)\n && parent.callee === node\n ) {\n return;\n }\n\n if (!isCallbackUsage(node)) {\n return;\n }\n\n if (isThisBindCall(node)) {\n return;\n }\n\n const symbol = getSymbolForMember(node);\n\n if (!symbol) {\n return;\n }\n\n if (!shouldReportSymbol(symbol)) {\n return;\n }\n\n context.report({\n data: {\n decoratorName: decoratorLabel,\n methodName: node.property.name\n },\n messageId: 'unboundMethod',\n node\n });\n },\n /**\n * Inspects constructor method definitions to detect assignments where a class method\n * is bound to `this` via `.bind(this)`, and reports such bindings for further handling.\n *\n * @param node The method definition node to analyze.\n */\n MethodDefinition(node: TSESTree.MethodDefinition) {\n if (node.kind !== 'constructor' || !node.value.body) {\n return;\n }\n\n const constructorBody = node.value.body;\n\n for (const statement of constructorBody.body) {\n if (statement.type !== AST_NODE_TYPES.ExpressionStatement) {\n continue;\n }\n\n const {expression} = statement;\n\n if (expression.type !== AST_NODE_TYPES.AssignmentExpression || expression.operator !== '=') {\n continue;\n }\n\n const {left, right} = expression;\n\n if (\n left.type !== AST_NODE_TYPES.MemberExpression\n || left.property.type !== AST_NODE_TYPES.Identifier\n ) {\n continue;\n }\n\n if (left.object.type !== AST_NODE_TYPES.ThisExpression) {\n continue;\n }\n\n if (right.type !== AST_NODE_TYPES.CallExpression) {\n continue;\n }\n\n const {callee} = right;\n\n if (callee.type !== AST_NODE_TYPES.MemberExpression) {\n continue;\n }\n\n if (\n callee.object.type !== AST_NODE_TYPES.MemberExpression\n || callee.object.object.type !== AST_NODE_TYPES.ThisExpression\n || callee.object.property.type !== AST_NODE_TYPES.Identifier\n || callee.object.property.name !== left.property.name\n ) {\n continue;\n }\n\n if (\n callee.property.type !== AST_NODE_TYPES.Identifier\n || callee.property.name !== 'bind'\n ) {\n continue;\n }\n\n if (right.arguments.length === 0) {\n continue;\n }\n\n const firstArg = unwrapExpression(right.arguments[0] as TSESTree.Expression);\n\n if (firstArg.type !== AST_NODE_TYPES.ThisExpression) {\n continue;\n }\n\n reportConstructorBinding(left.property.name, expression);\n }\n }\n };\n\n return listeners;\n }\n});"],"names":["createRule","ESLintUtils","RuleCreator","name","noUnboundMethod","defaultOptions","decoratorNames","DEFAULT_DECORATORS","meta","docs","description","messages","constructorBind","unboundMethod","schema","additionalProperties","properties","items","type","uniqueItems","create","context","services","getParserServices","checker","program","getTypeChecker","normalizeDecoratorNames","options","decoratorLabel","Array","from","methodCache","Map","reportCache","aliasCache","memberSymbolCache","classAutoBindCache","WeakMap","isAutoBindOption","node","ts","isObjectLiteralExpression","some","property","isPropertyAssignment","isIdentifier","text","isStringLiteral","initializer","kind","SyntaxKind","TrueKeyword","isMakeAutoObservableCallee","isPropertyAccessExpression","hasAutoBindInConstructor","classDecl","cached","get","undefined","ctor","members","find","member","isConstructorDeclaration","body","set","statement","statements","isExpressionStatement","expr","expression","isCallExpression","arguments","length","ThisKeyword","hasAutoBind","slice","arg","resolveSymbol","symbol","resolved","flags","SymbolFlags","Alias","getAliasedSymbol","getMethodInfo","aliased","Method","Property","Function","GetAccessor","SetAccessor","declarations","getDeclarations","methodDecl","decl","isMethodDeclaration","parent","isClassLike","getCombinedModifierFlags","isStatic","Boolean","ModifierFlags","Static","decorators","canHaveDecorators","getDecorators","hasDecorator","decorator","getDecoratorName","has","info","autoBind","usesThis","methodUsesThis","shouldReportSymbol","shouldReport","getSymbolForMember","tsNode","esTreeNodeToTSNodeMap","getSymbolAtLocation","isElementAccessExpression","argumentExpression","isStringLiteralLike","reportConstructorBinding","methodName","report","data","decoratorName","messageId","listeners","MemberExpression","AST_NODE_TYPES","Identifier","CallExpression","NewExpression","callee","isCallbackUsage","isThisBindCall","MethodDefinition","value","constructorBody","ExpressionStatement","AssignmentExpression","operator","left","right","object","ThisExpression","firstArg","unwrapExpression"],"mappings":";;;;AAeA,MAAMA,YAAU,GAAGC,WAAW,CAACC,WAAW,CACtCC,IAAI,IAAI,CAAA,kEAAA,EAAqEA,IAAI,CAAA,GAAA,CACrF,CAAC;AAeM,MAAMC,eAAe,GAAGJ,YAAU,CAA0B;AAC/DK,EAAAA,cAAc,EAAE,CAAC;AAACC,IAAAA,cAAc,EAAEC;AAAkB,GAAC,CAAC;AACtDC,EAAAA,IAAI,EAAE;AACFC,IAAAA,IAAI,EAAE;AAACC,MAAAA,WAAW,EAAE;KAAyE;AAC7FC,IAAAA,QAAQ,EAAE;AACNC,MAAAA,eAAe,EAAE,2DAA2D;AAC5EC,MAAAA,aAAa,EAAE;KAClB;AACDC,IAAAA,MAAM,EAAE,CACJ;AACIC,MAAAA,oBAAoB,EAAE,KAAK;AAC3BC,MAAAA,UAAU,EAAE;AACRV,QAAAA,cAAc,EAAE;AACZW,UAAAA,KAAK,EAAE;AAACC,YAAAA,IAAI,EAAE;WAAS;AACvBA,UAAAA,IAAI,EAAE,OAAO;AACbC,UAAAA,WAAW,EAAE;AACjB;OACH;AACDD,MAAAA,IAAI,EAAE;AACV,KAAC,CACJ;AACDA,IAAAA,IAAI,EAAE;GACT;AACDf,EAAAA,IAAI,EAAE,mBAAmB;EAczBiB,MAAMA,CAACC,OAAO,EAAE;AACZ,IAAA,MAAMC,QAAQ,GAAGrB,WAAW,CAACsB,iBAAiB,CAACF,OAAO,CAAC;IACvD,MAAMG,OAAO,GAAGF,QAAQ,CAACG,OAAO,CAACC,cAAc,EAAE;AACjD,IAAA,MAAMpB,cAAc,GAAGqB,uBAAuB,CAACN,OAAO,CAACO,OAAO,CAAC,CAAC,CAAC,EAAEtB,cAAc,CAAC;AAClF,IAAA,MAAMuB,cAAc,GAAG,CAAA,CAAA,EAAIC,KAAK,CAACC,IAAI,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,QAAQ,CAAC1B,IAAI,KAAKmH,cAAc,CAACC,UAAU,IAC/CG,MAAM,CAAC7F,QAAQ,CAACzC,IAAI,KAAK,MAAM,EACpC;AACE,YAAA;AACJ,UAAA;AAEA,UAAA,IAAIgJ,KAAK,CAAC1E,SAAS,CAACC,MAAM,KAAK,CAAC,EAAE;AAC9B,YAAA;AACJ,UAAA;UAEA,MAAM4E,QAAQ,GAAGC,gBAAgB,CAACJ,KAAK,CAAC1E,SAAS,CAAC,CAAC,CAAwB,CAAC;AAE5E,UAAA,IAAI6E,QAAQ,CAACpI,IAAI,KAAKmH,cAAc,CAACgB,cAAc,EAAE;AACjD,YAAA;AACJ,UAAA;UAEAxB,wBAAwB,CAACqB,IAAI,CAACtG,QAAQ,CAACzC,IAAI,EAAEoE,UAAU,CAAC;AAC5D,QAAA;AACJ,MAAA;KACH;AAED,IAAA,OAAO4D,SAAS;AACpB,EAAA;AACJ,CAAC;;;;"}
package/dist/index.js CHANGED
@@ -2155,7 +2155,7 @@ const componentFileStructure = createRule$b({
2155
2155
  if (isComponentExport(statement, componentName) || isDefaultComponentExport(statement, componentName)) {
2156
2156
  return 6;
2157
2157
  }
2158
- if (isPageComponent && isNonPropsTypeDeclaration(statement) && statement.range[0] < componentInfo.statement.range[0]) {
2158
+ if (isNonPropsTypeDeclaration(statement) && statement.range[0] < componentInfo.statement.range[0]) {
2159
2159
  return 2;
2160
2160
  }
2161
2161
  if (isStyledDeclaration(statement) || isStyledFactoryDeclaration(statement) || isNonPropsTypeDeclaration(statement)) {
@@ -3883,6 +3883,64 @@ const noUnboundMethod = createRule$4({
3883
3883
  const reportCache = new Map();
3884
3884
  const aliasCache = new Map();
3885
3885
  const memberSymbolCache = new Map();
3886
+ const classAutoBindCache = new WeakMap();
3887
+ const isAutoBindOption = node => {
3888
+ if (!ts__default.default.isObjectLiteralExpression(node)) {
3889
+ return false;
3890
+ }
3891
+ return node.properties.some(property => {
3892
+ if (!ts__default.default.isPropertyAssignment(property)) {
3893
+ return false;
3894
+ }
3895
+ const name = ts__default.default.isIdentifier(property.name) ? property.name.text : ts__default.default.isStringLiteral(property.name) ? property.name.text : null;
3896
+ if (name !== 'autoBind') {
3897
+ return false;
3898
+ }
3899
+ return property.initializer.kind === ts__default.default.SyntaxKind.TrueKeyword;
3900
+ });
3901
+ };
3902
+ const isMakeAutoObservableCallee = node => {
3903
+ if (ts__default.default.isIdentifier(node)) {
3904
+ return node.text === 'makeAutoObservable';
3905
+ }
3906
+ return ts__default.default.isPropertyAccessExpression(node) && node.name.text === 'makeAutoObservable';
3907
+ };
3908
+ const hasAutoBindInConstructor = classDecl => {
3909
+ const cached = classAutoBindCache.get(classDecl);
3910
+ if (cached !== undefined) {
3911
+ return cached;
3912
+ }
3913
+ const ctor = classDecl.members.find(member => ts__default.default.isConstructorDeclaration(member));
3914
+ if (!ctor?.body) {
3915
+ classAutoBindCache.set(classDecl, false);
3916
+ return false;
3917
+ }
3918
+ for (const statement of ctor.body.statements) {
3919
+ if (!ts__default.default.isExpressionStatement(statement)) {
3920
+ continue;
3921
+ }
3922
+ const expr = statement.expression;
3923
+ if (!ts__default.default.isCallExpression(expr)) {
3924
+ continue;
3925
+ }
3926
+ if (!isMakeAutoObservableCallee(expr.expression)) {
3927
+ continue;
3928
+ }
3929
+ if (expr.arguments.length < 2) {
3930
+ continue;
3931
+ }
3932
+ if (expr.arguments[0].kind !== ts__default.default.SyntaxKind.ThisKeyword) {
3933
+ continue;
3934
+ }
3935
+ const hasAutoBind = expr.arguments.slice(1).some(arg => isAutoBindOption(arg));
3936
+ if (hasAutoBind) {
3937
+ classAutoBindCache.set(classDecl, true);
3938
+ return true;
3939
+ }
3940
+ }
3941
+ classAutoBindCache.set(classDecl, false);
3942
+ return false;
3943
+ };
3886
3944
  const resolveSymbol = symbol => {
3887
3945
  const cached = aliasCache.get(symbol);
3888
3946
  if (cached) {
@@ -3917,6 +3975,7 @@ const noUnboundMethod = createRule$4({
3917
3975
  return Boolean(name && decoratorNames.has(name));
3918
3976
  }));
3919
3977
  const info = {
3978
+ autoBind: hasAutoBindInConstructor(methodDecl.parent),
3920
3979
  hasDecorator,
3921
3980
  isStatic,
3922
3981
  usesThis: methodUsesThis(methodDecl)
@@ -3935,7 +3994,7 @@ const noUnboundMethod = createRule$4({
3935
3994
  reportCache.set(aliased, false);
3936
3995
  return false;
3937
3996
  }
3938
- const shouldReport = !info.isStatic && info.usesThis && !info.hasDecorator;
3997
+ const shouldReport = !info.autoBind && !info.isStatic && info.usesThis && !info.hasDecorator;
3939
3998
  reportCache.set(aliased, shouldReport);
3940
3999
  return shouldReport;
3941
4000
  };