Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

🐛 noInnerDeclarations incorrectly reports on functions in esm/strict mode #4492

Closed
1 task done
nstepien opened this issue May 16, 2023 · 1 comment · Fixed by #4500
Closed
1 task done

🐛 noInnerDeclarations incorrectly reports on functions in esm/strict mode #4492

nstepien opened this issue May 16, 2023 · 1 comment · Fixed by #4500
Assignees
Labels
A-Linter Area: linter S-Bug: confirmed Status: report has been confirmed as a valid bug

Comments

@nstepien
Copy link
Contributor

Environment information

https://docs.rome.tools/playground/?quoteStyle=single&code=aQBmACAAKABNAGEAdABoAC4AcgBhAG4AZABvAG0AKAApACAAIQA9AD0AIAAtADEAKQAgAHsACgAgACAAYwBvAG4AcwB0ACAAdgBhAGwAIAA9ACAAMQA7AAoACgAgACAAZgB1AG4AYwB0AGkAbwBuACAAbQB5AEYAbgAoACkAIAB7AAoAIAAgACAAIABjAG8AbgBzAG8AbABlAC4AbABvAGcAKAAnAGMAYQBsAGwAZQBkACAAbQB5AEYAbgAnACwAIAB2AGEAbAApADsACgAgACAAfQAKAH0ACgAKAG0AeQBGAG4AKAApADsACgAKAGUAeABwAG8AcgB0ACAAewB9ADsACgA%3D

What happened?

In the playground example:

  1. myFn accesses val in the block scope, so moving it outside the block would break myFn.
  2. myFn is scoped to the block in esm/strict mode, so there's nothing wrong with keeping it in the block.
    Calling myFn() from outside the block would throw an error. Typescript correctly reports it (Cannot find name 'myFn'.)

Expected result

From the ESLint docs for no-inner-declarations:

The function declaration portion rule will be rendered obsolete when block-scoped functions land in ES6, but until then, it should be left on to enforce valid constructions.

The rule should only catch functions in blocks when the file is not an ESM or when the block is not in strict mode.

Code of Conduct

  • I agree to follow Rome's Code of Conduct
@nstepien nstepien added the S-To triage Status: user report of a possible bug that needs to be triaged label May 16, 2023
@ematipico ematipico added S-Bug: confirmed Status: report has been confirmed as a valid bug A-Linter Area: linter and removed S-To triage Status: user report of a possible bug that needs to be triaged labels May 16, 2023
@ematipico
Copy link
Contributor

@Conaclos Now that the analyzer can read the FileSource (the source type), we should be able to enhance the rule

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter S-Bug: confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants