【问题标题】:How to fix 'Definition for rule '@typescript-eslint/no-use-before-declare' was not found.eslint(@typescript-eslint/no-use-before-declare)'如何修复'未找到规则'@typescript-eslint/no-use-before-declare'的定义.eslint(@typescript-eslint/no-use-before-declare)'
【发布时间】:2020-03-23 19:15:31
【问题描述】:

我是 eslint 的新手,我不知道如何解决这个问题。我的导入的开头总是用红线下划线。它抱怨找不到指定规则的定义。我想保留该规则,因为它似乎在其他方面很有用。 .

对于我的 .eslintrc.js 文件,我设置了以下规则:

`

module.exports = {
    env: {
        browser: true,
        node: true
    },
    extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/eslint-recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:@typescript-eslint/recommended-requiring-type-checking',
        'prettier'
    ],
    parser: '@typescript-eslint/parser',
    parserOptions: {
        project: 'tsconfig.json',
        sourceType: 'module'
    },
    plugins: ['@typescript-eslint', '@typescript-eslint/tslint'],
    rules: {
        '@typescript-eslint/class-name-casing': 'error',
        '@typescript-eslint/consistent-type-definitions': 'error',
        '@typescript-eslint/explicit-member-accessibility': [
            'off',
            {
                accessibility: 'explicit'
            }
        ],
        '@typescript-eslint/indent': ['error', 'tab'],
        '@typescript-eslint/member-delimiter-style': [
            'error',
            {
                multiline: {
                    delimiter: 'semi',
                    requireLast: true
                },
                singleline: {
                    delimiter: 'semi',
                    requireLast: false
                }
            }
        ],
        '@typescript-eslint/member-ordering': 'error',
        '@typescript-eslint/no-empty-function': 'off',
        '@typescript-eslint/no-empty-interface': 'error',
        '@typescript-eslint/no-inferrable-types': 'error',
        '@typescript-eslint/no-misused-new': 'error',
        '@typescript-eslint/no-non-null-assertion': 'error',
        '@typescript-eslint/no-use-before-declare': ['error', { functions: true, classes: true, variables: true }],
        '@typescript-eslint/prefer-function-type': 'error',
        '@typescript-eslint/quotes': ['error', 'single'],
        '@typescript-eslint/semi': ['error', 'always'],
        '@typescript-eslint/type-annotation-spacing': 'error',
        '@typescript-eslint/unified-signatures': 'error',
        'arrow-body-style': 'error',
        camelcase: 'off',
        'capitalized-comments': 'error',
        'constructor-super': 'error',
        curly: 'error',
        'dot-notation': 'off',
        'eol-last': 'error',
        eqeqeq: ['error', 'smart'],
        'guard-for-in': 'error',
        'id-blacklist': 'off',
        'id-match': 'off',
        'import/no-deprecated': 'warn',
        'max-classes-per-file': ['error', 1],
        'max-len': [
            'error',
            {
                code: 140
            }
        ],
        'no-bitwise': 'error',
        'no-caller': 'error',
        'no-console': [
            'error',
            {
                allow: [
                    'log',
                    'warn',
                    'dir',
                    'timeLog',
                    'assert',
                    'clear',
                    'count',
                    'countReset',
                    'group',
                    'groupEnd',
                    'table',
                    'dirxml',
                    'error',
                    'groupCollapsed',
                    'Console',
                    'profile',
                    'profileEnd',
                    'timeStamp',
                    'context'
                ]
            }
        ],
        'no-debugger': 'error',
        'no-empty': 'off',
        'no-eval': 'error',
        'no-fallthrough': 'error',
        'no-new-wrappers': 'error',
        'no-shadow': [
            'error',
            {
                hoist: 'all'
            }
        ],
        'no-throw-literal': 'error',
        'no-trailing-spaces': 'error',
        'no-undef-init': 'error',
        'no-underscore-dangle': 'off',
        'no-unused-expressions': 'error',
        'no-unused-labels': 'error',
        'no-var': 'error',
        'prefer-const': 'error',
        radix: 'error',
        'spaced-comment': 'error',
        '@typescript-eslint/tslint/config': [
            'error',
            {
                rules: {
                    'component-class-suffix': [true, 'Component', 'View', 'Routing'],
                    'contextual-lifecycle': true,
                    'directive-class-suffix': true,
                    'import-blacklist': [true, 'rxjs/Rx'],
                    'import-spacing': true,
                    'no-host-metadata-property': true,
                    'no-input-rename': true,
                    'no-inputs-metadata-property': true,
                    'no-output-on-prefix': true,
                    'no-output-rename': true,
                    'no-outputs-metadata-property': true,
                    'no-redundant-jsdoc': true,
                    'one-line': [true, 'check-open-brace', 'check-catch', 'check-else', 'check-whitespace'],
                    'template-banana-in-box': true,
                    'template-no-negated-async': true,
                    'use-component-view-encapsulation': true,
                    'use-lifecycle-interface': true,
                    'use-pipe-decorator': true,
                    'use-pipe-transform-interface': true,
                    'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: false }],
                    whitespace: [true, 'check-branch', 'check-decl', 'check-operator', 'check-separator', 'check-type']
                }
            }
        ]
    }
};

`

除了删除规则之外,知道如何解决这个问题吗?

谢谢

【问题讨论】:

标签: typescript eslint


【解决方案1】:

根据page,不鼓励使用此规则,因为现代 TypeScript 不使用它并且计算速度很慢。所以你应该删除规则。

如果你仍然想继续使用它,你可以试试{ "no-use-before-define": ["error", { "variables": false }] }

你可以阅读更多关于这个here

【讨论】:

  • 您发送的链接中的什么地方是这样写的?我读过它,但没有看到不鼓励它与打字稿一起使用的参考资料。
  • 对不起,我在这两个地方都提供了相同的链接。我已经编辑了答案,page 现在指向正确的链接。它说 - “这个规则主要在使用 var 关键字时很有用,因为编译器会自动检测在声明之前是否使用了块范围的 let 和 const 变量。由于大多数现代 TypeScript 不使用 var,所以通常不鼓励使用这个规则并且出于遗留目的而保留。计算速度很慢,未在内置配置预设中启用,并且不应用于通知 TSLint 设计决策。”
【解决方案2】:

重新启动您的Visual Studio Code
它可以消除这个错误。 我和this dev 做了同样的事情。

【讨论】:

  • 不要发布仅链接到另一个答案的答案,而是将flag the question作为副本发布。
【解决方案3】:

对于那些在这里谷歌搜索的人,如果您遇到@typescript-eslint/** rule not found 问题,很可能是因为您使用的是过时的包。

这里我以@typescript-eslint/eslint-plugin 为例。它可能不是您的直接依赖项,请使用 npm ls @typescript-eslint/eslint-plugin 找出您正在使用的确切版本。并尝试将其更新到最新版本。

【讨论】:

  • 这正是我一直在努力解决的问题 - 尽管我用来存储共享 ESLint 配置的包有 eslint-plugin 4.6,但我安装该包的应用程序有eslint-plugin 2.33 正在使用那个,非常感谢!
【解决方案4】:

Visual Studio 通常在依赖项更新后开始发出此警告。

使用 shift + command ⌘ + P 并从那里运行 Restart Extension Host 为我解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-30
    • 2021-06-25
    • 2017-09-11
    • 2020-08-01
    • 2021-05-08
    • 2018-02-26
    • 2021-02-20
    • 1970-01-01
    相关资源
    最近更新 更多