Incorrectly removing used imports
See original GitHub issueI have the following file:
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { UserEntity } from './user.entity';
@Injectable()
export class UsersService {
constructor(
@InjectRepository(UserEntity)
private readonly _usersRepository: Repository<UserEntity>,
) {}
findAll(): Promise<UserEntity[]> {
return this._usersRepository.find();
}
}
After running eslint fix, it deletes import { Repository } from 'typeorm';
while @typescript-eslint/no-unused-vars
does not detect it as unused import originally
eslint output:
3:10 error 'Repository' is defined but never used unused-imports/no-unused-imports-ts
✖ 1 problem (1 error, 0 warnings)
1 error and 0 warnings potentially fixable with the `--fix` option.
Eslint config:
{
"no-unused-vars": 0,
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports-ts": "error",
}
This is only a single file, but there are more files throughout my whole project where this is happening.
Only after adding "unused-imports/no-unused-imports-ts": "error",
a lot of used imports are being deleted.
When running ESLint with only:
{
"no-unused-vars": 0,
"@typescript-eslint/no-unused-vars": 2,
}
No unused import are detected
I’d be happy to provide more examples/code. Let me know!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
x/tools/cmd/goimports: incorrect removal of imports #29557
I believe that goimports has always removed apparently-unused imports, even when the file isn't fully satisfied, and that's the behavior I tried ...
Read more >Removing unused import in typescript removes wrong import
When using code action on an unused import it removes the import properly if the cursor was on the right declaration. However if...
Read more >Any reason to clean up unused imports in Java, other than ...
There was an improper import that a developer had used and abandoned (they used the class, auto-imported it, and then realized it was...
Read more >Java: Why You Remove Unused Imports - DataDrivenInvestor
It's a quick fix, literally just delete them. However, it led me to wonder what's wrong if they stay? There weren't any issues...
Read more >How to remove unused imports in VSCode. - LinkedIn
Follow these steps to setup settings in VS Code. Press [Command + , ] to open settings. Click on that top-right icon (Open...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Works like a charm now, thanks @sweepline !
@sweepline nice! Updating @typescript-eslint/parser seems to solve the problem!
Thank you!