Skip to content
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

🐛 BUG: astro check reports false positive unused variable when variable is used in Astro.redirect #980

Closed
fengelniederhammer opened this issue Dec 11, 2024 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@fengelniederhammer
Copy link

Describe the Bug

astro check reports false positive when using import in return Astro.redirect( --> here <-- ).

For example here, it will report that MyObject is unused:

---
import { MyObject } from '../object';

return Astro.redirect(
    MyObject.asdfasdf,
);
---

This works as expected though (astro check recognizes MyObject as being used):

---
import { MyObject } from '../object';

let value = MyObject.asdfasdf;
return Astro.redirect(value);
---

A real-world example can be found in https://github.com/GenSpectrum/dashboards/blob/09e505a0bd82a87cf2d460dd3d70fff063eb1b0d/website/src/pages/covid/index.astro

Steps to Reproduce

  1. npm create astro@latest, npx astro check to install @astrojs/check - yields ATM:
  "dependencies": {
    "@astrojs/check": "^0.9.4",
    "astro": "^5.0.4",
    "typescript": "^5.7.2"
  }
  1. src/pages/index.astro:
---
import { MyObject } from '../object';

return Astro.redirect(
    MyObject.asdfasdf, // access a key that does not exist
);
---
  1. src/object.ts:
export const MyObject = {
    helloWorld: 'Hello World!',
}
  1. npx astro check:
$ npx astro check
11:12:10 [content] Syncing content
11:12:10 [content] Synced content
11:12:10 [types] Generated 26ms
11:12:10 [check] Getting diagnostics for Astro files in .../dashboards/astro/square-series...
src/pages/index.astro:2:1 - warning ts(6133): 'MyObject' is declared but its value is never read.

2 import { MyObject } from '../object';
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Result (4 files): 
- 0 errors
- 0 warnings
- 1 hint
  1. It reports a false positive on an unused variable (it is used - obviously). But it doesn't report the access to the non-existent key.

Link to Minimal Reproducible Example

GenSpectrum/dashboards@c209e44

@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 11, 2024
@Princesseuh
Copy link
Member

Duplicate of #476

@Princesseuh Princesseuh marked this as a duplicate of #476 Dec 11, 2024
@Princesseuh Princesseuh closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants