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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃拝 FileReaderSync Variable is undeclared #2121

Closed
1 task done
iivvaannxx opened this issue Mar 18, 2024 · 10 comments 路 Fixed by #2137
Closed
1 task done

馃拝 FileReaderSync Variable is undeclared #2121

iivvaannxx opened this issue Mar 18, 2024 · 10 comments 路 Fixed by #2137
Labels
A-Linter Area: linter good first issue Good for newcomers S-Enhancement Status: Improve an existing feature S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@iivvaannxx
Copy link

Environment information

CLI:
  Version:                      1.6.1
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.11.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "bun/1.0.30"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 false

Linter:
  Recommended:                  true
  All:                          false
  Rules:                        a11y/recommended = true
                                complexity/recommended = true
                                complexity/noStaticOnlyClass = "off"
                                complexity/useSimplifiedLogicExpression = "warn"
                                correctness/recommended = true
                                correctness/noUndeclaredVariables = "error"
                                performance/recommended = true
                                style/recommended = true
                                style/useBlockStatements = "error"
                                style/useCollapsedElseIf = "warn"
                                style/useNamingConvention = {"level":"error","options":{"strictCase":false,"enumMemberCase":"CONSTANT_CASE"}}
                                style/useShorthandArrayType = "error"
                                style/useShorthandAssign = "error"
                                style/useSingleCaseStatement = "error"
                                suspicious/recommended = true
                                suspicious/noApproximativeNumericConstant = "error"
                                suspicious/noMisrefactoredShorthandAssign = "warn"

Workspace:
  Open Documents:               0

Rule name

lint/correctness/noUndeclaredVariables

Playground link

https://biomejs.dev/playground/?lintRules=all&code=YwBvAG4AcwB0ACAAbgBvAHIAbQBhAGwAUgBlAGEAZABlAHIAIAA9ACAAbgBlAHcAIABGAGkAbABlAFIAZQBhAGQAZQByACgAKQA7ACAALwAvACAAVwBvAHIAawBzAAoAYwBvAG4AcwB0ACAAcwB5AG4AYwBSAGUAYQBkAGUAcgAgAD0AIABuAGUAdwAgAEYAaQBsAGUAUgBlAGEAZABlAHIAUwB5AG4AYwAoACkAOwAgAC8ALwAgAEYAbABhAGcAcwAgAGEAbgAgAGUAcgByAG8AcgAKAAoA

Expected result

It should not flag an error, the FileReaderSync API is only available on Web Workers but it still exists after all.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@Conaclos Conaclos added A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug labels Mar 18, 2024
@ematipico
Copy link
Member

@Conaclos I'm not sure this should be a bug. The API is not always available unless the JS file js executed in a worker context. How can Biome help here, considering the current infrastructure?

I think it makes more sense to use overrides, and declare a global for that single file

@iivvaannxx
Copy link
Author

@ematipico If it doesn't make sense then I will do what you say, just to extend a bit the issue, the function importScripts doesn't get recognized either. Just for you to know, in case you decide it to fix it.

@Conaclos Conaclos added S-Enhancement Status: Improve an existing feature and removed S-Bug-confirmed Status: report has been confirmed as a valid bug labels Mar 18, 2024
@Conaclos
Copy link
Member

@Conaclos I'm not sure this should be a bug. The API is not always available unless the JS file js executed in a worker context. How can Biome help here, considering the current infrastructure?

I think it makes more sense to use overrides, and declare a global for that single file

Yes. However, we could also claim that browser globals are not always available (for example in the backend) and Node globals are not always available (for example in a browser or in Deno).

We should certainly look for a way of declaring/detecting environments.

@iivvaannxx
Copy link
Author

iivvaannxx commented Mar 18, 2024

Important

In both cases it stops being flagged as an issue if you prepend self, like self.importScripts() and new self.FileReaderSync()

@ematipico
Copy link
Member

@ematipico If it doesn't make sense then I will do what you say, just to extend a bit the issue, the function importScripts doesn't get recognized either. Just for you to know, in case you decide it to fix it.

Thank you for your answer. My comment was a way to start a conversation and understand what's the best way to fix it. Probably it came off wrong. Sorry about that.

My suggestion is a workaround, so you don't need to wait for a fix for that.

@Conaclos you made a good point. It's possible that our globals are outdated

@iivvaannxx
Copy link
Author

iivvaannxx commented Mar 18, 2024

@ematipico Oh I didn't mean anything with what I said! I actually meant that if you said that it didn't make any sense then I would do what you said (you're a maintainer after all, you know how this works far better than me), which, by the way I already did! I apologize if it came off wrong too, I am not a native English speaker so it was probably not formulated very well.

What I meant with "in case you decide to fix it" it's because from your initial comment I understood that the issue could have been expected behaviour, and I wasn't sure if you were going to fix it or not.

@ematipico ematipico added good first issue Good for newcomers S-Help-wanted Status: you're familiar with the code base and want to help the project labels Mar 19, 2024
@ematipico
Copy link
Member

For anyone that wants to fix the issue, we should port this:

https://github.com/sindresorhus/globals/blob/9e2e2598dabdb845ff76c0c3acf5c52c812a64de/globals.json#L1443-L1726

In here:

https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/src/globals/mod.rs

Just create a new worker.rs file and follow the same pattern of the other files in that folder.

Then add a new check in here:

fn is_global(reference_name: &str, source_type: &JsFileSource) -> bool {

@Sec-ant
Copy link
Member

Sec-ant commented Mar 19, 2024

I think we already have worker globals defined in browser.rs

pub const WORKER: [&str; 71] = [

@ematipico
Copy link
Member

ematipico commented Mar 19, 2024

Look at that :D It seems we aren't using it, so that will be even simpler!

@Sec-ant
Copy link
Member

Sec-ant commented Mar 20, 2024

I'd like to work on this. I plan to update the globals and also fix the rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter good first issue Good for newcomers S-Enhancement Status: Improve an existing feature S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants