Skip to content

Enhancement: add strict parent types for nodes that have well-defined parents #10682

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

Closed
4 tasks done
ronami opened this issue Jan 19, 2025 · 1 comment · Fixed by #10685
Closed
4 tasks done

Enhancement: add strict parent types for nodes that have well-defined parents #10682

ronami opened this issue Jan 19, 2025 · 1 comment · Fixed by #10685
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

Comments

@ronami
Copy link
Member

ronami commented Jan 19, 2025

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

types

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

This PR is a very similar proposal to the one in #6225 and suggests having stricter parent types for some AST nodes:

  • ExportDefaultDeclaration has parent TSESTree.BlockStatement | TSESTree.Program | TSESTree.TSModuleBlock
  • ExportNamedDeclaration has parent TSESTree.BlockStatement | TSESTree.Program | TSESTree.TSModuleBlock
  • FunctionDeclaration with name has parent TSESTree.BlockStatement | TSESTree.ExportDefaultDeclaration | TSESTree.ExportNamedDeclaration | TSESTree.Program.
  • FunctionDeclaration without name has parent TSESTree.ExportDefaultDeclaration (reference).

This is a follow-up to the discussion in #10422 (comment).


Some thoughts/notes:

  • I've looked into @babel/parser, @swc/types, and @oxc-project/types (also the more technical 1, 2), but I didn't find anything that makes me confident this is valid in every case. I verified that @typescript-eslint itself is type-checked successfully with these assumptions.
  • TypeScript itself doesn't have a specific parent for FunctionDeclaration (it falls back to the generic ts.Node), although they do have stricter parent types for some other nodes.
  • To my understanding, TypeScript's AST doesn't have an actual AST node for ExportDefaultDeclaration or ExportNamedDeclaration, as they're expressed as modifiers.

Additional Info

No response

@ronami ronami added enhancement New feature or request triage Waiting for team members to take a look labels Jan 19, 2025
@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Jan 19, 2025
@JoshuaKGoldberg
Copy link
Member

My instinct is we're going to end up filing an issue like this every year or two as we keep finding more of these cases. 👍

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Feb 5, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.
Projects
None yet
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy