import-js / import-js/eslint-plugin-import
`no-unused-modules` gives a false positive on TypeScript declaration files
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
In TypeScript, it is common to write declaration files for 3rd-party modules or global variables.
For example, a file called "foo.d.ts":
```typescript
declare const foo: number;
```
However, this file will be flagged by the `import/no-unused-modules` rule for not having any exports found.
But this is a spurious error - this file is not intended to have any exports. The only purpose of the file is to declare the "foo" global variable.
End-users can fix this spurious error by using the `ignoreExports` config option in their ESLint config like so:
```js
module.exports = {
rules: {
"import/no-unused-modules": [
"error",
{
missingExports: true,
unusedExports: true,
ignoreExports: ["src/**/*.d.ts"],
},
],
},
}
```
However, this is not optimal. I propose that the `no-unused-modules` rule should work for TypeScript users "out of the box", meaning that the rule should probably ignore "*.d.ts" files by default.
Contributor guide
Research direction
Start by locating the implementation and tests for the `import/no-unused-modules` rule, then reproduce the report with a `foo.d.ts` file containing only a global declaration. Done means declaration files no longer produce a missing-export false positive by default, with regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100