Skip to content

[no-unused-vars] False positive for "export import Namespace" #4129

Closed
@MBuchalik

Description

@MBuchalik
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  overrides: [
    {
      files: ['*.ts'],
      extends: [
        'plugin:@typescript-eslint/recommended',
      ],
      rules: {
        '@typescript-eslint/no-unused-vars': 'error',
      },
    },
  ],
};
/* eslint-disable @typescript-eslint/no-namespace */

namespace Bar {
  export const bar = 123;
}

export namespace Foo {
  export import TheBar = Bar;
}

TSConfig:

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "strict": true,
    "noImplicitOverride": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "declaration": true,
    "baseUrl": ".",
    "lib": ["es2020"],
    "outDir": "dist"
  },
  "include": ["src/**/*.ts"]
}

Expected Result

I expected no "no-unused-vars" error on TheBar, since I am exporting both Foo and TheBar.

Actual Result

On TheBar, I am getting the error 'TheBar' is defined but never used`

grafik

Additional Info

I am not familiar with the --debug output, but I cannot really see anything that could point to the reason of the problem. Still, this is the debug output, maybe it helps:

2021-11-12T16:17:46.824Z eslint:cli Running on files
2021-11-12T16:17:46.843Z eslintrc:config-array-factory Loading JSON config file: E:\path-to-my-ts-project\package.json
2021-11-12T16:17:46.845Z eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], 
basePath: 'E:\\path-to-my-ts-project', loose: false } ]
2021-11-12T16:17:46.848Z eslintrc:ignore-pattern   processed: { basePath: 'E:\\path-to-my-ts-project', patterns: [ 
'/**/node_modules/*' ] }
2021-11-12T16:17:46.849Z eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], 
basePath: 'E:\\path-to-my-ts-project', loose: false } ]
2021-11-12T16:17:46.849Z eslintrc:ignore-pattern   processed: { basePath: 'E:\\path-to-my-ts-project', patterns: [ 
'/**/node_modules/*' ] }
2021-11-12T16:17:46.850Z eslint:file-enumerator Start to iterate files: [ 'src' ]
2021-11-12T16:17:46.851Z eslint:file-enumerator Directory: E:\path-to-my-ts-project\src
2021-11-12T16:17:46.852Z eslint:file-enumerator Enter the directory: E:\path-to-my-ts-project\src
2021-11-12T16:17:46.852Z eslintrc:cascading-config-array-factory Load config files for E:\path-to-my-ts-project\src.
2021-11-12T16:17:46.853Z eslintrc:cascading-config-array-factory No cache found: E:\path-to-my-ts-project\src.
2021-11-12T16:17:46.854Z eslintrc:config-array-factory Config file not found on E:\path-to-my-ts-project\src
2021-11-12T16:17:46.854Z eslintrc:cascading-config-array-factory No cache found: E:\path-to-my-ts-project.
2021-11-12T16:17:46.854Z eslintrc:config-array-factory Loading JS config file: E:\path-to-my-ts-project\.eslintrc.js
2021-11-12T16:17:46.857Z eslintrc:config-array-factory Config file found: E:\path-to-my-ts-project\.eslintrc.js
2021-11-12T16:17:46.858Z eslintrc:config-array-factory Loading parser "@typescript-eslint/parser" from 
E:\path-to-my-ts-project\.eslintrc.js
2021-11-12T16:17:46.860Z eslintrc:config-array-factory Loaded: @typescript-eslint/parser@5.3.1 
(E:\path-to-my-ts-project\node_modules\@typescript-eslint\parser\dist\index.js)
2021-11-12T16:17:47.342Z eslintrc:config-array-factory Loading {extends:"plugin:@typescript-eslint/recommended"} 
relative to E:\path-to-my-ts-project\.eslintrc.js
2021-11-12T16:17:47.342Z eslintrc:config-array-factory Loading plugin "@typescript-eslint" from 
E:\path-to-my-ts-project\.eslintrc.js
2021-11-12T16:17:47.344Z eslintrc:config-array-factory Loaded: @typescript-eslint/eslint-plugin@5.3.1 
(E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\index.js)
2021-11-12T16:17:47.453Z eslint:rules Loading rule 'brace-style' (remaining=284)
2021-11-12T16:17:47.463Z eslint:rules Loading rule 'comma-dangle' (remaining=283)
2021-11-12T16:17:47.477Z eslint:rules Loading rule 'dot-notation' (remaining=282)
2021-11-12T16:17:47.485Z eslint:rules Loading rule 'indent' (remaining=281)
2021-11-12T16:17:47.491Z eslint:rules Loading rule 'init-declarations' (remaining=280)
2021-11-12T16:17:47.492Z eslint:rules Loading rule 'keyword-spacing' (remaining=279)
2021-11-12T16:17:47.494Z eslint:rules Loading rule 'lines-between-class-members' (remaining=278)
2021-11-12T16:17:47.523Z eslint:rules Loading rule 'no-dupe-class-members' (remaining=277)
2021-11-12T16:17:47.524Z eslint:rules Loading rule 'no-duplicate-imports' (remaining=276)
2021-11-12T16:17:47.527Z eslint:rules Loading rule 'no-empty-function' (remaining=275)
2021-11-12T16:17:47.531Z eslint:rules Loading rule 'no-extra-parens' (remaining=274)
2021-11-12T16:17:47.533Z eslint:rules Loading rule 'no-extra-semi' (remaining=273)
2021-11-12T16:17:47.546Z eslint:rules Loading rule 'no-invalid-this' (remaining=272)
2021-11-12T16:17:47.549Z eslint:rules Loading rule 'no-loop-func' (remaining=271)
2021-11-12T16:17:47.551Z eslint:rules Loading rule 'no-loss-of-precision' (remaining=270)
2021-11-12T16:17:47.552Z eslint:rules Loading rule 'no-magic-numbers' (remaining=269)
2021-11-12T16:17:47.584Z eslint:rules Loading rule 'no-restricted-imports' (remaining=268)
2021-11-12T16:17:47.645Z eslint:rules Loading rule 'no-unused-expressions' (remaining=267)
2021-11-12T16:17:47.648Z eslint:rules Loading rule 'no-useless-constructor' (remaining=266)
2021-11-12T16:17:47.654Z eslint:rules Loading rule 'object-curly-spacing' (remaining=265)
2021-11-12T16:17:47.691Z eslint:rules Loading rule 'quotes' (remaining=264)
2021-11-12T16:17:47.704Z eslint:rules Loading rule 'semi' (remaining=263)
2021-11-12T16:17:47.707Z eslint:rules Loading rule 'space-infix-ops' (remaining=262)
2021-11-12T16:17:47.732Z eslintrc:config-array-factory Plugin 
E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\index.js loaded in: 387ms
2021-11-12T16:17:47.732Z eslintrc:config-array-factory Loading {extends:"./configs/base"} relative to 
E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\index.js
2021-11-12T16:17:47.733Z eslintrc:config-array-factory package.json was not found: Cannot find module 
'./configs/base/package.json'
Require stack:
- E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\index.js
2021-11-12T16:17:47.733Z eslintrc:config-array-factory Loaded: ./configs/base 
(E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\configs\base.js)
2021-11-12T16:17:47.733Z eslintrc:config-array-factory Loading JS config file: 
E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\configs\base.js
2021-11-12T16:17:47.735Z eslintrc:config-array-factory Loading parser "@typescript-eslint/parser" from 
E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\configs\base.js
2021-11-12T16:17:47.736Z eslintrc:config-array-factory Loaded: @typescript-eslint/parser@5.3.1 
(E:\path-to-my-ts-project\node_modules\@typescript-eslint\parser\dist\index.js)
2021-11-12T16:17:47.737Z eslintrc:config-array-factory Loading plugin "@typescript-eslint" from 
E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\configs\base.js
2021-11-12T16:17:47.737Z eslintrc:config-array-factory Loaded: @typescript-eslint/eslint-plugin@5.3.1 
(E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\index.js)
2021-11-12T16:17:47.737Z eslintrc:config-array-factory Plugin 
E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\index.js loaded in: 0ms
2021-11-12T16:17:47.738Z eslintrc:config-array-factory Loading {extends:"./configs/eslint-recommended"} relative to 
E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\index.js
2021-11-12T16:17:47.738Z eslintrc:config-array-factory package.json was not found: Cannot find module 
'./configs/eslint-recommended/package.json'
Require stack:
- E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\index.js
2021-11-12T16:17:47.738Z eslintrc:config-array-factory Loaded: ./configs/eslint-recommended 
(E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\configs\eslint-recommended.js)
2021-11-12T16:17:47.739Z eslintrc:config-array-factory Loading JS config file: 
E:\path-to-my-ts-project\node_modules\@typescript-eslint\eslint-plugin\dist\configs\eslint-recommended.js
2021-11-12T16:17:47.741Z eslintrc:cascading-config-array-factory Stop traversing because of 'root:true'.
2021-11-12T16:17:47.742Z eslint:rules Loading rule 'constructor-super' (remaining=261)
2021-11-12T16:17:47.743Z eslint:rules Loading rule 'getter-return' (remaining=260)
2021-11-12T16:17:47.744Z eslint:rules Loading rule 'no-const-assign' (remaining=259)
2021-11-12T16:17:47.745Z eslint:rules Loading rule 'no-dupe-args' (remaining=258)
2021-11-12T16:17:47.746Z eslint:rules Loading rule 'no-dupe-keys' (remaining=257)
2021-11-12T16:17:47.747Z eslint:rules Loading rule 'no-func-assign' (remaining=256)
2021-11-12T16:17:47.747Z eslint:rules Loading rule 'no-import-assign' (remaining=255)
2021-11-12T16:17:47.749Z eslint:rules Loading rule 'no-new-symbol' (remaining=254)
2021-11-12T16:17:47.749Z eslint:rules Loading rule 'no-obj-calls' (remaining=253)
2021-11-12T16:17:47.751Z eslint:rules Loading rule 'no-redeclare' (remaining=252)
2021-11-12T16:17:47.752Z eslint:rules Loading rule 'no-setter-return' (remaining=251)
2021-11-12T16:17:47.753Z eslint:rules Loading rule 'no-this-before-super' (remaining=250)
2021-11-12T16:17:47.754Z eslint:rules Loading rule 'no-undef' (remaining=249)
2021-11-12T16:17:47.754Z eslint:rules Loading rule 'no-unreachable' (remaining=248)
2021-11-12T16:17:47.755Z eslint:rules Loading rule 'no-unsafe-negation' (remaining=247)
2021-11-12T16:17:47.756Z eslint:rules Loading rule 'no-var' (remaining=246)
2021-11-12T16:17:47.758Z eslint:rules Loading rule 'prefer-const' (remaining=245)
2021-11-12T16:17:47.760Z eslint:rules Loading rule 'prefer-rest-params' (remaining=244)
2021-11-12T16:17:47.761Z eslint:rules Loading rule 'prefer-spread' (remaining=243)
2021-11-12T16:17:47.762Z eslint:rules Loading rule 'valid-typeof' (remaining=242)
2021-11-12T16:17:47.767Z eslint:rules Loading rule 'no-array-constructor' (remaining=241)
2021-11-12T16:17:47.775Z eslint:rules Loading rule 'no-unused-vars' (remaining=240)
2021-11-12T16:17:47.782Z eslintrc:cascading-config-array-factory Configuration was determined: ConfigArray(7) [ { 
type: 'config', name: 'DefaultIgnorePattern', filePath: '', criteria: null, env: undefined, globals: undefined, 
ignorePattern: IgnorePattern { patterns: [Array], basePath: 'E:\\path-to-my-ts-project', loose: false }, 
noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, 
reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { type: 'config', 
name: '.eslintrc.js', filePath: 'E:\\path-to-my-ts-project\\.eslintrc.js', criteria: null, env: undefined, globals: 
undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: 
'E:\\path-to-my-ts-project\\node_modules\\@typescript-eslint\\parser\\dist\\index.js', id: 
'@typescript-eslint/parser', importerName: '.eslintrc.js', importerPath: 'E:\\path-to-my-ts-project\\.eslintrc.js' }, 
parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: 
true, rules: undefined, settings: undefined }, { type: 'config', name: '.eslintrc.js#overrides[0] ┬╗ 
plugin:@typescript-eslint/recommended ┬╗ ./configs/base', filePath: 
'E:\\path-to-my-ts-project\\node_modules\\@typescript-eslint\\eslint-plugin\\dist\\configs\\base.js', criteria: { 
includes: [Array], excludes: null, basePath: 'E:\\path-to-my-ts-project' }, env: undefined, globals: undefined, 
ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: 
'E:\\path-to-my-ts-project\\node_modules\\@typescript-eslint\\parser\\dist\\index.js', id: 
'@typescript-eslint/parser', importerName: '.eslintrc.js#overrides[0] ┬╗ plugin:@typescript-eslint/recommended ┬╗ 
./configs/base', importerPath: 
'E:\\path-to-my-ts-project\\node_modules\\@typescript-eslint\\eslint-plugin\\dist\\configs\\base.js' }, parserOptions: 
{ sourceType: 'module' }, plugins: { '@typescript-eslint': [Object] }, processor: undefined, 
reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { type: 'config', 
name: '.eslintrc.js#overrides[0] ┬╗ plugin:@typescript-eslint/recommended ┬╗ ./configs/eslint-recommended', filePath: 
'E:\\path-to-my-ts-project\\node_modules\\@typescript-eslint\\eslint-plugin\\dist\\configs\\eslint-recommended.js', 
criteria: { includes: [Array], excludes: null, basePath: 'E:\\path-to-my-ts-project' }, env: undefined, globals: 
undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: 
undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, 
settings: undefined }, { type: 'config', name: '.eslintrc.js#overrides[0] ┬╗ plugin:@typescript-eslint/recommended ┬╗ 
./configs/eslint-recommended#overrides[0]', filePath: 
'E:\\path-to-my-ts-project\\node_modules\\@typescript-eslint\\eslint-plugin\\dist\\configs\\eslint-recommended.js', 
criteria: { AND: [Array], basePath: 'E:\\path-to-my-ts-project' }, env: undefined, globals: undefined, ignorePattern: 
undefined, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: 
undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { 'constructor-super': 'off', 
'getter-return': 'off', 'no-const-assign': 'off', 'no-dupe-args': 'off', 'no-dupe-class-members': 'off', 
'no-dupe-keys': 'off', 'no-func-assign': 'off', 'no-import-assign': 'off', 'no-new-symbol': 'off', 'no-obj-calls': 
'off', 'no-redeclare': 'off', 'no-setter-return': 'off', 'no-this-before-super': 'off', 'no-undef': 'off', 
'no-unreachable': 'off', 'no-unsafe-negation': 'off', 'no-var': 'error', 'prefer-const': 'error', 
'prefer-rest-params': 'error', 'prefer-spread': 'error', 'valid-typeof': 'off' }, settings: undefined }, { type: 
'config', name: '.eslintrc.js#overrides[0] ┬╗ plugin:@typescript-eslint/recommended', filePath: 
'E:\\path-to-my-ts-project\\node_modules\\@typescript-eslint\\eslint-plugin\\dist\\index.js', criteria: { includes: 
[Array], excludes: null, basePath: 'E:\\path-to-my-ts-project' }, env: undefined, globals: undefined, ignorePattern: 
undefined, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: 
undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { 
'@typescript-eslint/adjacent-overload-signatures': 'error', '@typescript-eslint/ban-ts-comment': 'error', 
'@typescript-eslint/ban-types': 'error', 'no-array-constructor': 'off', '@typescript-eslint/no-array-constructor': 
'error', 'no-empty-function': 'off', '@typescript-eslint/no-empty-function': 'error', 
'@typescript-eslint/no-empty-interface': 'error', '@typescript-eslint/no-explicit-any': 'warn', 
'@typescript-eslint/no-extra-non-null-assertion': 'error', 'no-extra-semi': 'off', '@typescript-eslint/no-extra-semi': 
'error', '@typescript-eslint/no-inferrable-types': 'error', 'no-loss-of-precision': 'off', 
'@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-misused-new': 'error', 
'@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', 
'@typescript-eslint/no-non-null-assertion': 'warn', '@typescript-eslint/no-this-alias': 'error', 
'@typescript-eslint/no-unnecessary-type-constraint': 'error', 'no-unused-vars': 'off', 
'@typescript-eslint/no-unused-vars': 'warn', '@typescript-eslint/no-var-requires': 'error', 
'@typescript-eslint/prefer-as-const': 'error', '@typescript-eslint/prefer-namespace-keyword': 'error', 
'@typescript-eslint/triple-slash-reference': 'error' }, settings: undefined }, { type: 'config', name: 
'.eslintrc.js#overrides[0]', filePath: 'E:\\path-to-my-ts-project\\.eslintrc.js', criteria: { includes: [Array], 
excludes: null, basePath: 'E:\\path-to-my-ts-project' }, env: undefined, globals: undefined, ignorePattern: undefined, 
noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, 
reportUnusedDisableDirectives: undefined, root: undefined, rules: { '@typescript-eslint/no-unused-vars': 'error' }, 
settings: undefined } ] on E:\path-to-my-ts-project\src
2021-11-12T16:17:47.785Z eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], 
basePath: 'E:\\path-to-my-ts-project', loose: false } ]
2021-11-12T16:17:47.787Z eslintrc:ignore-pattern   processed: { basePath: 'E:\\path-to-my-ts-project', patterns: [ 
'/**/node_modules/*' ] }
2021-11-12T16:17:47.788Z eslintrc:ignore-pattern Check {
  filePath: 'E:\\path-to-my-ts-project\\src\\index.ts',
  dot: false,
  relativePath: 'src/index.ts',
  result: false
}
2021-11-12T16:17:47.788Z eslint:file-enumerator Yield: index.ts
2021-11-12T16:17:47.788Z eslintrc:cascading-config-array-factory Load config files for E:\path-to-my-ts-project\src.
2021-11-12T16:17:47.788Z eslintrc:cascading-config-array-factory Cache hit: E:\path-to-my-ts-project\src.
2021-11-12T16:17:47.789Z eslint:cli-engine Lint E:\path-to-my-ts-project\src\index.ts
2021-11-12T16:17:47.789Z eslint:linter Linting code for E:\path-to-my-ts-project\src\index.ts (pass 1)
2021-11-12T16:17:47.789Z eslint:linter Verify
2021-11-12T16:17:47.789Z eslint:linter With ConfigArray: E:\path-to-my-ts-project\src\index.ts
2021-11-12T16:17:47.832Z eslint:config-comment-parser Parsing list config
2021-11-12T16:17:47.865Z eslint:linter Generating fixed text for E:\path-to-my-ts-project\src\index.ts (pass 1)
2021-11-12T16:17:47.865Z eslint:source-code-fixer Applying fixes
2021-11-12T16:17:47.865Z eslint:source-code-fixer shouldFix parameter was false, not attempting fixes
2021-11-12T16:17:47.865Z eslint:file-enumerator Leave the directory: E:\path-to-my-ts-project\src
2021-11-12T16:17:47.865Z eslint:file-enumerator Complete iterating files: ["src"]
2021-11-12T16:17:47.865Z eslint:cli-engine Linting complete in: 1016ms

E:\path-to-my-ts-project\src\index.ts
  8:17  error  'TheBar' is defined but never used  @typescript-eslint/no-unused-vars

Ô£û 1 problem (1 error, 0 warnings)

Versions

package version
@typescript-eslint/eslint-plugin 5.3.1
@typescript-eslint/parser 5.3.1
TypeScript 4.4.4
ESLint 8.2.0
node 16.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions