-
Notifications
You must be signed in to change notification settings - Fork 0
chore: add @function tags to all arrow functions #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,389 @@ | ||||||||||||||
| /** | ||||||||||||||
| * ESLint rule to require `@function` tag in JSDoc comments for arrow functions | ||||||||||||||
| * | ||||||||||||||
| * @packageDocumentation | ||||||||||||||
| */ | ||||||||||||||
|
|
||||||||||||||
| import { | ||||||||||||||
| AST_NODE_TYPES, | ||||||||||||||
| AST_TOKEN_TYPES, | ||||||||||||||
| ESLintUtils, | ||||||||||||||
| } from '@typescript-eslint/utils'; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * @import {TSESTree} from "@typescript-eslint/typescript-estree" | ||||||||||||||
| */ | ||||||||||||||
| /** | ||||||||||||||
| * ESLint rule to require `@function` tag in JSDoc comments for arrow functions | ||||||||||||||
| * | ||||||||||||||
| * This rule enforces the presence of `@function` tags in JSDoc comments for | ||||||||||||||
| * arrow functions to improve code documentation and maintain consistency with | ||||||||||||||
| * the project's documentation standards. | ||||||||||||||
| * | ||||||||||||||
| * The rule supports: | ||||||||||||||
| * | ||||||||||||||
| * - Named arrow functions (`const foo = () => {}`) | ||||||||||||||
| * - Arrow functions in object properties (`{ method: () => {} }`) | ||||||||||||||
| * - Arrow functions in assignments (`obj.method = () => {}`) | ||||||||||||||
| * - Export declarations (`export const foo = () => {}`) | ||||||||||||||
| * | ||||||||||||||
| * Configuration options: | ||||||||||||||
| * | ||||||||||||||
| * - `requireForNamed`: Whether to require `@function` tags for named arrow | ||||||||||||||
| * functions (default: `true`) | ||||||||||||||
| * - `requireForAnonymous`: Whether to require `@function` tags for anonymous | ||||||||||||||
| * arrow functions (default: `false`) | ||||||||||||||
| */ | ||||||||||||||
| export default ESLintUtils.RuleCreator.withoutDocs({ | ||||||||||||||
| create(context, [options]) { | ||||||||||||||
| const sourceCode = context.sourceCode; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Determines if an arrow function should require a @function tag based on | ||||||||||||||
| * its context. | ||||||||||||||
| * | ||||||||||||||
| * This function identifies "named" arrow functions, which are arrow | ||||||||||||||
| * functions that are assigned to a variable, property, or exported. These | ||||||||||||||
| * are distinguished from anonymous arrow functions used in callbacks or | ||||||||||||||
| * inline expressions. | ||||||||||||||
| * | ||||||||||||||
| * Supported patterns: | ||||||||||||||
| * | ||||||||||||||
| * - Variable declarations: `const foo = () => {}` | ||||||||||||||
| * - Object properties: `{ method: () => {} }` | ||||||||||||||
| * - Property assignments: `obj.method = () => {}` | ||||||||||||||
| * - Export declarations: `export const foo = () => {}` | ||||||||||||||
| * | ||||||||||||||
| * @example | ||||||||||||||
| * | ||||||||||||||
| * ```ts | ||||||||||||||
| * // Returns true for these patterns: | ||||||||||||||
| * const myFunc = () => {}; // Variable declaration | ||||||||||||||
| * obj.method = () => {}; // Property assignment | ||||||||||||||
| * const obj = { method: () => {} }; // Object property | ||||||||||||||
| * export const func = () => {}; // Export declaration | ||||||||||||||
| * | ||||||||||||||
| * // Returns false for these patterns: | ||||||||||||||
| * [1, 2, 3].map(() => {}); // Anonymous callback | ||||||||||||||
| * setTimeout(() => {}, 100); // Anonymous callback | ||||||||||||||
| * ``` | ||||||||||||||
| * | ||||||||||||||
| * @function | ||||||||||||||
| * @param {TSESTree.ArrowFunctionExpression} node - The arrow function AST | ||||||||||||||
| * node to check | ||||||||||||||
| * @returns {boolean} True if this arrow function should be considered | ||||||||||||||
| * "named" and potentially require a @function tag based on its syntactic | ||||||||||||||
| * context | ||||||||||||||
| */ | ||||||||||||||
| const shouldRequireTag = | ||||||||||||||
| /** | ||||||||||||||
| * @function | ||||||||||||||
| */ | ||||||||||||||
| (node) => { | ||||||||||||||
| const parent = node.parent; | ||||||||||||||
|
|
||||||||||||||
| if ( | ||||||||||||||
| parent?.type === AST_NODE_TYPES.VariableDeclarator && | ||||||||||||||
| parent.id?.type === AST_NODE_TYPES.Identifier | ||||||||||||||
| ) { | ||||||||||||||
| return true; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if ( | ||||||||||||||
| parent?.type === AST_NODE_TYPES.AssignmentExpression && | ||||||||||||||
| parent.left?.type === AST_NODE_TYPES.MemberExpression | ||||||||||||||
| ) { | ||||||||||||||
| return true; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (parent?.type === AST_NODE_TYPES.Property && parent.key) { | ||||||||||||||
| return true; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if ( | ||||||||||||||
| parent?.type === AST_NODE_TYPES.VariableDeclarator && | ||||||||||||||
| parent.parent?.parent?.type === AST_NODE_TYPES.ExportNamedDeclaration | ||||||||||||||
| ) { | ||||||||||||||
| return true; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
Comment on lines
+103
to
+109
|
||||||||||||||
| if ( | |
| parent?.type === AST_NODE_TYPES.VariableDeclarator && | |
| parent.parent?.parent?.type === AST_NODE_TYPES.ExportNamedDeclaration | |
| ) { | |
| return true; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation comment on lines 16-36 duplicates the comment at lines 1-5. The first comment is a package documentation comment, while the second one appears to be describing the same thing. This duplication creates unnecessary redundancy.