Skip to content

feat(eslint-plugin): [no-unused-var] handle implicit exports in declaration files #8611

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

Conversation

jakebailey
Copy link
Collaborator

PR Checklist

Overview

This modifies the unused variable analysis to ignore declarations that are "implicitly" exported. Roughly, this means declaration files which do not contain any exports, recursively into namespaces, excluding export import ... = ... which doesn't count.

This PR is not yet complete; I'm missing:

  • Look for export {} blocks, including empty ones (which probably don't show up in scope)
  • Check other ambient contexts like globals (need to query for that, and figure out the rules)
  • Consider whether I should actually move this into the rule and do things like those which use ambientDeclarationSelector
  • Consider whether this analysis can actually replace ambientDeclarationSelector entirely (if not vice versa)

I'm mainly having trouble at the moment debugging a single test; adding only to the test doesn't seem to really work and one of my tests fails for a reason I haven't figured out yet.

That and my continued issues with nx, where it always tells me that the tests pass, so I have to disable it, which can only be done via the checked in config file ☹️

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @jakebailey!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Mar 6, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit f9f18c5
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/65e8f850e46f9400093786ac
😎 Deploy Preview https://deploy-preview-8611--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 9 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@jakebailey jakebailey changed the title feat(eslint-plugin): [no-unused-var] Handle implicit exports in declaration files feat(eslint-plugin): [no-unused-var] handle implicit exports in declaration files Mar 6, 2024
}

for (const variable of scope.variables) {
if (isExported(variable) && !isExportImportEquals(variable)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare namespace Foo {
  const x = 1;
  export const y = 3;
}

Foo.x;
Foo.y;

The export doesn't always restrict other implicit, ambient exports, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the rules for this are super annoying. What I have currently may just be true only for declaration files, but "ambient" ones with declare (in ts files only?) may have different rules?

Copy link
Member

@bradzacher bradzacher Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these rules apply to both ts files and dts files as well
playground? Or did I misunderstand you?

It looks like export = is invalid in a namespace but I think that's the only case that invalidates this logic on declared namespaces.

So I think this entire function can just be updated to also short-circuit on if (namespace.declare) { return namespace_has_export_equals }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more issues than just this one IIRC; I've been so busy with other stuff that I haven't been able to sit down and actually fix this PR, sorry.

I'm also not 100% sure what works and doesn't work in the playground when it comes to d.ts files; not really something we often play with; I've been meaning to figure out something better for testing this

If it's bugging you all to stay open, I can close it, though if someone else attempts it too I'd love to review it and double check everything (but I don't think anyone's working on it besides me)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah Josh just pinged me cos I didn't respond :P
No rush at all.

@JoshuaKGoldberg
Copy link
Member

👋 just checking in @jakebailey, are you waiting on us for anything?

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period labels Jun 2, 2024
@jakebailey
Copy link
Collaborator Author

I honestly don't remember, I think I was blocked on "man the rules are complicated to implement" and finding time to figure them out to try again here.

@JoshuaKGoldberg
Copy link
Member

👍 should we close this out then? (do you know if you'll have time + priority soon?)

@jakebailey
Copy link
Collaborator Author

5.5 just closed so I'll probably have more time now, but I guess I don't know why closing it is helpful... Only been 2 months and I only stopped because I had some very high priority work elsewhere.

@jakebailey
Copy link
Collaborator Author

Or course if someone else wants to attempt it, be my guest, but I do want to see this fixed so I can run it on DT.

@JoshuaKGoldberg
Copy link
Member

Staying open it is!

We're just going through the backlog & trying to trim it down as much as we reasonably can.

@JoshuaKGoldberg JoshuaKGoldberg removed the stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period label Jun 2, 2024
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Feb 17, 2025

cc @ronami from #10714: should we close out this PR as superseded by that one?

@jakebailey
Copy link
Collaborator Author

Sure; I'll go look at that when I have a chance. It'd be nice to be able to enable this rule on DT.

@jakebailey jakebailey closed this Feb 17, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-unused-vars] False positives with members of exported namespace in .d.ts file
3 participants