简体   繁体   中英

Eslint to warn when there is a missing import statement?

I'm using nodejs with regular javascript, and using eslint. My eslint is setup to catch many errors in my code - however it isn't catching when I forgot to import a package into my code. Below is one such example.

在此处输入图像描述

The rest of the eslint works where it will show red squigglies when something is wrong... and I have it set so I can't do a deployment to production when errors exist. However it allows errors such as this.

Below is my current.eslint.rc file:

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'
    }
};

Turn your no-undef rule on to error or warn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM