簡體   English   中英

當缺少導入語句時發出警告?

[英]Eslint to warn when there is a missing import statement?

我正在使用帶有常規 javascript 的 nodejs,並使用 eslint。 我的 eslint 設置為在我的代碼中捕獲許多錯誤 - 但是當我忘記將 package 導入我的代碼時它沒有捕獲。 下面是一個這樣的例子。

在此處輸入圖像描述

eslint 的 rest 可以在出現問題時顯示紅色波浪線......我已經設置好了,所以當存在錯誤時我無法部署到生產環境。 但是,它允許這樣的錯誤。

下面是我的 current.eslint.rc 文件:

module.exports = {
    'env': {
        'browser': true,
        'commonjs': true,
        'es2021': true
    },
    'overrides': [
        {
            'files': ['*.ts'],
            'parserOptions': {
                'project': ['./tsconfig.json'],
            },
        }
    ],
    'extends': 'eslint:recommended',
    'parserOptions': {
        'ecmaVersion': 'latest'
    },
    'rules': {
        'arrow-body-style': 'off',
        'constructor-super': 'error',
        'curly': 'off',
        'dot-notation': 'off',
        'eol-last': 'error',
        'eqeqeq': [
            'error',
            'smart'
        ],
        'guard-for-in': 'off',
        'id-denylist': 'off',
        'id-match': 'off',
        'max-len': [
            'off',
            {
                'code': 140
            }
        ],
        'no-bitwise': 'error',
        'no-caller': 'error',
        'no-console': [
            'error',
            {
                'allow': [
                    'log',
                    'warn',
                    'info',
                    'dir',
                    'timeLog',
                    'assert',
                    'clear',
                    'count',
                    'countReset',
                    'group',
                    'groupEnd',
                    'table',
                    'dirxml',
                    'error',
                    'groupCollapsed',
                    'Console',
                    'profile',
                    'profileEnd',
                    'timeStamp',
                    'context'
                ]
            }
        ],
        'no-inner-declarations': 'off',
        'no-debugger': 'error',
        'no-empty': 'off',
        'no-empty-function': 'off',
        'no-eval': 'error',
        'no-fallthrough': 'error',
        'no-new-wrappers': 'error',
        'no-restricted-imports': [
            'error',
            'rxjs/Rx'
        ],
        'no-shadow': 'off',
        'no-throw-literal': 'error',
        // 'no-trailing-spaces': 'error',
        'no-undef': 'off',
        'no-undef-init': 'error',
        'no-underscore-dangle': 'off',
        'no-unused-expressions': 'error',
        'no-unused-labels': 'error',
        'no-var': 'error',
        'prefer-const': 'error',
        'quotes': [2, 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true, },],
        'semi': 'error'
    }
};

將您的no-undef規則打開以顯示錯誤或警告。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM