@slip-stream-kit/eslint-plugin 0.1.13 → 0.1.17

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 CHANGED
@@ -113,6 +113,39 @@ var getComponentFunction = (node) => {
113
113
  }
114
114
  return null;
115
115
  };
116
+ var getAnnotatedParam = (param) => {
117
+ return param.type === "AssignmentPattern" ? param.left : param;
118
+ };
119
+ var getPropsTypeNameFromFunction = (node) => {
120
+ const firstParam = node.params[0];
121
+ if (!firstParam) {
122
+ return null;
123
+ }
124
+ const inner = getAnnotatedParam(firstParam).typeAnnotation?.typeAnnotation;
125
+ if (inner?.type !== "TSTypeReference" || inner.typeName?.type !== "Identifier") {
126
+ return null;
127
+ }
128
+ return inner.typeName.name ?? null;
129
+ };
130
+ var getComponentPropsTypeName = (node) => {
131
+ if (!node) {
132
+ return null;
133
+ }
134
+ if (node.type === "FunctionDeclaration") {
135
+ return isComponent(node) ? getPropsTypeNameFromFunction(node) : null;
136
+ }
137
+ if (node.type === "VariableDeclaration") {
138
+ for (const declaration of node.declarations) {
139
+ const fn2 = getComponentFunction(declaration.init);
140
+ if (fn2 && isComponent(fn2)) {
141
+ return getPropsTypeNameFromFunction(fn2);
142
+ }
143
+ }
144
+ return null;
145
+ }
146
+ const fn = getComponentFunction(node);
147
+ return fn && isComponent(fn) ? getPropsTypeNameFromFunction(fn) : null;
148
+ };
116
149
  var unwrapExport = (statement) => {
117
150
  if (statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration") {
118
151
  return statement.declaration ?? null;
@@ -297,7 +330,7 @@ var getDirectivePrologueCount = (body) => {
297
330
  }
298
331
  return count;
299
332
  };
300
- var getPropsTypeName = (node) => {
333
+ var getTypeDeclName = (node) => {
301
334
  if (!node) {
302
335
  return null;
303
336
  }
@@ -305,13 +338,12 @@ var getPropsTypeName = (node) => {
305
338
  if (named.type !== "TSInterfaceDeclaration" && named.type !== "TSTypeAliasDeclaration") {
306
339
  return null;
307
340
  }
308
- const name = named.id?.name;
309
- return name?.endsWith(PROPS_SUFFIX) ? name : null;
341
+ return named.id?.name ?? null;
310
342
  };
311
343
  var collectTopLevel = (body) => {
312
344
  const importIndices = [];
313
345
  const components = [];
314
- const propsIndexByName = /* @__PURE__ */ new Map();
346
+ const declIndexByName = /* @__PURE__ */ new Map();
315
347
  const importedNames = /* @__PURE__ */ new Set();
316
348
  body.forEach((statement, index) => {
317
349
  if (statement.type === "ImportDeclaration") {
@@ -322,15 +354,17 @@ var collectTopLevel = (body) => {
322
354
  return;
323
355
  }
324
356
  const declaration = unwrapExport(statement);
325
- const propsName = getPropsTypeName(declaration);
326
- if (propsName !== null && !propsIndexByName.has(propsName)) {
327
- propsIndexByName.set(propsName, index);
357
+ const declName = getTypeDeclName(declaration);
358
+ if (declName !== null && !declIndexByName.has(declName)) {
359
+ declIndexByName.set(declName, index);
328
360
  }
329
361
  if (declaresComponent(declaration)) {
330
- components.push({ index, name: getDeclaredComponentName(declaration) });
362
+ const name = getDeclaredComponentName(declaration);
363
+ const propsName = getComponentPropsTypeName(declaration) ?? (name === null ? null : `${name}${PROPS_SUFFIX}`);
364
+ components.push({ index, name, propsName });
331
365
  }
332
366
  });
333
- return { importIndices, components, propsIndexByName, importedNames };
367
+ return { importIndices, components, declIndexByName, importedNames };
334
368
  };
335
369
  var hasStrayBefore = (body, boundary, directiveCount, skipIndex) => {
336
370
  return body.some((statement, index) => {
@@ -344,13 +378,20 @@ var findImportOrderViolations = (importIndices, importBoundary) => {
344
378
  return { index: importIndex, messageId: "importsFirst" };
345
379
  });
346
380
  };
347
- var findAdjacencyViolations = (components, propsIndexByName) => {
381
+ var findAdjacencyViolations = (components, declIndexByName) => {
348
382
  const violations = [];
383
+ const referenceCount = /* @__PURE__ */ new Map();
349
384
  for (const component of components) {
350
- if (component.name === null) {
385
+ if (component.propsName !== null) {
386
+ referenceCount.set(component.propsName, (referenceCount.get(component.propsName) ?? 0) + 1);
387
+ }
388
+ }
389
+ for (const component of components) {
390
+ const propsName = component.propsName;
391
+ if (propsName === null || (referenceCount.get(propsName) ?? 0) > 1) {
351
392
  continue;
352
393
  }
353
- const propsIndex = propsIndexByName.get(`${component.name}${PROPS_SUFFIX}`);
394
+ const propsIndex = declIndexByName.get(propsName);
354
395
  if (propsIndex !== void 0 && propsIndex !== component.index - 1) {
355
396
  violations.push({ index: propsIndex, messageId: "interfaceImmediatelyBeforeComponent" });
356
397
  }
@@ -421,17 +462,17 @@ var componentFileOrder = {
421
462
  Program(program) {
422
463
  const body = program.body;
423
464
  const directiveCount = getDirectivePrologueCount(body);
424
- const { importIndices, components, propsIndexByName, importedNames } = collectTopLevel(body);
465
+ const { importIndices, components, declIndexByName, importedNames } = collectTopLevel(body);
425
466
  if (components.length === 0) {
426
467
  return;
427
468
  }
428
469
  const first = components[0];
429
- const firstPropsName = first.name === null ? null : `${first.name}${PROPS_SUFFIX}`;
430
- const firstPropsIndex = firstPropsName === null ? void 0 : propsIndexByName.get(firstPropsName);
470
+ const firstPropsName = first.propsName;
471
+ const firstPropsIndex = firstPropsName === null ? void 0 : declIndexByName.get(firstPropsName);
431
472
  const importBoundary = Math.min(first.index, firstPropsIndex ?? first.index);
432
473
  const violations = [
433
474
  ...findImportOrderViolations(importIndices, importBoundary),
434
- ...findAdjacencyViolations(components, propsIndexByName),
475
+ ...findAdjacencyViolations(components, declIndexByName),
435
476
  ...findAnchorViolations(
436
477
  body,
437
478
  directiveCount,
@@ -567,14 +608,12 @@ var propsDestructuringNewline = {
567
608
  }
568
609
  const boundNames = /* @__PURE__ */ new Set();
569
610
  collectBoundNames(firstParam, boundNames);
570
- if (boundNames.has("props")) {
571
- return;
572
- }
611
+ const bindsProps = boundNames.has("props");
573
612
  const objectPattern = firstParam;
574
613
  context.report({
575
614
  node: firstParam,
576
615
  messageId: "destructureOnNewLine",
577
- fix(fixer) {
616
+ fix: bindsProps ? void 0 : (fixer) => {
578
617
  const text = sourceCode.getText();
579
618
  const annotation = objectPattern.typeAnnotation;
580
619
  const patternStart = objectPattern.range[0];
@@ -626,11 +665,80 @@ ${baseIndent}}`
626
665
  }
627
666
  };
628
667
 
668
+ // src/rules/props-type-name.ts
669
+ var PROPS_SUFFIX2 = "Props";
670
+ var propsTypeName = {
671
+ meta: {
672
+ type: "suggestion",
673
+ docs: {
674
+ description: "Require a React component's props type to be named `<ComponentName>Props` (e.g. `ButtonProps` for `Button`).",
675
+ recommended: true,
676
+ url: "https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin"
677
+ },
678
+ schema: [
679
+ {
680
+ type: "object",
681
+ properties: {
682
+ paths: {
683
+ type: "array",
684
+ items: { type: "string" },
685
+ description: "Optional glob patterns. When provided, the rule only runs for files whose path matches one of them."
686
+ },
687
+ ignore: {
688
+ type: "array",
689
+ items: { type: "string" },
690
+ description: "Optional glob patterns. The rule is skipped for files whose path matches one of them, even if it also matches `paths`."
691
+ }
692
+ },
693
+ additionalProperties: false
694
+ }
695
+ ],
696
+ messages: {
697
+ propsTypeNameMismatch: "A component's props type must be named `{{expected}}`, but it is named `{{actual}}`."
698
+ }
699
+ },
700
+ create(context) {
701
+ const options = context.options[0] ?? {};
702
+ const paths = options.paths ?? [];
703
+ const ignore = options.ignore ?? [];
704
+ if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {
705
+ return {};
706
+ }
707
+ if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {
708
+ return {};
709
+ }
710
+ const check = (node) => {
711
+ if (!isComponent(node)) {
712
+ return;
713
+ }
714
+ const componentName = getComponentName(node);
715
+ if (componentName === null) {
716
+ return;
717
+ }
718
+ const actual = getPropsTypeNameFromFunction(node);
719
+ if (actual === null) {
720
+ return;
721
+ }
722
+ const expected = `${componentName}${PROPS_SUFFIX2}`;
723
+ if (actual === expected) {
724
+ return;
725
+ }
726
+ context.report({
727
+ node: getAnnotatedParam(node.params[0]),
728
+ messageId: "propsTypeNameMismatch",
729
+ data: { expected, actual }
730
+ });
731
+ };
732
+ return {
733
+ ArrowFunctionExpression: check,
734
+ FunctionDeclaration: check,
735
+ FunctionExpression: check
736
+ };
737
+ }
738
+ };
739
+
629
740
  // src/rules/props-type-reference.ts
630
741
  var INLINE_OBJECT_TYPE = "TSTypeLiteral";
631
- var getAnnotatedParam = (param) => {
632
- return param.type === "AssignmentPattern" ? param.left : param;
633
- };
634
742
  var propsTypeReference = {
635
743
  meta: {
636
744
  type: "suggestion",
@@ -901,6 +1009,7 @@ var rules = {
901
1009
  "props-destructuring-newline": propsDestructuringNewline,
902
1010
  "props-destructuring-blank-line": propsDestructuringBlankLine,
903
1011
  "props-type-reference": propsTypeReference,
1012
+ "props-type-name": propsTypeName,
904
1013
  "component-file-order": componentFileOrder,
905
1014
  "component-arrow-function": componentArrowFunction,
906
1015
  "require-component-stories": requireComponentStories
@@ -911,7 +1020,7 @@ var PLUGIN_NAME = "@wl";
911
1020
  var plugin = {
912
1021
  meta: {
913
1022
  name: "@wl/eslint-plugin",
914
- version: "0.1.11"
1023
+ version: "0.1.14"
915
1024
  },
916
1025
  rules,
917
1026
  configs: {}
@@ -926,6 +1035,7 @@ plugin.configs.recommended = [
926
1035
  [`${PLUGIN_NAME}/props-destructuring-newline`]: "error",
927
1036
  [`${PLUGIN_NAME}/props-destructuring-blank-line`]: "error",
928
1037
  [`${PLUGIN_NAME}/props-type-reference`]: "error",
1038
+ [`${PLUGIN_NAME}/props-type-name`]: "error",
929
1039
  [`${PLUGIN_NAME}/component-file-order`]: "error",
930
1040
  // Pages and routes are excluded: route/page modules commonly use `function`
931
1041
  // declarations (and framework conventions like default-exported page functions).
@@ -933,13 +1043,17 @@ plugin.configs.recommended = [
933
1043
  [`${PLUGIN_NAME}/require-component-stories`]: "error"
934
1044
  }
935
1045
  },
936
- // Storybook stories legitimately deviate from the imports *Props → component
937
- // order (meta/args/decorators/render fns), so component-file-order would only
938
- // produce noise there. Every other rule stays enabled for story files.
1046
+ // Storybook stories legitimately deviate from the component conventions: the
1047
+ // imports → *Props → component order (meta/args/decorators/render fns), and
1048
+ // named templates that reference the *component's* props type (e.g.
1049
+ // `const Template = (args: ButtonProps) => ...`) rather than their own
1050
+ // `<TemplateName>Props`. So both the ordering and the props-type-name rules
1051
+ // would only produce noise there. Every other rule stays enabled for stories.
939
1052
  {
940
1053
  files: ["**/*.stories.{ts,tsx}"],
941
1054
  rules: {
942
- [`${PLUGIN_NAME}/component-file-order`]: "off"
1055
+ [`${PLUGIN_NAME}/component-file-order`]: "off",
1056
+ [`${PLUGIN_NAME}/props-type-name`]: "off"
943
1057
  }
944
1058
  }
945
1059
  ];
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/utils/component.ts", "../src/utils/path-match.ts", "../src/rules/component-arrow-function.ts", "../src/rules/component-file-order.ts", "../src/rules/props-destructuring-blank-line.ts", "../src/rules/props-destructuring-newline.ts", "../src/rules/props-type-reference.ts", "../src/rules/require-component-stories.ts", "../src/utils/story-path.ts", "../src/rules/index.ts", "../src/index.ts"],
4
- "sourcesContent": ["import type * as ESTree from 'estree'\n\nexport type ComponentFunction = ESTree.ArrowFunctionExpression | ESTree.FunctionDeclaration | ESTree.FunctionExpression\n\n// Minimal structural view over the `parent` back-reference ESLint adds to every node.\ninterface WithParent {\n parent?: ESTree.Node\n}\n\n// Calls that wrap a component while preserving its identity (memo, forwardRef, observer, ...).\nconst COMPONENT_WRAPPER_CALLEES = new Set(['memo', 'forwardRef', 'observer', 'React.memo', 'React.forwardRef'])\n\n// Node types that introduce a new function scope \u2014 their returns are not the outer component's.\nconst NESTED_SCOPES = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression'])\n\nconst isPascalCase = (name: string): boolean => {\n return /^[A-Z]/.test(name)\n}\n\nconst isJsxNode = (node: ESTree.Node | null | undefined): boolean => {\n if (!node) {\n return false\n }\n\n const type = node.type as string\n\n return type === 'JSXElement' || type === 'JSXFragment'\n}\n\nconst getParent = (node: ESTree.Node | undefined): ESTree.Node | undefined => {\n return (node as (WithParent & ESTree.Node) | undefined)?.parent\n}\n\n/** Best-effort name of a call's callee: `memo` for `memo(...)`, `React.memo` for `React.memo(...)`. */\nconst getCalleeName = (callee: ESTree.CallExpression['callee']): string | null => {\n if (callee.type === 'Identifier') {\n return callee.name\n }\n\n if (\n callee.type === 'MemberExpression' &&\n callee.object.type === 'Identifier' &&\n callee.property.type === 'Identifier'\n ) {\n return `${callee.object.name}.${callee.property.name}`\n }\n\n return null\n}\n\n/**\n * Resolve the declared name of a function, looking through component wrappers\n * such as `memo`/`forwardRef` so that `const Comp = memo(({ a }) => ...)` is\n * still recognised by its PascalCase variable name.\n */\nexport const getComponentName = (node: ComponentFunction): string | null => {\n if (node.type === 'FunctionDeclaration') {\n return node.id?.name ?? null\n }\n\n let current = getParent(node)\n\n // Walk through wrapping call expressions (memo, forwardRef, React.memo, ...).\n while (current?.type === 'CallExpression') {\n const calleeName = getCalleeName(current.callee)\n\n if (!calleeName || !COMPONENT_WRAPPER_CALLEES.has(calleeName)) {\n break\n }\n\n current = getParent(current)\n }\n\n if (current?.type === 'VariableDeclarator' && current.id.type === 'Identifier') {\n return current.id.name\n }\n\n return null\n}\n\n/** Whether a function returns JSX, scanning its own body without descending into nested functions. */\nconst returnsJsx = (node: ComponentFunction): boolean => {\n if (node.body.type !== 'BlockStatement') {\n return isJsxNode(node.body)\n }\n\n let found = false\n\n const visit = (current: ESTree.Node | null | undefined): void => {\n if (found || !current || NESTED_SCOPES.has(current.type)) {\n return\n }\n\n if (current.type === 'ReturnStatement') {\n if (isJsxNode(current.argument)) {\n found = true\n }\n\n return\n }\n\n if (current.type === 'IfStatement') {\n visit(current.consequent)\n visit(current.alternate)\n\n return\n }\n\n if (current.type === 'BlockStatement') {\n current.body.forEach(visit)\n\n return\n }\n\n if (current.type === 'SwitchStatement') {\n for (const switchCase of current.cases) {\n switchCase.consequent.forEach(visit)\n }\n\n return\n }\n\n if (current.type === 'TryStatement') {\n visit(current.block)\n visit(current.handler?.body)\n visit(current.finalizer)\n\n return\n }\n\n if (\n current.type === 'ForStatement' ||\n current.type === 'ForInStatement' ||\n current.type === 'ForOfStatement' ||\n current.type === 'WhileStatement' ||\n current.type === 'DoWhileStatement'\n ) {\n visit(current.body)\n }\n }\n\n node.body.body.forEach(visit)\n\n return found\n}\n\n/** A function is treated as a React component when it is PascalCase-named or returns JSX. */\nexport const isComponent = (node: ComponentFunction): boolean => {\n const name = getComponentName(node)\n\n if (name && isPascalCase(name)) {\n return true\n }\n\n return returnsJsx(node)\n}\n\nconst isComponentFunctionNode = (node: ESTree.Node): node is ComponentFunction => {\n return (\n node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration'\n )\n}\n\n/**\n * Extract the component function from an expression, unwrapping a single layer of\n * component wrappers (`memo(fn)`, `forwardRef(fn)`, `React.memo(fn)`, ...). Returns\n * null when no function is found.\n */\nexport const getComponentFunction = (node: ESTree.Node | null | undefined): ComponentFunction | null => {\n if (!node) {\n return null\n }\n\n if (isComponentFunctionNode(node)) {\n return node\n }\n\n if (node.type === 'CallExpression') {\n for (const argument of node.arguments) {\n if (argument.type === 'SpreadElement') {\n continue\n }\n\n const found = getComponentFunction(argument)\n\n if (found) {\n return found\n }\n }\n }\n\n return null\n}\n\n/** Unwrap an `export ...` statement to the declaration it wraps (or the statement itself). */\nexport const unwrapExport = (statement: ESTree.Statement | ESTree.ModuleDeclaration): ESTree.Node | null => {\n if (statement.type === 'ExportNamedDeclaration' || statement.type === 'ExportDefaultDeclaration') {\n return (statement.declaration as ESTree.Node | null) ?? null\n }\n\n return statement\n}\n\n/** Whether a single top-level declaration declares a React component. */\nexport const declaresComponent = (node: ESTree.Node | null): boolean => {\n if (!node) {\n return false\n }\n\n if (node.type === 'FunctionDeclaration') {\n return isComponent(node)\n }\n\n if (node.type === 'VariableDeclaration') {\n return node.declarations.some((declaration) => {\n const fn = getComponentFunction(declaration.init)\n\n return fn ? isComponent(fn) : false\n })\n }\n\n const fn = getComponentFunction(node)\n\n return fn ? isComponent(fn) : false\n}\n\n/**\n * Resolve the name of the React component declared by a single top-level declaration,\n * or null when the declaration is not a component or the component is anonymous\n * (e.g. `export default () => <div />`). Mirrors `declaresComponent`'s node dispatch and\n * resolves the name through component wrappers (`memo`/`forwardRef`).\n */\nexport const getDeclaredComponentName = (node: ESTree.Node | null): string | null => {\n if (!node) {\n return null\n }\n\n if (node.type === 'FunctionDeclaration') {\n return isComponent(node) ? getComponentName(node) : null\n }\n\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n const fn = getComponentFunction(declaration.init)\n\n if (fn && isComponent(fn)) {\n return getComponentName(fn)\n }\n }\n\n return null\n }\n\n const fn = getComponentFunction(node)\n\n return fn && isComponent(fn) ? getComponentName(fn) : null\n}\n\n/** Whether any top-level statement in a program body declares a React component. */\nexport const bodyDeclaresComponent = (body: Array<ESTree.Statement | ESTree.ModuleDeclaration>): boolean => {\n return body.some((statement) => {\n return declaresComponent(unwrapExport(statement))\n })\n}\n", "// Characters that must be escaped when embedded literally into a RegExp source.\nconst REGEX_METACHARS = new Set(['\\\\', '^', '$', '.', '|', '+', '(', ')', '[', ']', '{', '}'])\n\n/**\n * Convert a glob pattern to an (unanchored) RegExp.\n *\n * - `**` matches any characters, including path separators.\n * - `*` matches any characters except a path separator.\n * - `?` matches a single non-separator character.\n *\n * The result is intentionally unanchored so a pattern matches anywhere in the\n * path (e.g. `features/**` matches `/repo/src/features/x/comp.tsx`).\n */\nconst globToRegExp = (glob: string): RegExp => {\n let source = ''\n\n for (let index = 0; index < glob.length; index++) {\n const char = glob[index]!\n\n if (char === '*') {\n if (glob[index + 1] === '*') {\n source += '.*'\n index++\n\n // Consume a trailing slash so `**/foo` also matches a bare `foo`.\n if (glob[index + 1] === '/') {\n index++\n }\n } else {\n source += '[^/]*'\n }\n } else if (char === '?') {\n source += '[^/]'\n } else if (REGEX_METACHARS.has(char)) {\n source += `\\\\${char}`\n } else {\n source += char\n }\n }\n\n return new RegExp(source)\n}\n\n/** Whether `filename` matches at least one of the provided glob `patterns`. */\nexport const matchesAnyGlob = (filename: string, patterns: readonly string[]): boolean => {\n const normalized = filename.split('\\\\').join('/')\n\n return patterns.some((pattern) => {\n return globToRegExp(pattern).test(normalized)\n })\n}\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport { getComponentFunction, getComponentName, isComponent, unwrapExport } from '../utils/component'\nimport type { ComponentFunction } from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n}\n\n// Fallback used when a component is anonymous (e.g. `export default memo(function () { ... })`),\n// since `getComponentName` returns null rather than a placeholder in that case.\nconst ANONYMOUS_NAME = 'component'\n\ntype MessageId = 'functionDeclaration' | 'functionExpression'\n\ninterface Violation {\n node: ESTree.Node\n messageId: MessageId\n name: string\n}\n\nconst reportName = (fn: ComponentFunction): string => {\n return getComponentName(fn) ?? ANONYMOUS_NAME\n}\n\n/**\n * Violation for a single non-`VariableDeclaration` top-level declaration:\n * - a `function Foo() {}` component declaration (incl. exported/default/anonymous), or\n * - an expression that resolves to a function-expression component\n * (e.g. `export default memo(function () { ... })`).\n */\nconst nonVariableViolation = (declaration: ESTree.Node): Violation | null => {\n if (declaration.type === 'FunctionDeclaration') {\n return isComponent(declaration)\n ? { node: declaration, messageId: 'functionDeclaration', name: reportName(declaration) }\n : null\n }\n\n const fn = getComponentFunction(declaration)\n\n return fn?.type === 'FunctionExpression' && isComponent(fn)\n ? { node: fn, messageId: 'functionExpression', name: reportName(fn) }\n : null\n}\n\n/** Function-expression component violations across every declarator in a `const`/`let`/`var`. */\nconst variableViolations = (declaration: ESTree.VariableDeclaration): Violation[] => {\n const violations: Violation[] = []\n\n for (const declarator of declaration.declarations) {\n const fn = getComponentFunction(declarator.init)\n\n if (fn?.type === 'FunctionExpression' && isComponent(fn)) {\n violations.push({ node: declarator, messageId: 'functionExpression', name: reportName(fn) })\n }\n }\n\n return violations\n}\n\n/** Every non-arrow component declared at the top level of the program body. */\nconst collectViolations = (body: Array<ESTree.Statement | ESTree.ModuleDeclaration>): Violation[] => {\n const violations: Violation[] = []\n\n for (const statement of body) {\n const declaration = unwrapExport(statement)\n\n if (!declaration) {\n continue\n }\n\n if (declaration.type === 'VariableDeclaration') {\n violations.push(...variableViolations(declaration))\n\n continue\n }\n\n const violation = nonVariableViolation(declaration)\n\n if (violation) {\n violations.push(violation)\n }\n }\n\n return violations\n}\n\nexport const componentArrowFunction: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Enforce that React components are declared as arrow functions, not `function` declarations or function expressions.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. When provided, the rule only runs for files whose path matches one of them.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. The rule is skipped for files whose path matches one of them, even if it also matches `paths`. Use this to exclude pages and routes (e.g. `**/pages/**`, `**/routes/**`).',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n functionDeclaration:\n 'React components must be arrow functions; convert the `function {{name}}` declaration to `const {{name}} = () => { \u2026 }`.',\n functionExpression:\n 'React components must be arrow functions; replace the `function` expression for `{{name}}` with an arrow function.',\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n return {\n Program(program) {\n for (const { node, messageId, name } of collectViolations(program.body)) {\n context.report({ node, messageId, data: { name } })\n }\n },\n }\n },\n}\n\nexport default componentArrowFunction\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport { declaresComponent, getDeclaredComponentName, unwrapExport } from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n}\n\n// TS-only nodes are not modelled by estree; access their identifier structurally.\ninterface NamedDeclaration {\n type: string\n id?: { name?: string } | null\n}\n\nconst PROPS_SUFFIX = 'Props'\n\n/**\n * Count the directive prologue \u2014 the leading run of string-literal expression statements\n * (`'use client'`, `'use server'`, `'use strict'`) at the top of the file. They are\n * legitimate file-leading content (like imports) and must not count as \"stray\" before the\n * props interface. Per the ECMAScript spec a directive is only one that *precedes* any other\n * statement, so we stop at the first non-string-literal statement rather than matching any\n * bare string anywhere in the body.\n */\nconst getDirectivePrologueCount = (body: Array<ESTree.Statement | ESTree.ModuleDeclaration>): number => {\n let count = 0\n\n for (const statement of body) {\n const isStringExpression =\n statement.type === 'ExpressionStatement' &&\n statement.expression.type === 'Literal' &&\n typeof statement.expression.value === 'string'\n\n if (!isStringExpression) {\n break\n }\n\n count += 1\n }\n\n return count\n}\n\n/** The name of a props interface/type alias (`SomethingProps`), or null when it is neither. */\nconst getPropsTypeName = (node: ESTree.Node | null): string | null => {\n if (!node) {\n return null\n }\n\n const named = node as NamedDeclaration\n\n if (named.type !== 'TSInterfaceDeclaration' && named.type !== 'TSTypeAliasDeclaration') {\n return null\n }\n\n const name = named.id?.name\n\n return name?.endsWith(PROPS_SUFFIX) ? name : null\n}\n\ninterface ComponentRef {\n index: number\n name: string | null\n}\n\ninterface TopLevel {\n importIndices: number[]\n components: ComponentRef[]\n // First index of each `*Props` declaration, keyed by its name.\n propsIndexByName: Map<string, number>\n // Local binding names introduced by imports \u2014 used to detect a props type that is\n // imported (e.g. `import type { CompProps }`) rather than declared in the file.\n importedNames: Set<string>\n}\n\n/** Classify each top-level statement into imports, components, local props types, and import bindings. */\nconst collectTopLevel = (body: Array<ESTree.Statement | ESTree.ModuleDeclaration>): TopLevel => {\n const importIndices: number[] = []\n const components: ComponentRef[] = []\n const propsIndexByName = new Map<string, number>()\n const importedNames = new Set<string>()\n\n body.forEach((statement, index) => {\n if (statement.type === 'ImportDeclaration') {\n importIndices.push(index)\n\n for (const specifier of statement.specifiers) {\n importedNames.add(specifier.local.name)\n }\n\n return\n }\n\n const declaration = unwrapExport(statement)\n\n const propsName = getPropsTypeName(declaration)\n\n if (propsName !== null && !propsIndexByName.has(propsName)) {\n propsIndexByName.set(propsName, index)\n }\n\n if (declaresComponent(declaration)) {\n components.push({ index, name: getDeclaredComponentName(declaration) })\n }\n })\n\n return { importIndices, components, propsIndexByName, importedNames }\n}\n\n/**\n * Whether any top-level statement in the half-open range `[directiveCount, boundary)` is a stray \u2014\n * i.e. not an import and not part of the leading directive prologue. `skipIndex` excludes a single\n * known-good statement (the component itself, when scanning the gap before its props interface).\n */\nconst hasStrayBefore = (\n body: Array<ESTree.Statement | ESTree.ModuleDeclaration>,\n boundary: number,\n directiveCount: number,\n skipIndex?: number,\n): boolean => {\n return body.some((statement, index) => {\n return index < boundary && index >= directiveCount && index !== skipIndex && statement.type !== 'ImportDeclaration'\n })\n}\n\ntype MessageId =\n | 'importsFirst'\n | 'interfaceImmediatelyBeforeComponent'\n | 'interfaceImmediatelyAfterImports'\n | 'componentImmediatelyAfterImports'\n\n// A pending report, expressed as a body index plus the message to raise against it.\ninterface Violation {\n index: number\n messageId: MessageId\n}\n\n/** Imports that sit after the first component (or its props interface) must move up. */\nconst findImportOrderViolations = (importIndices: number[], importBoundary: number): Violation[] => {\n return importIndices\n .filter((importIndex) => {\n return importIndex > importBoundary\n })\n .map((importIndex) => {\n return { index: importIndex, messageId: 'importsFirst' }\n })\n}\n\n/**\n * Each component's own `<Name>Props` interface, when present, must sit immediately before the\n * component. Matching by name keeps a sibling component's props from being judged against this one.\n */\nconst findAdjacencyViolations = (components: ComponentRef[], propsIndexByName: Map<string, number>): Violation[] => {\n const violations: Violation[] = []\n\n for (const component of components) {\n if (component.name === null) {\n continue\n }\n\n const propsIndex = propsIndexByName.get(`${component.name}${PROPS_SUFFIX}`)\n\n if (propsIndex !== undefined && propsIndex !== component.index - 1) {\n violations.push({ index: propsIndex, messageId: 'interfaceImmediatelyBeforeComponent' })\n }\n }\n\n return violations\n}\n\n/**\n * The first component is anchored to the import block: no stray top-level definition may wedge\n * between the imports and the props interface \u2014 or, when the props type is *imported* rather than\n * declared in the file, between the imports and the component itself. Only the first component is\n * anchored; later interfaces are governed solely by the adjacency check. Each `every` guard skips\n * when an import sits after its anchor, since that misorder is already reported by `importsFirst`.\n */\nconst findAnchorViolations = (\n body: Array<ESTree.Statement | ESTree.ModuleDeclaration>,\n directiveCount: number,\n importIndices: number[],\n first: ComponentRef,\n firstPropsName: string | null,\n firstPropsIndex: number | undefined,\n importedNames: Set<string>,\n): Violation[] => {\n const violations: Violation[] = []\n\n const importsBeforeInterface =\n firstPropsIndex !== undefined &&\n importIndices.every((importIndex) => {\n return importIndex < firstPropsIndex\n })\n\n if (importsBeforeInterface && hasStrayBefore(body, firstPropsIndex!, directiveCount, first.index)) {\n violations.push({ index: firstPropsIndex!, messageId: 'interfaceImmediatelyAfterImports' })\n }\n\n const firstPropsImported =\n firstPropsIndex === undefined && firstPropsName !== null && importedNames.has(firstPropsName)\n const importsBeforeComponent = importIndices.every((importIndex) => {\n return importIndex < first.index\n })\n\n if (firstPropsImported && importsBeforeComponent && hasStrayBefore(body, first.index, directiveCount)) {\n violations.push({ index: first.index, messageId: 'componentImmediatelyAfterImports' })\n }\n\n return violations\n}\n\nexport const componentFileOrder: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Enforce a strict top-level order in React component files: imports first, then \u2014 for each component \u2014 its props interface/type declared immediately before the component.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. When provided, the rule only runs for files whose path matches one of them.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. The rule is skipped for files whose path matches one of them, even if it also matches `paths`.',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n importsFirst: 'Imports must come before the component interface and declaration.',\n interfaceImmediatelyBeforeComponent:\n 'The component props interface must be declared immediately before the component.',\n interfaceImmediatelyAfterImports:\n 'The component props interface must be declared immediately after the imports, with no other declarations in between.',\n componentImmediatelyAfterImports:\n 'When the component props type is imported, the component must be declared immediately after the imports, with no other declarations in between.',\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n return {\n Program(program) {\n const body = program.body\n\n // Leading directive prologue (`'use client'`, ...) \u2014 excluded from the stray checks.\n const directiveCount = getDirectivePrologueCount(body)\n\n const { importIndices, components, propsIndexByName, importedNames } = collectTopLevel(body)\n\n // The rule only governs files that actually contain a component.\n if (components.length === 0) {\n return\n }\n\n const first = components[0]!\n const firstPropsName = first.name === null ? null : `${first.name}${PROPS_SUFFIX}`\n const firstPropsIndex = firstPropsName === null ? undefined : propsIndexByName.get(firstPropsName)\n // `importBoundary` is intentionally directive-insensitive: a leading directive prologue\n // shifts every subsequent index up uniformly, so it never crosses this boundary. The\n // prologue is excluded only from the stray checks, where the raw index matters.\n const importBoundary = Math.min(first.index, firstPropsIndex ?? first.index)\n\n const violations = [\n ...findImportOrderViolations(importIndices, importBoundary),\n ...findAdjacencyViolations(components, propsIndexByName),\n ...findAnchorViolations(\n body,\n directiveCount,\n importIndices,\n first,\n firstPropsName,\n firstPropsIndex,\n importedNames,\n ),\n ]\n\n for (const violation of violations) {\n context.report({ node: body[violation.index]!, messageId: violation.messageId })\n }\n },\n }\n },\n}\n\nexport default componentFileOrder\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport type { ComponentFunction } from '../utils/component'\nimport { isComponent } from '../utils/component'\n\n/** Whether a statement is `const { ... } = props` (destructuring the `props` identifier). */\nconst isPropsDestructuring = (statement: ESTree.Statement): boolean => {\n if (statement.type !== 'VariableDeclaration') {\n return false\n }\n\n return statement.declarations.some((declaration) => {\n return (\n declaration.id.type === 'ObjectPattern' &&\n declaration.init?.type === 'Identifier' &&\n declaration.init.name === 'props'\n )\n })\n}\n\nexport const propsDestructuringBlankLine: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Require a blank line after the `const { ... } = props` destructuring statement at the top of a React component body.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n fixable: 'whitespace',\n schema: [],\n messages: {\n blankLineAfterProps: 'Add a blank line after destructuring props.',\n },\n },\n\n create(context) {\n const sourceCode = context.sourceCode\n\n const check = (node: ComponentFunction): void => {\n if (node.body.type !== 'BlockStatement') {\n return\n }\n\n if (!isComponent(node)) {\n return\n }\n\n const statements = node.body.body\n const index = statements.findIndex(isPropsDestructuring)\n\n if (index === -1) {\n return\n }\n\n const propsStatement = statements[index]\n const nextStatement = statements[index + 1]\n\n // `propsStatement` is defined because `index !== -1`; the guard also narrows the type.\n // Nothing follows the destructuring \u2014 no separation needed.\n if (!propsStatement || !nextStatement) {\n return\n }\n\n // The token/comment that follows the destructuring statement; a comment on the\n // next line still counts as \"no blank line\" until it is pushed down.\n const tokenAfter = sourceCode.getTokenAfter(propsStatement, { includeComments: true })\n const referenceLine = (tokenAfter ?? nextStatement).loc!.start.line\n\n if (referenceLine - propsStatement.loc!.end.line >= 2) {\n return\n }\n\n context.report({\n node: propsStatement,\n messageId: 'blankLineAfterProps',\n fix(fixer) {\n return fixer.insertTextAfter(propsStatement, '\\n')\n },\n })\n }\n\n return {\n ArrowFunctionExpression: check,\n FunctionDeclaration: check,\n FunctionExpression: check,\n }\n },\n}\n\nexport default propsDestructuringBlankLine\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport type { ComponentFunction } from '../utils/component'\nimport { isComponent } from '../utils/component'\n\n// Minimal structural views over nodes that estree's types do not fully model:\n// the optional TS type annotation and `range` that the parser attaches to params.\ninterface WithRange {\n range?: [number, number]\n}\ntype AnnotatedPattern = ESTree.ObjectPattern & { typeAnnotation?: ESTree.Node & WithRange } & WithRange\n\n// Recursively collect every identifier a destructuring pattern binds, so we can detect\n// whether it already introduces a `props` binding (e.g. a `...props` rest).\nconst collectBoundNames = (node: ESTree.Node | null, names: Set<string>): void => {\n if (!node) {\n return\n }\n\n switch (node.type) {\n case 'Identifier':\n names.add(node.name)\n break\n case 'ObjectPattern':\n for (const property of node.properties) collectBoundNames(property, names)\n break\n case 'ArrayPattern':\n for (const element of node.elements) collectBoundNames(element, names)\n break\n case 'Property':\n collectBoundNames(node.value, names)\n break\n case 'RestElement':\n collectBoundNames(node.argument, names)\n break\n case 'AssignmentPattern':\n collectBoundNames(node.left, names)\n break\n default:\n break\n }\n}\n\nexport const propsDestructuringNewline: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Require React components to accept a single props parameter and destructure it on its own line in the body, rather than destructuring inline in the parameter list.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n fixable: 'code',\n schema: [],\n messages: {\n destructureOnNewLine:\n 'Accept a single `props` parameter and destructure it on its own line in the component body instead of destructuring in the parameter list.',\n },\n },\n\n create(context) {\n const sourceCode = context.sourceCode\n\n const check = (node: ComponentFunction): void => {\n const firstParam = node.params[0]\n\n if (!firstParam || firstParam.type !== 'ObjectPattern') {\n return\n }\n\n if (!isComponent(node)) {\n return\n }\n\n // The fix renames the parameter to `props` and re-destructures it in the body\n // (`const <pattern> = props`). If the pattern already binds `props` (e.g. a\n // `...props` rest), that body binding collides with the new parameter and yields\n // an invalid \"Duplicate declaration props\". There is no safe rename that keeps the\n // `props` name the rule mandates, so skip these patterns entirely.\n const boundNames = new Set<string>()\n\n collectBoundNames(firstParam, boundNames)\n\n if (boundNames.has('props')) {\n return\n }\n\n const objectPattern = firstParam as AnnotatedPattern\n\n context.report({\n node: firstParam,\n messageId: 'destructureOnNewLine',\n fix(fixer) {\n const text = sourceCode.getText()\n const annotation = objectPattern.typeAnnotation\n\n const patternStart = objectPattern.range![0]\n const patternEnd = annotation ? annotation.range![0] : objectPattern.range![1]\n const fullEnd = annotation ? annotation.range![1] : objectPattern.range![1]\n\n const patternText = text.slice(patternStart, patternEnd).trim()\n const annotationText = annotation ? sourceCode.getText(annotation) : ''\n\n const fixes = [fixer.replaceTextRange([patternStart, fullEnd], `props${annotationText}`)]\n\n const destructureStatement = `const ${patternText} = props`\n\n // Indentation of the line the component is declared on, used as the base for inserted code.\n const lines = sourceCode.getLines()\n const declarationLine = lines[node.loc!.start.line - 1] ?? ''\n const baseIndent = declarationLine.slice(0, declarationLine.length - declarationLine.trimStart().length)\n const innerIndent = `${baseIndent} `\n\n if (node.body.type === 'BlockStatement') {\n const [firstStatement] = node.body.body\n\n if (firstStatement) {\n const indent = ' '.repeat(firstStatement.loc!.start.column)\n\n fixes.push(fixer.insertTextBefore(firstStatement, `${destructureStatement}\\n\\n${indent}`))\n } else {\n const openBrace = sourceCode.getFirstToken(node.body)!\n\n fixes.push(fixer.insertTextAfter(openBrace, `\\n${innerIndent}${destructureStatement}\\n${baseIndent}`))\n }\n\n return fixes\n }\n\n // Expression-bodied arrow (implicit return) \u2014 wrap it in a block.\n const bodyText = sourceCode.getText(node.body)\n\n fixes.push(\n fixer.replaceText(\n node.body,\n `{\\n${innerIndent}${destructureStatement}\\n\\n${innerIndent}return ${bodyText}\\n${baseIndent}}`,\n ),\n )\n\n return fixes\n },\n })\n }\n\n return {\n ArrowFunctionExpression: check,\n FunctionDeclaration: check,\n FunctionExpression: check,\n }\n },\n}\n\nexport default propsDestructuringNewline\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport type { ComponentFunction } from '../utils/component'\nimport { getComponentName, isComponent } from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n}\n\n// TS-only nodes are not modelled by estree, so we view them through a minimal two-level\n// structural interface: the `TSTypeAnnotation` wrapper a parser attaches to a parameter, and\n// its inner type node. An inline object type is `TSTypeLiteral`; a named type is `TSTypeReference`.\ninterface AnnotatedNode {\n typeAnnotation?: {\n typeAnnotation?: { type?: string }\n }\n}\n\nconst INLINE_OBJECT_TYPE = 'TSTypeLiteral'\n\n/**\n * The parameter that actually carries the props type annotation. A default value wraps the\n * parameter in an `AssignmentPattern` (`(props: { x } = {})`), moving the annotation onto its\n * `.left`; unwrap one layer so the inline-type check sees the annotated binding either way.\n */\nconst getAnnotatedParam = (param: ESTree.Pattern): ESTree.Pattern => {\n return param.type === 'AssignmentPattern' ? param.left : param\n}\n\nexport const propsTypeReference: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n \"Require a React component's props parameter to use a named type (e.g. `ButtonProps`) instead of an inline object type literal.\",\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. When provided, the rule only runs for files whose path matches one of them.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. The rule is skipped for files whose path matches one of them, even if it also matches `paths`.',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n useNamedPropsType:\n \"Use a named props type (e.g. `{{name}}Props`) instead of an inline object type for this component's props.\",\n useNamedPropsTypeAnonymous: \"Use a named props type instead of an inline object type for this component's props.\",\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n const check = (node: ComponentFunction): void => {\n const firstParam = node.params[0]\n\n if (!firstParam || !isComponent(node)) {\n return\n }\n\n const annotatedParam = getAnnotatedParam(firstParam)\n const innerType = (annotatedParam as AnnotatedNode).typeAnnotation?.typeAnnotation?.type\n\n if (innerType !== INLINE_OBJECT_TYPE) {\n return\n }\n\n const name = getComponentName(node)\n\n context.report(\n name === null\n ? { node: annotatedParam, messageId: 'useNamedPropsTypeAnonymous' }\n : { node: annotatedParam, messageId: 'useNamedPropsType', data: { name } },\n )\n }\n\n return {\n ArrowFunctionExpression: check,\n FunctionDeclaration: check,\n FunctionExpression: check,\n }\n },\n}\n\nexport default propsTypeReference\n", "import type { Rule } from 'eslint'\nimport { existsSync } from 'node:fs'\nimport path from 'node:path'\n\nimport { bodyDeclaresComponent } from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\nimport type { ExtraTarget, StoryPathOptions } from '../utils/story-path'\nimport { DEFAULT_STORY_PATH_OPTIONS, classifyComponent, deriveExpectedStoryPaths } from '../utils/story-path'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n storiesDir?: string\n storySuffix?: string\n storyExtensions?: string[]\n componentSuffix?: string\n requireComponentAst?: boolean\n extraTargets?: ExtraTarget[]\n}\n\n/** Pick the story-path knobs out of the rule options, leaving defaults to the helper. */\nconst toStoryPathOptions = (options: Options): Partial<StoryPathOptions> => {\n const picked: Partial<StoryPathOptions> = {}\n\n if (options.storiesDir !== undefined) {\n picked.storiesDir = options.storiesDir\n }\n\n if (options.storySuffix !== undefined) {\n picked.storySuffix = options.storySuffix\n }\n\n if (options.storyExtensions !== undefined) {\n picked.storyExtensions = options.storyExtensions\n }\n\n if (options.componentSuffix !== undefined) {\n picked.componentSuffix = options.componentSuffix\n }\n\n if (options.extraTargets !== undefined) {\n picked.extraTargets = options.extraTargets\n }\n\n return picked\n}\n\nexport const requireComponentStories: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: {\n description: 'Require a co-located Storybook story for every dumb component.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description: 'Optional globs; when provided the rule only runs for files whose path matches one.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description: 'Optional globs; the rule is skipped for matching files, even if they also match `paths`.',\n },\n storiesDir: {\n type: 'string',\n description: `Story directory name (default '${DEFAULT_STORY_PATH_OPTIONS.storiesDir}').`,\n },\n storySuffix: {\n type: 'string',\n description: `Suffix inserted before the extension (default '${DEFAULT_STORY_PATH_OPTIONS.storySuffix}').`,\n },\n storyExtensions: {\n type: 'array',\n items: { type: 'string' },\n description: 'Extensions a satisfying story file may have, in priority order.',\n },\n componentSuffix: {\n type: 'string',\n description: `Basename suffix a component file must end with (default '${DEFAULT_STORY_PATH_OPTIONS.componentSuffix}'; '' disables).`,\n },\n requireComponentAst: {\n type: 'boolean',\n description: 'When true (default), only require a story for files that actually declare a component.',\n },\n extraTargets: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n componentsDir: { type: 'string' },\n anchorParentDir: { type: 'string' },\n storyMode: { enum: ['feature-root', 'sibling'] },\n },\n required: ['componentsDir', 'storyMode'],\n additionalProperties: false,\n },\n description: 'Extra structured component layouts (componentsDir + optional anchorParentDir + storyMode).',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n missingStory: \"Dumb component '{{component}}' is missing a Storybook story (expected at '{{expected}}').\",\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n const requireComponentAst = options.requireComponentAst ?? true\n const storyPathOptions = toStoryPathOptions(options)\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n return {\n Program(program) {\n // Is this file a dumb component that requires a story, and where would the story live?\n if (!classifyComponent(context.filename, storyPathOptions)) {\n return\n }\n\n // Only enforce on files that actually declare a component (avoids flagging stray\n // non-component files placed under a components/ directory).\n if (requireComponentAst && !bodyDeclaresComponent(program.body)) {\n return\n }\n\n const candidates = deriveExpectedStoryPaths(context.filename, storyPathOptions)\n\n // The story is satisfied if ANY candidate (by extension) exists on disk.\n const hasStory = candidates.some((candidate) => {\n return existsSync(candidate)\n })\n\n if (hasStory) {\n return\n }\n\n context.report({\n node: program,\n messageId: 'missingStory',\n data: {\n component: path.posix.basename(context.filename.split('\\\\').join('/')),\n expected: candidates[0] ?? '',\n },\n })\n },\n }\n },\n}\n\nexport default requireComponentStories\n", "import path from 'node:path'\n\n/** Where a story file lives relative to its component. */\nexport type StoryMode = 'feature-root' | 'sibling'\n\n/** A consumer-defined extra component layout (structured \u2014 never a glob). */\nexport interface ExtraTarget {\n /** Immediate parent directory name a component file must sit directly inside. */\n componentsDir: string\n /** Optional grandparent directory name gate (e.g. `features`). */\n anchorParentDir?: string\n /** Where the story is expected for files matched by this target. */\n storyMode: StoryMode\n}\n\nexport interface StoryPathOptions {\n /** Story directory name (default `__stories__`). */\n storiesDir: string\n /** Suffix inserted before the extension (default `.stories`). */\n storySuffix: string\n /** Extensions a satisfying story file may have, in priority order. */\n storyExtensions: string[]\n /** Extensions a file must have to be considered a component. */\n componentExtensions: string[]\n /** Basename suffix a component file must end with (default `-component`; `''` disables). */\n componentSuffix: string\n /** Additional structured component layouts beyond the two built-ins. */\n extraTargets: ExtraTarget[]\n}\n\nexport const DEFAULT_STORY_PATH_OPTIONS: StoryPathOptions = {\n storiesDir: '__stories__',\n storySuffix: '.stories',\n storyExtensions: ['.tsx', '.jsx', '.ts', '.js'],\n componentExtensions: ['.tsx', '.jsx'],\n componentSuffix: '-component',\n extraTargets: [],\n}\n\nconst resolveOptions = (opts?: Partial<StoryPathOptions>): StoryPathOptions => {\n return { ...DEFAULT_STORY_PATH_OPTIONS, ...opts }\n}\n\n/** Normalize OS-native separators to posix so all downstream path logic is deterministic. */\nconst toPosix = (filePath: string): string => {\n return filePath.split('\\\\').join('/')\n}\n\ninterface ParsedComponent {\n /** Posix directory of the file. */\n dir: string\n /** Basename without its extension. */\n base: string\n /** Original extension (e.g. `.tsx`). */\n ext: string\n /** Immediate parent directory name. */\n parent: string\n /** Grandparent directory name. */\n grandparent: string\n /** Great-grandparent directory name. */\n greatGrandparent: string\n}\n\n/** Parse a file path into the segment view the gate and derivation both need. */\nconst parse = (filePath: string): ParsedComponent => {\n const normalized = toPosix(filePath)\n const segments = normalized.split('/')\n const basename = segments[segments.length - 1] ?? ''\n const ext = path.posix.extname(basename)\n const base = ext ? basename.slice(0, -ext.length) : basename\n\n return {\n dir: path.posix.dirname(normalized),\n base,\n ext,\n parent: segments[segments.length - 2] ?? '',\n grandparent: segments[segments.length - 3] ?? '',\n greatGrandparent: segments[segments.length - 4] ?? '',\n }\n}\n\n/** Whether the file passes the component preconditions (extension + name suffix). */\nconst passesComponentPreconditions = (parsed: ParsedComponent, options: StoryPathOptions): boolean => {\n if (!options.componentExtensions.includes(parsed.ext)) {\n return false\n }\n\n return options.componentSuffix === '' || parsed.base.endsWith(options.componentSuffix)\n}\n\n/**\n * Classify a file as a dumb component requiring a story, resolving WHERE its story should live.\n * Returns null when the file is not a component-requiring-a-story under any branch.\n *\n * Exactly one admit-condition may hold:\n * - feature-root: direct child of `components/` whose chain is `features/<f>/components`.\n * - sibling: a `components/default/<name>-component` file (parent `default`, grandparent `components`).\n * - extraTargets: a structured consumer-defined layout.\n */\nexport const classifyComponent = (filePath: string, opts?: Partial<StoryPathOptions>): { mode: StoryMode } | null => {\n const options = resolveOptions(opts)\n const parsed = parse(filePath)\n\n if (!passesComponentPreconditions(parsed, options)) {\n return null\n }\n\n // (a) feature-root \u2014 immediate parent is `components` AND the chain is `features/<feature>/components`.\n if (parsed.parent === 'components' && parsed.greatGrandparent === 'features') {\n return { mode: 'feature-root' }\n }\n\n // (b) sibling \u2014 `components/default/<name>-component.*` (NOT a direct child of `components/`).\n if (parsed.parent === 'default' && parsed.grandparent === 'components') {\n return { mode: 'sibling' }\n }\n\n // (c) extraTargets \u2014 structured layouts (componentsDir + optional anchorParentDir).\n for (const target of options.extraTargets) {\n const parentMatches = parsed.parent === target.componentsDir\n const anchorMatches = target.anchorParentDir == null || parsed.grandparent === target.anchorParentDir\n\n if (parentMatches && anchorMatches) {\n return { mode: target.storyMode }\n }\n }\n\n return null\n}\n\n/**\n * Ordered candidate story paths for a component file. Empty when the file is not a\n * component-requiring-a-story (see {@link classifyComponent}). The story is considered present\n * when ANY candidate exists on disk.\n */\nexport const deriveExpectedStoryPaths = (filePath: string, opts?: Partial<StoryPathOptions>): string[] => {\n const options = resolveOptions(opts)\n const classification = classifyComponent(filePath, options)\n\n if (!classification) {\n return []\n }\n\n const parsed = parse(filePath)\n\n // feature-root: dirname(file) is `.../components`, so its parent is the feature root.\n // sibling: the story dir sits next to the component file itself.\n const storyBaseDir = classification.mode === 'feature-root' ? path.posix.dirname(parsed.dir) : parsed.dir\n const storyDir = path.posix.join(storyBaseDir, options.storiesDir)\n\n return options.storyExtensions.map((extension) => {\n return path.posix.join(storyDir, `${parsed.base}${options.storySuffix}${extension}`)\n })\n}\n", "import type { Rule } from 'eslint'\n\nimport { componentArrowFunction } from './component-arrow-function'\nimport { componentFileOrder } from './component-file-order'\nimport { propsDestructuringBlankLine } from './props-destructuring-blank-line'\nimport { propsDestructuringNewline } from './props-destructuring-newline'\nimport { propsTypeReference } from './props-type-reference'\nimport { requireComponentStories } from './require-component-stories'\n\nexport const rules: Record<string, Rule.RuleModule> = {\n 'props-destructuring-newline': propsDestructuringNewline,\n 'props-destructuring-blank-line': propsDestructuringBlankLine,\n 'props-type-reference': propsTypeReference,\n 'component-file-order': componentFileOrder,\n 'component-arrow-function': componentArrowFunction,\n 'require-component-stories': requireComponentStories,\n}\n", "import type { ESLint, Linter } from 'eslint'\n\nimport { rules } from './rules'\n\nconst PLUGIN_NAME = '@wl'\n\nconst plugin: ESLint.Plugin & { configs: Record<string, Linter.Config | Linter.Config[]> } = {\n meta: {\n name: '@wl/eslint-plugin',\n version: '0.1.11',\n },\n rules,\n configs: {},\n}\n\n/**\n * Flat-config preset that registers the plugin and turns every rule on, scoped to\n * the files each rule is meant for. It is an array of config blocks, so spread it:\n *\n * @example\n * import wl from '@wl/eslint-plugin'\n *\n * export default [...wl.configs.recommended]\n */\nplugin.configs.recommended = [\n {\n files: ['**/*.tsx'],\n plugins: {\n [PLUGIN_NAME]: plugin,\n },\n rules: {\n [`${PLUGIN_NAME}/props-destructuring-newline`]: 'error',\n [`${PLUGIN_NAME}/props-destructuring-blank-line`]: 'error',\n [`${PLUGIN_NAME}/props-type-reference`]: 'error',\n [`${PLUGIN_NAME}/component-file-order`]: 'error',\n // Pages and routes are excluded: route/page modules commonly use `function`\n // declarations (and framework conventions like default-exported page functions).\n [`${PLUGIN_NAME}/component-arrow-function`]: ['error', { ignore: ['**/pages/**', '**/routes/**'] }],\n [`${PLUGIN_NAME}/require-component-stories`]: 'error',\n },\n },\n // Storybook stories legitimately deviate from the imports \u2192 *Props \u2192 component\n // order (meta/args/decorators/render fns), so component-file-order would only\n // produce noise there. Every other rule stays enabled for story files.\n {\n files: ['**/*.stories.{ts,tsx}'],\n rules: {\n [`${PLUGIN_NAME}/component-file-order`]: 'off',\n },\n },\n]\n\nexport const meta: ESLint.Plugin['meta'] = plugin.meta\nexport const configs: Record<string, Linter.Config | Linter.Config[]> = plugin.configs\nexport { rules }\n\nexport default plugin\n"],
5
- "mappings": ";AAUA,IAAM,4BAA4B,oBAAI,IAAI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AAA,IACA,OAAO;AAAA,MACL,CAAC,GAAG,WAAW,8BAA8B,GAAG;AAAA,MAChD,CAAC,GAAG,WAAW,iCAAiC,GAAG;AAAA,MACnD,CAAC,GAAG,WAAW,uBAAuB,GAAG;AAAA,MACzC,CAAC,GAAG,WAAW,uBAAuB,GAAG;AAAA;AAAA;AAAA,MAGzC,CAAC,GAAG,WAAW,2BAA2B,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,eAAe,cAAc,EAAE,CAAC;AAAA,MAClG,CAAC,GAAG,WAAW,4BAA4B,GAAG;AAAA,IAChD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA,IACE,OAAO,CAAC,uBAAuB;AAAA,IAC/B,OAAO;AAAA,MACL,CAAC,GAAG,WAAW,uBAAuB,GAAG;AAAA,IAC3C;AAAA,EACF;AACF;AAEO,IAAM,OAA8B,OAAO;AAC3C,IAAM,UAA2D,OAAO;AAG/E,IAAO,gBAAQ;",
6
- "names": ["fn", "path", "path"]
3
+ "sources": ["../src/utils/component.ts", "../src/utils/path-match.ts", "../src/rules/component-arrow-function.ts", "../src/rules/component-file-order.ts", "../src/rules/props-destructuring-blank-line.ts", "../src/rules/props-destructuring-newline.ts", "../src/rules/props-type-name.ts", "../src/rules/props-type-reference.ts", "../src/rules/require-component-stories.ts", "../src/utils/story-path.ts", "../src/rules/index.ts", "../src/index.ts"],
4
+ "sourcesContent": ["import type * as ESTree from 'estree'\n\nexport type ComponentFunction = ESTree.ArrowFunctionExpression | ESTree.FunctionDeclaration | ESTree.FunctionExpression\n\n// Minimal structural view over the `parent` back-reference ESLint adds to every node.\ninterface WithParent {\n parent?: ESTree.Node\n}\n\n// Calls that wrap a component while preserving its identity (memo, forwardRef, observer, ...).\nconst COMPONENT_WRAPPER_CALLEES = new Set(['memo', 'forwardRef', 'observer', 'React.memo', 'React.forwardRef'])\n\n// Node types that introduce a new function scope \u2014 their returns are not the outer component's.\nconst NESTED_SCOPES = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression'])\n\nconst isPascalCase = (name: string): boolean => {\n return /^[A-Z]/.test(name)\n}\n\nconst isJsxNode = (node: ESTree.Node | null | undefined): boolean => {\n if (!node) {\n return false\n }\n\n const type = node.type as string\n\n return type === 'JSXElement' || type === 'JSXFragment'\n}\n\nconst getParent = (node: ESTree.Node | undefined): ESTree.Node | undefined => {\n return (node as (WithParent & ESTree.Node) | undefined)?.parent\n}\n\n/** Best-effort name of a call's callee: `memo` for `memo(...)`, `React.memo` for `React.memo(...)`. */\nconst getCalleeName = (callee: ESTree.CallExpression['callee']): string | null => {\n if (callee.type === 'Identifier') {\n return callee.name\n }\n\n if (\n callee.type === 'MemberExpression' &&\n callee.object.type === 'Identifier' &&\n callee.property.type === 'Identifier'\n ) {\n return `${callee.object.name}.${callee.property.name}`\n }\n\n return null\n}\n\n/**\n * Resolve the declared name of a function, looking through component wrappers\n * such as `memo`/`forwardRef` so that `const Comp = memo(({ a }) => ...)` is\n * still recognised by its PascalCase variable name.\n */\nexport const getComponentName = (node: ComponentFunction): string | null => {\n if (node.type === 'FunctionDeclaration') {\n return node.id?.name ?? null\n }\n\n let current = getParent(node)\n\n // Walk through wrapping call expressions (memo, forwardRef, React.memo, ...).\n while (current?.type === 'CallExpression') {\n const calleeName = getCalleeName(current.callee)\n\n if (!calleeName || !COMPONENT_WRAPPER_CALLEES.has(calleeName)) {\n break\n }\n\n current = getParent(current)\n }\n\n if (current?.type === 'VariableDeclarator' && current.id.type === 'Identifier') {\n return current.id.name\n }\n\n return null\n}\n\n/** Whether a function returns JSX, scanning its own body without descending into nested functions. */\nconst returnsJsx = (node: ComponentFunction): boolean => {\n if (node.body.type !== 'BlockStatement') {\n return isJsxNode(node.body)\n }\n\n let found = false\n\n const visit = (current: ESTree.Node | null | undefined): void => {\n if (found || !current || NESTED_SCOPES.has(current.type)) {\n return\n }\n\n if (current.type === 'ReturnStatement') {\n if (isJsxNode(current.argument)) {\n found = true\n }\n\n return\n }\n\n if (current.type === 'IfStatement') {\n visit(current.consequent)\n visit(current.alternate)\n\n return\n }\n\n if (current.type === 'BlockStatement') {\n current.body.forEach(visit)\n\n return\n }\n\n if (current.type === 'SwitchStatement') {\n for (const switchCase of current.cases) {\n switchCase.consequent.forEach(visit)\n }\n\n return\n }\n\n if (current.type === 'TryStatement') {\n visit(current.block)\n visit(current.handler?.body)\n visit(current.finalizer)\n\n return\n }\n\n if (\n current.type === 'ForStatement' ||\n current.type === 'ForInStatement' ||\n current.type === 'ForOfStatement' ||\n current.type === 'WhileStatement' ||\n current.type === 'DoWhileStatement'\n ) {\n visit(current.body)\n }\n }\n\n node.body.body.forEach(visit)\n\n return found\n}\n\n/** A function is treated as a React component when it is PascalCase-named or returns JSX. */\nexport const isComponent = (node: ComponentFunction): boolean => {\n const name = getComponentName(node)\n\n if (name && isPascalCase(name)) {\n return true\n }\n\n return returnsJsx(node)\n}\n\nconst isComponentFunctionNode = (node: ESTree.Node): node is ComponentFunction => {\n return (\n node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration'\n )\n}\n\n/**\n * Extract the component function from an expression, unwrapping a single layer of\n * component wrappers (`memo(fn)`, `forwardRef(fn)`, `React.memo(fn)`, ...). Returns\n * null when no function is found.\n */\nexport const getComponentFunction = (node: ESTree.Node | null | undefined): ComponentFunction | null => {\n if (!node) {\n return null\n }\n\n if (isComponentFunctionNode(node)) {\n return node\n }\n\n if (node.type === 'CallExpression') {\n for (const argument of node.arguments) {\n if (argument.type === 'SpreadElement') {\n continue\n }\n\n const found = getComponentFunction(argument)\n\n if (found) {\n return found\n }\n }\n }\n\n return null\n}\n\n// TS-only nodes are not modelled by estree. A parameter's `typeAnnotation` wraps the type node;\n// for a named type that inner node is a `TSTypeReference` whose `typeName` is the referenced\n// identifier (`Props`, `ButtonProps`, ...). Inline object types, qualified names (`NS.Props`) and\n// generics surface a different `typeName` shape and are intentionally left unresolved.\ninterface TypeReferenceNode {\n type?: string\n typeName?: { type?: string; name?: string }\n}\n\ninterface AnnotatedParam {\n typeAnnotation?: {\n typeAnnotation?: TypeReferenceNode\n }\n}\n\n/**\n * The parameter that actually carries the props type annotation. A default value wraps the\n * parameter in an `AssignmentPattern` (`(props: Props = {})`), moving the annotation onto its\n * `.left`; unwrap one layer so the annotation is found either way.\n */\nexport const getAnnotatedParam = (param: ESTree.Pattern): ESTree.Pattern => {\n return param.type === 'AssignmentPattern' ? param.left : param\n}\n\n/** The named type referenced by a component function's first parameter (`Props`), or null. */\nexport const getPropsTypeNameFromFunction = (node: ComponentFunction): string | null => {\n const firstParam = node.params[0]\n\n if (!firstParam) {\n return null\n }\n\n const inner = (getAnnotatedParam(firstParam) as AnnotatedParam).typeAnnotation?.typeAnnotation\n\n if (inner?.type !== 'TSTypeReference' || inner.typeName?.type !== 'Identifier') {\n return null\n }\n\n return inner.typeName.name ?? null\n}\n\n/**\n * Resolve the props type name a component *uses* \u2014 the named type on its first parameter \u2014\n * looking through component wrappers (`memo`/`forwardRef`). Returns null when the component is\n * anonymous of props (no parameter) or its props type is not a simple named reference (inline\n * object, qualified name, generic). Mirrors `getDeclaredComponentName`'s node dispatch so a\n * `const`-declared arrow component resolves through its `init`, not the `VariableDeclaration`.\n */\nexport const getComponentPropsTypeName = (node: ESTree.Node | null): string | null => {\n if (!node) {\n return null\n }\n\n if (node.type === 'FunctionDeclaration') {\n return isComponent(node) ? getPropsTypeNameFromFunction(node) : null\n }\n\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n const fn = getComponentFunction(declaration.init)\n\n if (fn && isComponent(fn)) {\n return getPropsTypeNameFromFunction(fn)\n }\n }\n\n return null\n }\n\n const fn = getComponentFunction(node)\n\n return fn && isComponent(fn) ? getPropsTypeNameFromFunction(fn) : null\n}\n\n/** Unwrap an `export ...` statement to the declaration it wraps (or the statement itself). */\nexport const unwrapExport = (statement: ESTree.Statement | ESTree.ModuleDeclaration): ESTree.Node | null => {\n if (statement.type === 'ExportNamedDeclaration' || statement.type === 'ExportDefaultDeclaration') {\n return (statement.declaration as ESTree.Node | null) ?? null\n }\n\n return statement\n}\n\n/** Whether a single top-level declaration declares a React component. */\nexport const declaresComponent = (node: ESTree.Node | null): boolean => {\n if (!node) {\n return false\n }\n\n if (node.type === 'FunctionDeclaration') {\n return isComponent(node)\n }\n\n if (node.type === 'VariableDeclaration') {\n return node.declarations.some((declaration) => {\n const fn = getComponentFunction(declaration.init)\n\n return fn ? isComponent(fn) : false\n })\n }\n\n const fn = getComponentFunction(node)\n\n return fn ? isComponent(fn) : false\n}\n\n/**\n * Resolve the name of the React component declared by a single top-level declaration,\n * or null when the declaration is not a component or the component is anonymous\n * (e.g. `export default () => <div />`). Mirrors `declaresComponent`'s node dispatch and\n * resolves the name through component wrappers (`memo`/`forwardRef`).\n */\nexport const getDeclaredComponentName = (node: ESTree.Node | null): string | null => {\n if (!node) {\n return null\n }\n\n if (node.type === 'FunctionDeclaration') {\n return isComponent(node) ? getComponentName(node) : null\n }\n\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n const fn = getComponentFunction(declaration.init)\n\n if (fn && isComponent(fn)) {\n return getComponentName(fn)\n }\n }\n\n return null\n }\n\n const fn = getComponentFunction(node)\n\n return fn && isComponent(fn) ? getComponentName(fn) : null\n}\n\n/** Whether any top-level statement in a program body declares a React component. */\nexport const bodyDeclaresComponent = (body: Array<ESTree.Statement | ESTree.ModuleDeclaration>): boolean => {\n return body.some((statement) => {\n return declaresComponent(unwrapExport(statement))\n })\n}\n", "// Characters that must be escaped when embedded literally into a RegExp source.\nconst REGEX_METACHARS = new Set(['\\\\', '^', '$', '.', '|', '+', '(', ')', '[', ']', '{', '}'])\n\n/**\n * Convert a glob pattern to an (unanchored) RegExp.\n *\n * - `**` matches any characters, including path separators.\n * - `*` matches any characters except a path separator.\n * - `?` matches a single non-separator character.\n *\n * The result is intentionally unanchored so a pattern matches anywhere in the\n * path (e.g. `features/**` matches `/repo/src/features/x/comp.tsx`).\n */\nconst globToRegExp = (glob: string): RegExp => {\n let source = ''\n\n for (let index = 0; index < glob.length; index++) {\n const char = glob[index]!\n\n if (char === '*') {\n if (glob[index + 1] === '*') {\n source += '.*'\n index++\n\n // Consume a trailing slash so `**/foo` also matches a bare `foo`.\n if (glob[index + 1] === '/') {\n index++\n }\n } else {\n source += '[^/]*'\n }\n } else if (char === '?') {\n source += '[^/]'\n } else if (REGEX_METACHARS.has(char)) {\n source += `\\\\${char}`\n } else {\n source += char\n }\n }\n\n return new RegExp(source)\n}\n\n/** Whether `filename` matches at least one of the provided glob `patterns`. */\nexport const matchesAnyGlob = (filename: string, patterns: readonly string[]): boolean => {\n const normalized = filename.split('\\\\').join('/')\n\n return patterns.some((pattern) => {\n return globToRegExp(pattern).test(normalized)\n })\n}\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport { getComponentFunction, getComponentName, isComponent, unwrapExport } from '../utils/component'\nimport type { ComponentFunction } from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n}\n\n// Fallback used when a component is anonymous (e.g. `export default memo(function () { ... })`),\n// since `getComponentName` returns null rather than a placeholder in that case.\nconst ANONYMOUS_NAME = 'component'\n\ntype MessageId = 'functionDeclaration' | 'functionExpression'\n\ninterface Violation {\n node: ESTree.Node\n messageId: MessageId\n name: string\n}\n\nconst reportName = (fn: ComponentFunction): string => {\n return getComponentName(fn) ?? ANONYMOUS_NAME\n}\n\n/**\n * Violation for a single non-`VariableDeclaration` top-level declaration:\n * - a `function Foo() {}` component declaration (incl. exported/default/anonymous), or\n * - an expression that resolves to a function-expression component\n * (e.g. `export default memo(function () { ... })`).\n */\nconst nonVariableViolation = (declaration: ESTree.Node): Violation | null => {\n if (declaration.type === 'FunctionDeclaration') {\n return isComponent(declaration)\n ? { node: declaration, messageId: 'functionDeclaration', name: reportName(declaration) }\n : null\n }\n\n const fn = getComponentFunction(declaration)\n\n return fn?.type === 'FunctionExpression' && isComponent(fn)\n ? { node: fn, messageId: 'functionExpression', name: reportName(fn) }\n : null\n}\n\n/** Function-expression component violations across every declarator in a `const`/`let`/`var`. */\nconst variableViolations = (declaration: ESTree.VariableDeclaration): Violation[] => {\n const violations: Violation[] = []\n\n for (const declarator of declaration.declarations) {\n const fn = getComponentFunction(declarator.init)\n\n if (fn?.type === 'FunctionExpression' && isComponent(fn)) {\n violations.push({ node: declarator, messageId: 'functionExpression', name: reportName(fn) })\n }\n }\n\n return violations\n}\n\n/** Every non-arrow component declared at the top level of the program body. */\nconst collectViolations = (body: Array<ESTree.Statement | ESTree.ModuleDeclaration>): Violation[] => {\n const violations: Violation[] = []\n\n for (const statement of body) {\n const declaration = unwrapExport(statement)\n\n if (!declaration) {\n continue\n }\n\n if (declaration.type === 'VariableDeclaration') {\n violations.push(...variableViolations(declaration))\n\n continue\n }\n\n const violation = nonVariableViolation(declaration)\n\n if (violation) {\n violations.push(violation)\n }\n }\n\n return violations\n}\n\nexport const componentArrowFunction: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Enforce that React components are declared as arrow functions, not `function` declarations or function expressions.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. When provided, the rule only runs for files whose path matches one of them.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. The rule is skipped for files whose path matches one of them, even if it also matches `paths`. Use this to exclude pages and routes (e.g. `**/pages/**`, `**/routes/**`).',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n functionDeclaration:\n 'React components must be arrow functions; convert the `function {{name}}` declaration to `const {{name}} = () => { \u2026 }`.',\n functionExpression:\n 'React components must be arrow functions; replace the `function` expression for `{{name}}` with an arrow function.',\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n return {\n Program(program) {\n for (const { node, messageId, name } of collectViolations(program.body)) {\n context.report({ node, messageId, data: { name } })\n }\n },\n }\n },\n}\n\nexport default componentArrowFunction\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport {\n declaresComponent,\n getComponentPropsTypeName,\n getDeclaredComponentName,\n unwrapExport,\n} from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n}\n\n// TS-only nodes are not modelled by estree; access their identifier structurally.\ninterface NamedDeclaration {\n type: string\n id?: { name?: string } | null\n}\n\nconst PROPS_SUFFIX = 'Props'\n\n/**\n * Count the directive prologue \u2014 the leading run of string-literal expression statements\n * (`'use client'`, `'use server'`, `'use strict'`) at the top of the file. They are\n * legitimate file-leading content (like imports) and must not count as \"stray\" before the\n * props interface. Per the ECMAScript spec a directive is only one that *precedes* any other\n * statement, so we stop at the first non-string-literal statement rather than matching any\n * bare string anywhere in the body.\n */\nconst getDirectivePrologueCount = (body: Array<ESTree.Statement | ESTree.ModuleDeclaration>): number => {\n let count = 0\n\n for (const statement of body) {\n const isStringExpression =\n statement.type === 'ExpressionStatement' &&\n statement.expression.type === 'Literal' &&\n typeof statement.expression.value === 'string'\n\n if (!isStringExpression) {\n break\n }\n\n count += 1\n }\n\n return count\n}\n\n/**\n * The name of a top-level interface or type-alias declaration, or null when it is neither.\n * Unlike the props lookup, this is name-agnostic: any local type declaration is indexed so a\n * component can be matched against the type it actually references, whatever that type is called.\n */\nconst getTypeDeclName = (node: ESTree.Node | null): string | null => {\n if (!node) {\n return null\n }\n\n const named = node as NamedDeclaration\n\n if (named.type !== 'TSInterfaceDeclaration' && named.type !== 'TSTypeAliasDeclaration') {\n return null\n }\n\n return named.id?.name ?? null\n}\n\ninterface ComponentRef {\n index: number\n name: string | null\n // The type name the component uses for its props \u2014 resolved from its parameter annotation, or\n // the `<Name>Props` convention when the parameter carries no resolvable named type. Null when\n // neither is available (e.g. an anonymous component with no typed props parameter).\n propsName: string | null\n}\n\ninterface TopLevel {\n importIndices: number[]\n components: ComponentRef[]\n // First index of each top-level type declaration, keyed by its name.\n declIndexByName: Map<string, number>\n // Local binding names introduced by imports \u2014 used to detect a props type that is\n // imported (e.g. `import type { CompProps }`) rather than declared in the file.\n importedNames: Set<string>\n}\n\n/** Classify each top-level statement into imports, components, local type declarations, and import bindings. */\nconst collectTopLevel = (body: Array<ESTree.Statement | ESTree.ModuleDeclaration>): TopLevel => {\n const importIndices: number[] = []\n const components: ComponentRef[] = []\n const declIndexByName = new Map<string, number>()\n const importedNames = new Set<string>()\n\n body.forEach((statement, index) => {\n if (statement.type === 'ImportDeclaration') {\n importIndices.push(index)\n\n for (const specifier of statement.specifiers) {\n importedNames.add(specifier.local.name)\n }\n\n return\n }\n\n const declaration = unwrapExport(statement)\n\n const declName = getTypeDeclName(declaration)\n\n if (declName !== null && !declIndexByName.has(declName)) {\n declIndexByName.set(declName, index)\n }\n\n if (declaresComponent(declaration)) {\n const name = getDeclaredComponentName(declaration)\n // Prefer the type the component's parameter actually references; fall back to the\n // `<Name>Props` convention only when no named parameter type is resolvable.\n const propsName = getComponentPropsTypeName(declaration) ?? (name === null ? null : `${name}${PROPS_SUFFIX}`)\n\n components.push({ index, name, propsName })\n }\n })\n\n return { importIndices, components, declIndexByName, importedNames }\n}\n\n/**\n * Whether any top-level statement in the half-open range `[directiveCount, boundary)` is a stray \u2014\n * i.e. not an import and not part of the leading directive prologue. `skipIndex` excludes a single\n * known-good statement (the component itself, when scanning the gap before its props interface).\n */\nconst hasStrayBefore = (\n body: Array<ESTree.Statement | ESTree.ModuleDeclaration>,\n boundary: number,\n directiveCount: number,\n skipIndex?: number,\n): boolean => {\n return body.some((statement, index) => {\n return index < boundary && index >= directiveCount && index !== skipIndex && statement.type !== 'ImportDeclaration'\n })\n}\n\ntype MessageId =\n | 'importsFirst'\n | 'interfaceImmediatelyBeforeComponent'\n | 'interfaceImmediatelyAfterImports'\n | 'componentImmediatelyAfterImports'\n\n// A pending report, expressed as a body index plus the message to raise against it.\ninterface Violation {\n index: number\n messageId: MessageId\n}\n\n/** Imports that sit after the first component (or its props interface) must move up. */\nconst findImportOrderViolations = (importIndices: number[], importBoundary: number): Violation[] => {\n return importIndices\n .filter((importIndex) => {\n return importIndex > importBoundary\n })\n .map((importIndex) => {\n return { index: importIndex, messageId: 'importsFirst' }\n })\n}\n\n/**\n * Each component's props type, when declared locally, must sit immediately before the component.\n * The type is matched by the name the component's parameter actually references, so an interface\n * named anything (`Props`, `UserCardProps`, ...) is judged \u2014 not just the `<Name>Props` convention.\n * A type referenced by more than one component is skipped: a single declaration cannot sit\n * immediately before two components, so adjacency is unenforceable and would misfire.\n */\nconst findAdjacencyViolations = (components: ComponentRef[], declIndexByName: Map<string, number>): Violation[] => {\n const violations: Violation[] = []\n\n const referenceCount = new Map<string, number>()\n\n for (const component of components) {\n if (component.propsName !== null) {\n referenceCount.set(component.propsName, (referenceCount.get(component.propsName) ?? 0) + 1)\n }\n }\n\n for (const component of components) {\n const propsName = component.propsName\n\n if (propsName === null || (referenceCount.get(propsName) ?? 0) > 1) {\n continue\n }\n\n const propsIndex = declIndexByName.get(propsName)\n\n if (propsIndex !== undefined && propsIndex !== component.index - 1) {\n violations.push({ index: propsIndex, messageId: 'interfaceImmediatelyBeforeComponent' })\n }\n }\n\n return violations\n}\n\n/**\n * The first component is anchored to the import block: no stray top-level definition may wedge\n * between the imports and the props interface \u2014 or, when the props type is *imported* rather than\n * declared in the file, between the imports and the component itself. Only the first component is\n * anchored; later interfaces are governed solely by the adjacency check. Each `every` guard skips\n * when an import sits after its anchor, since that misorder is already reported by `importsFirst`.\n */\nconst findAnchorViolations = (\n body: Array<ESTree.Statement | ESTree.ModuleDeclaration>,\n directiveCount: number,\n importIndices: number[],\n first: ComponentRef,\n firstPropsName: string | null,\n firstPropsIndex: number | undefined,\n importedNames: Set<string>,\n): Violation[] => {\n const violations: Violation[] = []\n\n const importsBeforeInterface =\n firstPropsIndex !== undefined &&\n importIndices.every((importIndex) => {\n return importIndex < firstPropsIndex\n })\n\n if (importsBeforeInterface && hasStrayBefore(body, firstPropsIndex!, directiveCount, first.index)) {\n violations.push({ index: firstPropsIndex!, messageId: 'interfaceImmediatelyAfterImports' })\n }\n\n const firstPropsImported =\n firstPropsIndex === undefined && firstPropsName !== null && importedNames.has(firstPropsName)\n const importsBeforeComponent = importIndices.every((importIndex) => {\n return importIndex < first.index\n })\n\n if (firstPropsImported && importsBeforeComponent && hasStrayBefore(body, first.index, directiveCount)) {\n violations.push({ index: first.index, messageId: 'componentImmediatelyAfterImports' })\n }\n\n return violations\n}\n\nexport const componentFileOrder: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Enforce a strict top-level order in React component files: imports first, then \u2014 for each component \u2014 its props interface/type declared immediately before the component.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. When provided, the rule only runs for files whose path matches one of them.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. The rule is skipped for files whose path matches one of them, even if it also matches `paths`.',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n importsFirst: 'Imports must come before the component interface and declaration.',\n interfaceImmediatelyBeforeComponent:\n 'The component props interface must be declared immediately before the component.',\n interfaceImmediatelyAfterImports:\n 'The component props interface must be declared immediately after the imports, with no other declarations in between.',\n componentImmediatelyAfterImports:\n 'When the component props type is imported, the component must be declared immediately after the imports, with no other declarations in between.',\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n return {\n Program(program) {\n const body = program.body\n\n // Leading directive prologue (`'use client'`, ...) \u2014 excluded from the stray checks.\n const directiveCount = getDirectivePrologueCount(body)\n\n const { importIndices, components, declIndexByName, importedNames } = collectTopLevel(body)\n\n // The rule only governs files that actually contain a component.\n if (components.length === 0) {\n return\n }\n\n const first = components[0]!\n const firstPropsName = first.propsName\n const firstPropsIndex = firstPropsName === null ? undefined : declIndexByName.get(firstPropsName)\n // `importBoundary` is intentionally directive-insensitive: a leading directive prologue\n // shifts every subsequent index up uniformly, so it never crosses this boundary. The\n // prologue is excluded only from the stray checks, where the raw index matters.\n const importBoundary = Math.min(first.index, firstPropsIndex ?? first.index)\n\n const violations = [\n ...findImportOrderViolations(importIndices, importBoundary),\n ...findAdjacencyViolations(components, declIndexByName),\n ...findAnchorViolations(\n body,\n directiveCount,\n importIndices,\n first,\n firstPropsName,\n firstPropsIndex,\n importedNames,\n ),\n ]\n\n for (const violation of violations) {\n context.report({ node: body[violation.index]!, messageId: violation.messageId })\n }\n },\n }\n },\n}\n\nexport default componentFileOrder\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport type { ComponentFunction } from '../utils/component'\nimport { isComponent } from '../utils/component'\n\n/** Whether a statement is `const { ... } = props` (destructuring the `props` identifier). */\nconst isPropsDestructuring = (statement: ESTree.Statement): boolean => {\n if (statement.type !== 'VariableDeclaration') {\n return false\n }\n\n return statement.declarations.some((declaration) => {\n return (\n declaration.id.type === 'ObjectPattern' &&\n declaration.init?.type === 'Identifier' &&\n declaration.init.name === 'props'\n )\n })\n}\n\nexport const propsDestructuringBlankLine: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Require a blank line after the `const { ... } = props` destructuring statement at the top of a React component body.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n fixable: 'whitespace',\n schema: [],\n messages: {\n blankLineAfterProps: 'Add a blank line after destructuring props.',\n },\n },\n\n create(context) {\n const sourceCode = context.sourceCode\n\n const check = (node: ComponentFunction): void => {\n if (node.body.type !== 'BlockStatement') {\n return\n }\n\n if (!isComponent(node)) {\n return\n }\n\n const statements = node.body.body\n const index = statements.findIndex(isPropsDestructuring)\n\n if (index === -1) {\n return\n }\n\n const propsStatement = statements[index]\n const nextStatement = statements[index + 1]\n\n // `propsStatement` is defined because `index !== -1`; the guard also narrows the type.\n // Nothing follows the destructuring \u2014 no separation needed.\n if (!propsStatement || !nextStatement) {\n return\n }\n\n // The token/comment that follows the destructuring statement; a comment on the\n // next line still counts as \"no blank line\" until it is pushed down.\n const tokenAfter = sourceCode.getTokenAfter(propsStatement, { includeComments: true })\n const referenceLine = (tokenAfter ?? nextStatement).loc!.start.line\n\n if (referenceLine - propsStatement.loc!.end.line >= 2) {\n return\n }\n\n context.report({\n node: propsStatement,\n messageId: 'blankLineAfterProps',\n fix(fixer) {\n return fixer.insertTextAfter(propsStatement, '\\n')\n },\n })\n }\n\n return {\n ArrowFunctionExpression: check,\n FunctionDeclaration: check,\n FunctionExpression: check,\n }\n },\n}\n\nexport default propsDestructuringBlankLine\n", "import type { Rule } from 'eslint'\nimport type * as ESTree from 'estree'\n\nimport type { ComponentFunction } from '../utils/component'\nimport { isComponent } from '../utils/component'\n\n// Minimal structural views over nodes that estree's types do not fully model:\n// the optional TS type annotation and `range` that the parser attaches to params.\ninterface WithRange {\n range?: [number, number]\n}\ntype AnnotatedPattern = ESTree.ObjectPattern & { typeAnnotation?: ESTree.Node & WithRange } & WithRange\n\n// Recursively collect every identifier a destructuring pattern binds, so we can detect\n// whether it already introduces a `props` binding (e.g. a `...props` rest).\nconst collectBoundNames = (node: ESTree.Node | null, names: Set<string>): void => {\n if (!node) {\n return\n }\n\n switch (node.type) {\n case 'Identifier':\n names.add(node.name)\n break\n case 'ObjectPattern':\n for (const property of node.properties) collectBoundNames(property, names)\n break\n case 'ArrayPattern':\n for (const element of node.elements) collectBoundNames(element, names)\n break\n case 'Property':\n collectBoundNames(node.value, names)\n break\n case 'RestElement':\n collectBoundNames(node.argument, names)\n break\n case 'AssignmentPattern':\n collectBoundNames(node.left, names)\n break\n default:\n break\n }\n}\n\nexport const propsDestructuringNewline: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Require React components to accept a single props parameter and destructure it on its own line in the body, rather than destructuring inline in the parameter list.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n fixable: 'code',\n schema: [],\n messages: {\n destructureOnNewLine:\n 'Accept a single `props` parameter and destructure it on its own line in the component body instead of destructuring in the parameter list.',\n },\n },\n\n create(context) {\n const sourceCode = context.sourceCode\n\n const check = (node: ComponentFunction): void => {\n const firstParam = node.params[0]\n\n if (!firstParam || firstParam.type !== 'ObjectPattern') {\n return\n }\n\n if (!isComponent(node)) {\n return\n }\n\n // The fix renames the parameter to `props` and re-destructures it in the body\n // (`const <pattern> = props`). If the pattern already binds `props` (e.g. a\n // `...props` rest, a `{ props }` shorthand, or a `{ data: props }` rename), that\n // body binding collides with the new parameter and yields an invalid \"Duplicate\n // declaration props\". No safe rename keeps the `props` name the rule mandates \u2014\n // and an ESLint fixer cannot scope-rename the downstream `props.*` usages a rename\n // would require \u2014 so these patterns are still reported (the inline destructuring is\n // a violation regardless) but WITHOUT an autofix; the developer resolves them by hand.\n const boundNames = new Set<string>()\n\n collectBoundNames(firstParam, boundNames)\n\n const bindsProps = boundNames.has('props')\n\n const objectPattern = firstParam as AnnotatedPattern\n\n context.report({\n node: firstParam,\n messageId: 'destructureOnNewLine',\n fix: bindsProps\n ? undefined\n : (fixer) => {\n const text = sourceCode.getText()\n const annotation = objectPattern.typeAnnotation\n\n const patternStart = objectPattern.range![0]\n const patternEnd = annotation ? annotation.range![0] : objectPattern.range![1]\n const fullEnd = annotation ? annotation.range![1] : objectPattern.range![1]\n\n const patternText = text.slice(patternStart, patternEnd).trim()\n const annotationText = annotation ? sourceCode.getText(annotation) : ''\n\n const fixes = [fixer.replaceTextRange([patternStart, fullEnd], `props${annotationText}`)]\n\n const destructureStatement = `const ${patternText} = props`\n\n // Indentation of the line the component is declared on, used as the base for inserted code.\n const lines = sourceCode.getLines()\n const declarationLine = lines[node.loc!.start.line - 1] ?? ''\n const baseIndent = declarationLine.slice(0, declarationLine.length - declarationLine.trimStart().length)\n const innerIndent = `${baseIndent} `\n\n if (node.body.type === 'BlockStatement') {\n const [firstStatement] = node.body.body\n\n if (firstStatement) {\n const indent = ' '.repeat(firstStatement.loc!.start.column)\n\n fixes.push(fixer.insertTextBefore(firstStatement, `${destructureStatement}\\n\\n${indent}`))\n } else {\n const openBrace = sourceCode.getFirstToken(node.body)!\n\n fixes.push(fixer.insertTextAfter(openBrace, `\\n${innerIndent}${destructureStatement}\\n${baseIndent}`))\n }\n\n return fixes\n }\n\n // Expression-bodied arrow (implicit return) \u2014 wrap it in a block.\n const bodyText = sourceCode.getText(node.body)\n\n fixes.push(\n fixer.replaceText(\n node.body,\n `{\\n${innerIndent}${destructureStatement}\\n\\n${innerIndent}return ${bodyText}\\n${baseIndent}}`,\n ),\n )\n\n return fixes\n },\n })\n }\n\n return {\n ArrowFunctionExpression: check,\n FunctionDeclaration: check,\n FunctionExpression: check,\n }\n },\n}\n\nexport default propsDestructuringNewline\n", "import type { Rule } from 'eslint'\n\nimport type { ComponentFunction } from '../utils/component'\nimport { getAnnotatedParam, getComponentName, getPropsTypeNameFromFunction, isComponent } from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n}\n\nconst PROPS_SUFFIX = 'Props'\n\nexport const propsTypeName: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n \"Require a React component's props type to be named `<ComponentName>Props` (e.g. `ButtonProps` for `Button`).\",\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. When provided, the rule only runs for files whose path matches one of them.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. The rule is skipped for files whose path matches one of them, even if it also matches `paths`.',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n propsTypeNameMismatch: \"A component's props type must be named `{{expected}}`, but it is named `{{actual}}`.\",\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n const check = (node: ComponentFunction): void => {\n if (!isComponent(node)) {\n return\n }\n\n // An anonymous component (e.g. `export default () => ...`) has no name to derive the\n // expected props type name from, so the convention cannot be checked.\n const componentName = getComponentName(node)\n\n if (componentName === null) {\n return\n }\n\n // Only a simple named type reference is checked. An inline object type is the\n // `props-type-reference` rule's concern; qualified names and generics are out of scope and\n // resolve to null. A component with no typed props parameter is likewise not constrained.\n const actual = getPropsTypeNameFromFunction(node)\n\n if (actual === null) {\n return\n }\n\n const expected = `${componentName}${PROPS_SUFFIX}`\n\n if (actual === expected) {\n return\n }\n\n // `getPropsTypeNameFromFunction` only returns non-null when the first parameter carries a\n // named type reference, so an annotated parameter is guaranteed to exist here.\n context.report({\n node: getAnnotatedParam(node.params[0]!),\n messageId: 'propsTypeNameMismatch',\n data: { expected, actual },\n })\n }\n\n return {\n ArrowFunctionExpression: check,\n FunctionDeclaration: check,\n FunctionExpression: check,\n }\n },\n}\n\nexport default propsTypeName\n", "import type { Rule } from 'eslint'\n\nimport type { ComponentFunction } from '../utils/component'\nimport { getAnnotatedParam, getComponentName, isComponent } from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n}\n\n// TS-only nodes are not modelled by estree, so we view them through a minimal two-level\n// structural interface: the `TSTypeAnnotation` wrapper a parser attaches to a parameter, and\n// its inner type node. An inline object type is `TSTypeLiteral`; a named type is `TSTypeReference`.\ninterface AnnotatedNode {\n typeAnnotation?: {\n typeAnnotation?: { type?: string }\n }\n}\n\nconst INLINE_OBJECT_TYPE = 'TSTypeLiteral'\n\nexport const propsTypeReference: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n \"Require a React component's props parameter to use a named type (e.g. `ButtonProps`) instead of an inline object type literal.\",\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. When provided, the rule only runs for files whose path matches one of them.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'Optional glob patterns. The rule is skipped for files whose path matches one of them, even if it also matches `paths`.',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n useNamedPropsType:\n \"Use a named props type (e.g. `{{name}}Props`) instead of an inline object type for this component's props.\",\n useNamedPropsTypeAnonymous: \"Use a named props type instead of an inline object type for this component's props.\",\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n const check = (node: ComponentFunction): void => {\n const firstParam = node.params[0]\n\n if (!firstParam || !isComponent(node)) {\n return\n }\n\n const annotatedParam = getAnnotatedParam(firstParam)\n const innerType = (annotatedParam as AnnotatedNode).typeAnnotation?.typeAnnotation?.type\n\n if (innerType !== INLINE_OBJECT_TYPE) {\n return\n }\n\n const name = getComponentName(node)\n\n context.report(\n name === null\n ? { node: annotatedParam, messageId: 'useNamedPropsTypeAnonymous' }\n : { node: annotatedParam, messageId: 'useNamedPropsType', data: { name } },\n )\n }\n\n return {\n ArrowFunctionExpression: check,\n FunctionDeclaration: check,\n FunctionExpression: check,\n }\n },\n}\n\nexport default propsTypeReference\n", "import type { Rule } from 'eslint'\nimport { existsSync } from 'node:fs'\nimport path from 'node:path'\n\nimport { bodyDeclaresComponent } from '../utils/component'\nimport { matchesAnyGlob } from '../utils/path-match'\nimport type { ExtraTarget, StoryPathOptions } from '../utils/story-path'\nimport { DEFAULT_STORY_PATH_OPTIONS, classifyComponent, deriveExpectedStoryPaths } from '../utils/story-path'\n\ninterface Options {\n paths?: string[]\n ignore?: string[]\n storiesDir?: string\n storySuffix?: string\n storyExtensions?: string[]\n componentSuffix?: string\n requireComponentAst?: boolean\n extraTargets?: ExtraTarget[]\n}\n\n/** Pick the story-path knobs out of the rule options, leaving defaults to the helper. */\nconst toStoryPathOptions = (options: Options): Partial<StoryPathOptions> => {\n const picked: Partial<StoryPathOptions> = {}\n\n if (options.storiesDir !== undefined) {\n picked.storiesDir = options.storiesDir\n }\n\n if (options.storySuffix !== undefined) {\n picked.storySuffix = options.storySuffix\n }\n\n if (options.storyExtensions !== undefined) {\n picked.storyExtensions = options.storyExtensions\n }\n\n if (options.componentSuffix !== undefined) {\n picked.componentSuffix = options.componentSuffix\n }\n\n if (options.extraTargets !== undefined) {\n picked.extraTargets = options.extraTargets\n }\n\n return picked\n}\n\nexport const requireComponentStories: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: {\n description: 'Require a co-located Storybook story for every dumb component.',\n recommended: true,\n url: 'https://github.com/ArthurSaenz/infra-kit/tree/main/apps/infra-kit/eslint-plugin',\n },\n schema: [\n {\n type: 'object',\n properties: {\n paths: {\n type: 'array',\n items: { type: 'string' },\n description: 'Optional globs; when provided the rule only runs for files whose path matches one.',\n },\n ignore: {\n type: 'array',\n items: { type: 'string' },\n description: 'Optional globs; the rule is skipped for matching files, even if they also match `paths`.',\n },\n storiesDir: {\n type: 'string',\n description: `Story directory name (default '${DEFAULT_STORY_PATH_OPTIONS.storiesDir}').`,\n },\n storySuffix: {\n type: 'string',\n description: `Suffix inserted before the extension (default '${DEFAULT_STORY_PATH_OPTIONS.storySuffix}').`,\n },\n storyExtensions: {\n type: 'array',\n items: { type: 'string' },\n description: 'Extensions a satisfying story file may have, in priority order.',\n },\n componentSuffix: {\n type: 'string',\n description: `Basename suffix a component file must end with (default '${DEFAULT_STORY_PATH_OPTIONS.componentSuffix}'; '' disables).`,\n },\n requireComponentAst: {\n type: 'boolean',\n description: 'When true (default), only require a story for files that actually declare a component.',\n },\n extraTargets: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n componentsDir: { type: 'string' },\n anchorParentDir: { type: 'string' },\n storyMode: { enum: ['feature-root', 'sibling'] },\n },\n required: ['componentsDir', 'storyMode'],\n additionalProperties: false,\n },\n description: 'Extra structured component layouts (componentsDir + optional anchorParentDir + storyMode).',\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n missingStory: \"Dumb component '{{component}}' is missing a Storybook story (expected at '{{expected}}').\",\n },\n },\n\n create(context) {\n const options = (context.options[0] ?? {}) as Options\n const paths = options.paths ?? []\n const ignore = options.ignore ?? []\n const requireComponentAst = options.requireComponentAst ?? true\n const storyPathOptions = toStoryPathOptions(options)\n\n // `ignore` takes precedence: skip excluded files even when they also match `paths`.\n if (ignore.length > 0 && matchesAnyGlob(context.filename, ignore)) {\n return {}\n }\n\n if (paths.length > 0 && !matchesAnyGlob(context.filename, paths)) {\n return {}\n }\n\n return {\n Program(program) {\n // Is this file a dumb component that requires a story, and where would the story live?\n if (!classifyComponent(context.filename, storyPathOptions)) {\n return\n }\n\n // Only enforce on files that actually declare a component (avoids flagging stray\n // non-component files placed under a components/ directory).\n if (requireComponentAst && !bodyDeclaresComponent(program.body)) {\n return\n }\n\n const candidates = deriveExpectedStoryPaths(context.filename, storyPathOptions)\n\n // The story is satisfied if ANY candidate (by extension) exists on disk.\n const hasStory = candidates.some((candidate) => {\n return existsSync(candidate)\n })\n\n if (hasStory) {\n return\n }\n\n context.report({\n node: program,\n messageId: 'missingStory',\n data: {\n component: path.posix.basename(context.filename.split('\\\\').join('/')),\n expected: candidates[0] ?? '',\n },\n })\n },\n }\n },\n}\n\nexport default requireComponentStories\n", "import path from 'node:path'\n\n/** Where a story file lives relative to its component. */\nexport type StoryMode = 'feature-root' | 'sibling'\n\n/** A consumer-defined extra component layout (structured \u2014 never a glob). */\nexport interface ExtraTarget {\n /** Immediate parent directory name a component file must sit directly inside. */\n componentsDir: string\n /** Optional grandparent directory name gate (e.g. `features`). */\n anchorParentDir?: string\n /** Where the story is expected for files matched by this target. */\n storyMode: StoryMode\n}\n\nexport interface StoryPathOptions {\n /** Story directory name (default `__stories__`). */\n storiesDir: string\n /** Suffix inserted before the extension (default `.stories`). */\n storySuffix: string\n /** Extensions a satisfying story file may have, in priority order. */\n storyExtensions: string[]\n /** Extensions a file must have to be considered a component. */\n componentExtensions: string[]\n /** Basename suffix a component file must end with (default `-component`; `''` disables). */\n componentSuffix: string\n /** Additional structured component layouts beyond the two built-ins. */\n extraTargets: ExtraTarget[]\n}\n\nexport const DEFAULT_STORY_PATH_OPTIONS: StoryPathOptions = {\n storiesDir: '__stories__',\n storySuffix: '.stories',\n storyExtensions: ['.tsx', '.jsx', '.ts', '.js'],\n componentExtensions: ['.tsx', '.jsx'],\n componentSuffix: '-component',\n extraTargets: [],\n}\n\nconst resolveOptions = (opts?: Partial<StoryPathOptions>): StoryPathOptions => {\n return { ...DEFAULT_STORY_PATH_OPTIONS, ...opts }\n}\n\n/** Normalize OS-native separators to posix so all downstream path logic is deterministic. */\nconst toPosix = (filePath: string): string => {\n return filePath.split('\\\\').join('/')\n}\n\ninterface ParsedComponent {\n /** Posix directory of the file. */\n dir: string\n /** Basename without its extension. */\n base: string\n /** Original extension (e.g. `.tsx`). */\n ext: string\n /** Immediate parent directory name. */\n parent: string\n /** Grandparent directory name. */\n grandparent: string\n /** Great-grandparent directory name. */\n greatGrandparent: string\n}\n\n/** Parse a file path into the segment view the gate and derivation both need. */\nconst parse = (filePath: string): ParsedComponent => {\n const normalized = toPosix(filePath)\n const segments = normalized.split('/')\n const basename = segments[segments.length - 1] ?? ''\n const ext = path.posix.extname(basename)\n const base = ext ? basename.slice(0, -ext.length) : basename\n\n return {\n dir: path.posix.dirname(normalized),\n base,\n ext,\n parent: segments[segments.length - 2] ?? '',\n grandparent: segments[segments.length - 3] ?? '',\n greatGrandparent: segments[segments.length - 4] ?? '',\n }\n}\n\n/** Whether the file passes the component preconditions (extension + name suffix). */\nconst passesComponentPreconditions = (parsed: ParsedComponent, options: StoryPathOptions): boolean => {\n if (!options.componentExtensions.includes(parsed.ext)) {\n return false\n }\n\n return options.componentSuffix === '' || parsed.base.endsWith(options.componentSuffix)\n}\n\n/**\n * Classify a file as a dumb component requiring a story, resolving WHERE its story should live.\n * Returns null when the file is not a component-requiring-a-story under any branch.\n *\n * Exactly one admit-condition may hold:\n * - feature-root: direct child of `components/` whose chain is `features/<f>/components`.\n * - sibling: a `components/default/<name>-component` file (parent `default`, grandparent `components`).\n * - extraTargets: a structured consumer-defined layout.\n */\nexport const classifyComponent = (filePath: string, opts?: Partial<StoryPathOptions>): { mode: StoryMode } | null => {\n const options = resolveOptions(opts)\n const parsed = parse(filePath)\n\n if (!passesComponentPreconditions(parsed, options)) {\n return null\n }\n\n // (a) feature-root \u2014 immediate parent is `components` AND the chain is `features/<feature>/components`.\n if (parsed.parent === 'components' && parsed.greatGrandparent === 'features') {\n return { mode: 'feature-root' }\n }\n\n // (b) sibling \u2014 `components/default/<name>-component.*` (NOT a direct child of `components/`).\n if (parsed.parent === 'default' && parsed.grandparent === 'components') {\n return { mode: 'sibling' }\n }\n\n // (c) extraTargets \u2014 structured layouts (componentsDir + optional anchorParentDir).\n for (const target of options.extraTargets) {\n const parentMatches = parsed.parent === target.componentsDir\n const anchorMatches = target.anchorParentDir == null || parsed.grandparent === target.anchorParentDir\n\n if (parentMatches && anchorMatches) {\n return { mode: target.storyMode }\n }\n }\n\n return null\n}\n\n/**\n * Ordered candidate story paths for a component file. Empty when the file is not a\n * component-requiring-a-story (see {@link classifyComponent}). The story is considered present\n * when ANY candidate exists on disk.\n */\nexport const deriveExpectedStoryPaths = (filePath: string, opts?: Partial<StoryPathOptions>): string[] => {\n const options = resolveOptions(opts)\n const classification = classifyComponent(filePath, options)\n\n if (!classification) {\n return []\n }\n\n const parsed = parse(filePath)\n\n // feature-root: dirname(file) is `.../components`, so its parent is the feature root.\n // sibling: the story dir sits next to the component file itself.\n const storyBaseDir = classification.mode === 'feature-root' ? path.posix.dirname(parsed.dir) : parsed.dir\n const storyDir = path.posix.join(storyBaseDir, options.storiesDir)\n\n return options.storyExtensions.map((extension) => {\n return path.posix.join(storyDir, `${parsed.base}${options.storySuffix}${extension}`)\n })\n}\n", "import type { Rule } from 'eslint'\n\nimport { componentArrowFunction } from './component-arrow-function'\nimport { componentFileOrder } from './component-file-order'\nimport { propsDestructuringBlankLine } from './props-destructuring-blank-line'\nimport { propsDestructuringNewline } from './props-destructuring-newline'\nimport { propsTypeName } from './props-type-name'\nimport { propsTypeReference } from './props-type-reference'\nimport { requireComponentStories } from './require-component-stories'\n\nexport const rules: Record<string, Rule.RuleModule> = {\n 'props-destructuring-newline': propsDestructuringNewline,\n 'props-destructuring-blank-line': propsDestructuringBlankLine,\n 'props-type-reference': propsTypeReference,\n 'props-type-name': propsTypeName,\n 'component-file-order': componentFileOrder,\n 'component-arrow-function': componentArrowFunction,\n 'require-component-stories': requireComponentStories,\n}\n", "import type { ESLint, Linter } from 'eslint'\n\nimport { rules } from './rules'\n\nconst PLUGIN_NAME = '@wl'\n\nconst plugin: ESLint.Plugin & { configs: Record<string, Linter.Config | Linter.Config[]> } = {\n meta: {\n name: '@wl/eslint-plugin',\n version: '0.1.14',\n },\n rules,\n configs: {},\n}\n\n/**\n * Flat-config preset that registers the plugin and turns every rule on, scoped to\n * the files each rule is meant for. It is an array of config blocks, so spread it:\n *\n * @example\n * import wl from '@wl/eslint-plugin'\n *\n * export default [...wl.configs.recommended]\n */\nplugin.configs.recommended = [\n {\n files: ['**/*.tsx'],\n plugins: {\n [PLUGIN_NAME]: plugin,\n },\n rules: {\n [`${PLUGIN_NAME}/props-destructuring-newline`]: 'error',\n [`${PLUGIN_NAME}/props-destructuring-blank-line`]: 'error',\n [`${PLUGIN_NAME}/props-type-reference`]: 'error',\n [`${PLUGIN_NAME}/props-type-name`]: 'error',\n [`${PLUGIN_NAME}/component-file-order`]: 'error',\n // Pages and routes are excluded: route/page modules commonly use `function`\n // declarations (and framework conventions like default-exported page functions).\n [`${PLUGIN_NAME}/component-arrow-function`]: ['error', { ignore: ['**/pages/**', '**/routes/**'] }],\n [`${PLUGIN_NAME}/require-component-stories`]: 'error',\n },\n },\n // Storybook stories legitimately deviate from the component conventions: the\n // imports \u2192 *Props \u2192 component order (meta/args/decorators/render fns), and\n // named templates that reference the *component's* props type (e.g.\n // `const Template = (args: ButtonProps) => ...`) rather than their own\n // `<TemplateName>Props`. So both the ordering and the props-type-name rules\n // would only produce noise there. Every other rule stays enabled for stories.\n {\n files: ['**/*.stories.{ts,tsx}'],\n rules: {\n [`${PLUGIN_NAME}/component-file-order`]: 'off',\n [`${PLUGIN_NAME}/props-type-name`]: 'off',\n },\n },\n]\n\nexport const meta: ESLint.Plugin['meta'] = plugin.meta\nexport const configs: Record<string, Linter.Config | Linter.Config[]> = plugin.configs\nexport { rules }\n\nexport default plugin\n"],
5
+ "mappings": ";AAUA,IAAM,4BAA4B,oBAAI,IAAI,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ACA,OAAO;AAAA,MACL,CAAC,GAAG,WAAW,8BAA8B,GAAG;AAAA,MAChD,CAAC,GAAG,WAAW,iCAAiC,GAAG;AAAA,MACnD,CAAC,GAAG,WAAW,uBAAuB,GAAG;AAAA,MACzC,CAAC,GAAG,WAAW,kBAAkB,GAAG;AAAA,MACpC,CAAC,GAAG,WAAW,uBAAuB,GAAG;AAAA;AAAA;AAAA,MAGzC,CAAC,GAAG,WAAW,2BAA2B,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,eAAe,cAAc,EAAE,CAAC;AAAA,MAClG,CAAC,GAAG,WAAW,4BAA4B,GAAG;AAAA,IAChD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AAAA,IACE,OAAO,CAAC,uBAAuB;AAAA,IAC/B,OAAO;AAAA,MACL,CAAC,GAAG,WAAW,uBAAuB,GAAG;AAAA,MACzC,CAAC,GAAG,WAAW,kBAAkB,GAAG;AAAA,IACtC;AAAA,EACF;AACF;AAEO,IAAM,OAA8B,OAAO;AAC3C,IAAM,UAA2D,OAAO;AAG/E,IAAO,gBAAQ;",
6
+ "names": ["fn", "PROPS_SUFFIX", "path", "path"]
7
7
  }
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const propsTypeName: Rule.RuleModule;
3
+ export default propsTypeName;
@@ -14,6 +14,22 @@ export declare const isComponent: (node: ComponentFunction) => boolean;
14
14
  * null when no function is found.
15
15
  */
16
16
  export declare const getComponentFunction: (node: ESTree.Node | null | undefined) => ComponentFunction | null;
17
+ /**
18
+ * The parameter that actually carries the props type annotation. A default value wraps the
19
+ * parameter in an `AssignmentPattern` (`(props: Props = {})`), moving the annotation onto its
20
+ * `.left`; unwrap one layer so the annotation is found either way.
21
+ */
22
+ export declare const getAnnotatedParam: (param: ESTree.Pattern) => ESTree.Pattern;
23
+ /** The named type referenced by a component function's first parameter (`Props`), or null. */
24
+ export declare const getPropsTypeNameFromFunction: (node: ComponentFunction) => string | null;
25
+ /**
26
+ * Resolve the props type name a component *uses* — the named type on its first parameter —
27
+ * looking through component wrappers (`memo`/`forwardRef`). Returns null when the component is
28
+ * anonymous of props (no parameter) or its props type is not a simple named reference (inline
29
+ * object, qualified name, generic). Mirrors `getDeclaredComponentName`'s node dispatch so a
30
+ * `const`-declared arrow component resolves through its `init`, not the `VariableDeclaration`.
31
+ */
32
+ export declare const getComponentPropsTypeName: (node: ESTree.Node | null) => string | null;
17
33
  /** Unwrap an `export ...` statement to the declaration it wraps (or the statement itself). */
18
34
  export declare const unwrapExport: (statement: ESTree.Statement | ESTree.ModuleDeclaration) => ESTree.Node | null;
19
35
  /** Whether a single top-level declaration declares a React component. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@slip-stream-kit/eslint-plugin",
3
3
  "type": "module",
4
- "version": "0.1.13",
4
+ "version": "0.1.17",
5
5
  "description": "Custom ESLint rules enforcing the white-label frontend architecture conventions",
6
6
  "author": "Arthur Saenko <arthur.saenz7@gmail.com> (https://github.com/ArthurSaenz)",
7
7
  "license": "MIT",
package/readme.md CHANGED
@@ -11,8 +11,8 @@ pnpm add -D @wl/eslint-plugin
11
11
  ## Usage (flat config)
12
12
 
13
13
  Enable everything via the recommended preset. It is an array of config blocks
14
- (rules scoped to `*.tsx`, with `component-file-order` turned off for
15
- `*.stories.{ts,tsx}`), so spread it:
14
+ (rules scoped to `*.tsx`, with `component-file-order` and `props-type-name`
15
+ turned off for `*.stories.{ts,tsx}`), so spread it:
16
16
 
17
17
  ```js
18
18
  // eslint.config.js
@@ -136,12 +136,61 @@ matching files, `ignore` skips matching files (and takes precedence over
136
136
  }
137
137
  ```
138
138
 
139
+ ### `props-type-name`
140
+
141
+ A React component's props type must be named **`<ComponentName>Props`** (e.g.
142
+ `ButtonProps` for `Button`). This complements `props-type-reference`: that rule
143
+ requires a _named_ type (not an inline literal); this rule requires that name to
144
+ follow the convention. Report-only.
145
+
146
+ ```tsx
147
+ // ❌ Incorrect — props type does not match the component name
148
+ const Button = (props: Props) => <button>{props.label}</button>
149
+ function Card({ title }: CardConfig) {
150
+ return <div>{title}</div>
151
+ }
152
+
153
+ // ✅ Correct — `<ComponentName>Props`
154
+ const Button = (props: ButtonProps) => <button>{props.label}</button>
155
+ function Card({ title }: CardProps) {
156
+ return <div>{title}</div>
157
+ }
158
+ ```
159
+
160
+ The component is detected the same way as the other rules (PascalCase name
161
+ through `memo`/`forwardRef`/`observer` wrappers, or a JSX return). Only a simple
162
+ named type reference on the first parameter is checked: inline object types are
163
+ the `props-type-reference` rule's concern, and anonymous components, untyped
164
+ props, and qualified/generic annotations (`NS.Props`, `FC<Props>`) are left
165
+ alone. An imported props type with a non-conventional name is still flagged —
166
+ use `paths`/`ignore` to exempt it.
167
+
168
+ The recommended preset turns this rule **off for `*.stories.{ts,tsx}`**: story
169
+ templates legitimately reference the component's own props type (e.g.
170
+ `const Template = (args: ButtonProps) => ...`) rather than `<TemplateName>Props`.
171
+
172
+ #### Option: `paths` / `ignore` (optional)
173
+
174
+ Same glob semantics as `component-file-order`: `paths` restricts the rule to
175
+ matching files, `ignore` skips matching files (and takes precedence over
176
+ `paths`).
177
+
178
+ ```js
179
+ {
180
+ rules: {
181
+ '@wl/props-type-name': ['error', { ignore: ['**/*.stories.tsx'] }],
182
+ },
183
+ }
184
+ ```
185
+
139
186
  ### `component-file-order`
140
187
 
141
188
  Enforce a strict top-level order in files that contain a React component:
142
- **imports → component props interface/type → component declaration**. Constants
143
- and helpers between the interface and the component are allowed. Report-only (it
144
- does not auto-reorder code).
189
+ **imports → component props interface/type → component declaration**, with the
190
+ props interface declared **immediately before** the component no constants,
191
+ helpers, or other declarations wedged between them. Helpers are allowed _after_
192
+ the component (or between two separate component blocks). Report-only (it does
193
+ not auto-reorder code).
145
194
 
146
195
  ```tsx
147
196
  // ❌ Incorrect — interface before imports, or component before its interface
@@ -162,15 +211,18 @@ const Card = (props: CardProps) => {
162
211
  }
163
212
  ```
164
213
 
165
- The rule activates only when the file actually contains a component. The "props
166
- interface" is any top-level `interface`/`type` whose name ends in `Props`.
214
+ The rule activates only when the file actually contains a component. A
215
+ component's props interface is matched by the **type its parameter actually
216
+ references** (e.g. `Props` in `(props: Props)`), not by a name convention — so an
217
+ interface named anything is enforced, as long as the component uses it. (When the
218
+ parameter has no resolvable named type, the rule falls back to looking for a
219
+ `<ComponentName>Props` interface.)
167
220
 
168
221
  When the first component's props type is **imported** (e.g.
169
222
  `import type { CardProps } from './types'`) instead of declared in the file,
170
223
  there is no in-file interface to anchor against — so the component itself must
171
224
  sit immediately after the imports, with no stray top-level definitions wedged in
172
- between. Only the first component is anchored this way; the props binding must be
173
- the conventional `<ComponentName>Props` name for the check to apply.
225
+ between. Only the first component is anchored this way.
174
226
 
175
227
  ```tsx
176
228
  // ❌ Incorrect — props imported, but a stray const sits before the component