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

False positive on esnext 'using' declaration #55

Open
erictheswift opened this issue Oct 11, 2023 · 7 comments · May be fixed by #56
Open

False positive on esnext 'using' declaration #55

erictheswift opened this issue Oct 11, 2023 · 7 comments · May be fixed by #56

Comments

@erictheswift
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Explicit resource management proposal (using keyword) landed in typescript 5.2. prefer-let plugin false positively reacts on using aiming to replace it with let

Here is the diff that solved my problem:

diff --git a/node_modules/eslint-plugin-prefer-let/lib/rules/prefer-let.js b/node_modules/eslint-plugin-prefer-let/lib/rules/prefer-let.js
index 73d487f..abab361 100644
--- a/node_modules/eslint-plugin-prefer-let/lib/rules/prefer-let.js
+++ b/node_modules/eslint-plugin-prefer-let/lib/rules/prefer-let.js
@@ -55,7 +55,7 @@ module.exports = {
             message: 'prefer `let` over `var` to declare value bindings',
             node
           });
-        } else if (node.kind !== 'let' && !isTopLevelScope(node)) {
+        } else if (node.kind === 'const' && !isTopLevelScope(node)) {
           let constToken = sourceCode.getFirstToken(node);
 
           context.report({

This issue body was partially generated by patch-package.

@cowboyd
Copy link
Member

cowboyd commented Oct 12, 2023

@erictheswift Thanks for reporting this, and thanks for generating a fix. It's definitely something we should address. Is there a test case you add to the test suite to make sure that we don't experience any regression?

@erictheswift
Copy link
Author

Sure:

valid: [
    ...
    {code: "await using disposables = new AsyncDisposableStack()"},
    {code: "using disposables = new DisposableStack()"},
]

@cowboyd
Copy link
Member

cowboyd commented Dec 20, 2023

@erictheswift Thanks! This poses an interesting problem however, since the parser can't actually parse the source when I run the test. Only TypeScript understands this syntax and we aren't set up for running through TS.

For example, if I try to include these examples, it just gives me a syntax error:

AssertionError [ERR_ASSERTION]: A fatal parsing error occurred: Parsing error: Unexpected token disposable

Do you know of a common way to do test eslint plugins against TypeScript source?

@erictheswift
Copy link
Author

erictheswift commented Dec 20, 2023 via email

@erictheswift
Copy link
Author

erictheswift commented Dec 20, 2023

Do you know of a common way to do test eslint plugins against TypeScript source?

I guess this would require typescript parser specified as well as typescript as a dependency

@cowboyd
Copy link
Member

cowboyd commented Dec 20, 2023

@erictheswift I can just go ahead and merge this as-is, and then comment it back in when it is supported.

@erictheswift
Copy link
Author

@cowboyd sounds reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants